Skip to content

Instantly share code, notes, and snippets.

@carboleum
carboleum / kraken.lisp
Last active January 6, 2021 19:30
Access Kraken API with Common Lisp
(ql:quickload :cl-kraken)
(setq cl-kraken/src/globals::*api-key* "my api key")
(setq cl-kraken/src/globals::*api-secret* "my api secret")
; public market data
(cl-kraken::request "Time")
(cl-kraken::request "Ticker" :params '(("pair" . "XXBTZEUR")))
; private user data
(cl-kraken::request "Balance" :post t)
(cl-kraken::request "TradeBalance" :params '(("asset" . "ZEUR")) :post t)
@carboleum
carboleum / rolling-map.lisp
Last active June 4, 2020 13:33
function to calculate moving average, bollinger bands and so on
(defun rolling-map (n func list &optional (sequence '()) (return '()))
(cond ((eq list '()) return)
(t (setq sequence (append sequence (list (car list))))
(if (> (length sequence) n) (setq sequence (cdr sequence)))
(setq return (append return (list (apply func sequence))))
(rolling-map n func (cdr list) sequence return))))
(defun average (&rest list) (/ (apply '+ list) (length list)))
(rolling-map 3 'list '(1 1 2 3 5 8 13 21 34))
@carboleum
carboleum / rsi.lisp
Created June 9, 2020 08:26
Relative Strength Index
;; use rolling-map and average (https://gist.github.com/carboleum/c329d255746a7659cb01ba0305c1d2f0)
(defun rsi (n prices)
(let ((gain (let ((cumul 0))
(mapcar #'(lambda (x) (setq cumul (/ (+ (* cumul (1- n)) x) n)))
(cdr (rolling-map 2 #'(lambda (&rest list)
(if (apply #'< list) (abs (apply #'- list)) 0))
prices)))))
(loss (let ((cumul 0))
(mapcar #'(lambda (x) (setq cumul (/ (+ (* cumul (1- n)) x) n)))
@carboleum
carboleum / sockets.md
Last active January 4, 2022 23:10
How to write a message in another terminal (with Common Lisp) ?
@carboleum
carboleum / send-gmail-with-lisp.md
Last active September 5, 2023 16:23
Send gmail with common lisp cl-smtp

Autoriser les applications moins sécurisées

Dans Google, paramètres du compte, sécurité

use cl-smpt library

(ql:quickload :cl-smtp)
@carboleum
carboleum / error.lisp
Last active August 23, 2020 16:07
error handling with common lisp
(define-condition my-error (condition)
((message :initarg :message :reader message)))
(handler-case (signal 'my-error :message "Damned! an error!")
(my-error (e) (warn "~s" (message e))))
@carboleum
carboleum / mathjax.html
Created July 26, 2022 20:47
mathjax tab in head of html
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>