一段时间以来,我一直在努力为私有 GDAX 端点签名请求。我尝试过的所有操作都会导致 400 响应,并显示“签名无效”的消息。我已经多次阅读他们关于此事的文档,可以在这里找到。我当前的代码如下。我clj-http
用于提出请求。我正在使用他们的/time
端点响应作为时间戳,并且我正在使用pandect来生成 sha256 HMAC。在将其secret-decoded
传递String.
给sha256-hmac
. 我还使用检查了请求clj-http
的调试标志。在我看来,我完全按照他们的指示行事,但肯定有问题。在这里发帖之前,我已经做了很多在线搜索。任何帮助将不胜感激。
(defn get-time
[]
(-> (str (:api-base-url config) "/time")
(http/get {:as :json})
:body))
(defn- create-signature
([timestamp method path]
(create-signature timestamp method path ""))
([timestamp method path body]
(let [secret-decoded (b64/decode (.getBytes (:api-secret config)))
prehash-string (str timestamp (clojure.string/upper-case method) path body)
hmac (sha256-hmac prehash-string secret-decoded)]
(-> hmac
.getBytes
b64/encode
String.))))
(defn- send-signed-request
[method path & [opts]]
(let [url (str (:api-base-url config) path)
timestamp (long (:epoch (get-time)))
signature (create-signature timestamp method path (:body opts))]
(http/request
(merge {:method method
:url url
:as :json
:headers {"CB-ACCESS-KEY" (:api-key config)
"CB-ACCESS-SIGN" signature
"CB-ACCESS-TIMESTAMP" timestamp
"CB-ACCESS-PASSPHRASE" (:api-passphrase config)
"Content-Type" "application/json"}
:debug true}
opts))))
(defn get-accounts []
(send-signed-request "GET" "/accounts"))
(send-signed-request "GET" "/accounts")))