简体   繁体   English

通过VBA HTTP Post将参数传递给Gdax API

[英]Passing arguments to Gdax API via VBA HTTP Post

I got a problem in vba while trying to interact with GDAX API. 尝试与GDAX API交互时,vba出现问题。

I get this error: {"message":"Requires product_id"} 我收到此错误:{“ message”:“需要product_id”}

I cant pass my product_id in the orders "POST" in WinHttp.WinHttpRequest.5.1 Nothing seems to work: 我无法在WinHttp.WinHttpRequest.5.1中的“ POST”命令中传递我的product_id,似乎没有任何作用:

I tried adding ?product_id=BTC-EUR after the URL as Methodoptions(this works for GET Statements) i tried adding "product_id=BTC-EUR" after the send I tried using JsonString = "{""size"": ""0.01"",""price"": ""0.100"",""side"": ""buy"",""product_id"": ""BTC-USD""}" this as postdata 我尝试在URL后面添加?product_id = BTC-EUR作为Methodoptions(这适用于GET语句)我尝试在发送后添加“ product_id = BTC-EUR”,我尝试使用JsonString =“ {”“ size”“:”“ 0.01 “”,“” price“”:“” 0.100“”,“” side“”:“”购买“”,“” product_id“”“:”“ BTC-USD”“}”作为后数据

Does anyone know, how to pass those arguments? 有人知道如何传递这些论点吗?

This is the code im working with, that works well for all other authenticated statements not passing parameters. 这是我正在使用的代码,它对于所有其他未传递参数的已验证语句均适用。

TradeApiSite = "https://api-public.sandbox.gdax.com"

SignMsg = NonceUnique & UCase(HTTPMethod) & "/" & Method & MethodOptions
APIsign = Base64Encode(ComputeHash_C("SHA256", SignMsg, Base64Decode(secretkey), "RAW"))

' Instantiate a WinHttpRequest object and open it
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.Open UCase(HTTPMethod), TradeApiSite & "/" & Method & MethodOptions, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.setRequestHeader "CB-ACCESS-KEY", apikey
objHTTP.setRequestHeader "CB-ACCESS-SIGN", APIsign
objHTTP.setRequestHeader "CB-ACCESS-TIMESTAMP", NonceUnique
objHTTP.setRequestHeader "CB-ACCESS-PASSPHRASE", passphrase

objHTTP.Send '(postdata)

Figured it out after look a bit deeper at how danpaquin/gdax-python does authentication over here https://github.com/danpaquin/gdax-python/blob/master/gdax/gdax_auth.py 在更深入地了解danpaquin / gdax-python如何在此处进行身份验证后找到答案了https://github.com/danpaquin/gdax-python/blob/master/gdax/gdax_auth.py

  1. You want to send the JSON string as the post data like you described 您想要像所描述的那样发送JSON字符串作为发布数据
  2. Content-Type header should be set to application/json Content-Type标头应设置为application / json
  3. The post data needs to appended to the pre-hash (in your case SignMsg) 帖子数据需要附加到哈希前(在您的情况下为SignMsg)

Step 2 is important because with out it, GDAX doesn't seem to read your post data - so you get Requires product_id error. 第2步很重要,因为如果没有它,GDAX似乎不会读取您的帖子数据-因此您收到Requires product_id错误。 If you do step 2 without step 3, you will get invalid signature error 如果您执行第2步而不执行第3步,则会收到无效的签名错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM