Last active
April 14, 2018 20:38
-
-
Save lnostdal/1634952ad4dd6ad9ee18637672f0056c to your computer and use it in GitHub Desktop.
Bitmex API key signature generation in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; www.Quanto.ga | |
;;;;;;;;;;;;;;;;; | |
;; Test from https://www.bitmex.com/app/apiKeysUsage#Full-sample-calculation | |
(letfn [(sign [^String api-secret ^String s] | |
(let [h (com.google.common.hash.Hashing/hmacSha256 (.getBytes api-secret))] | |
(.toString (.hashString h s com.google.common.base.Charsets/UTF_8))))] | |
(let [apiKey "LAqUlngMIQkIUjXMUreyu3qn" | |
apiSecret "chNOOS4KvNXR_Xq4k4c9qsfoKWvnDecLATCRlcBwyKDYnWgO"] | |
;; Simple GET | |
(let [verb "GET" | |
path "/api/v1/instrument" | |
expires 1518064236 ;; 2018-02-08T04:30:36Z | |
data ""] | |
(assert (= "c7682d435d0cfe87c16098df34ef2eb5a549d4c5a3c2b1f0f77b8af73423bf00" | |
(sign apiSecret (str verb path expires data)))) | |
;; POST | |
(let [verb "POST" | |
path "/api/v1/order" | |
expires 1518064238 ;; 2018-02-08T04:30:38Z | |
data "{\"symbol\":\"XBTM15\",\"price\":219.0,\"clOrdID\":\"mm_bitmex_1a/oemUeQ4CAJZgP3fjHsA\",\"orderQty\":98}"] | |
(assert (= "1749cd2ccae4aa49048ae09f0b95110cee706e0944e6a14ad0b3a8cb45bd336b" | |
(sign apiSecret (str verb path expires data)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment