If you look at this 2 links:
- https://testnet.bitmex.com/app/apiKeysUsage
- https://testnet.bitmex.com/api/explorer/#!/Order/Order_new
I have been trying for 2 days now to structure my code so I can authenticate there, but it's just wrong.
What exactly should I put in the data param for the HMAC encryption? How does the body Matlab sends in a webread POST request look? As I said, Im getting nowhere with this.
import matlab.net.*import matlab.net.http.*URI = matlab.net.URI('https://testnet.bitmex.com/api/v1/order');U = '?symbol=XBTUSD&side=Sell&orderQty=30&clOrdLinkID=SoL&ordType=Market&contingencyType=OneCancelsTheOther';Meth = matlab.net.http.RequestMethod.POST;Req = matlab.net.http.RequestMessage;Req.Method = Meth;Body = matlab.net.http.MessageBody(U);Req.Body = Body;ApiExpires = datetime('now','format','yyyy-MM-dd''T''HH:mm:ss''Z') + days(5);ApiExpires = posixtime(ApiExpires);ApiExpires = round(ApiExpires);ApiExpires = num2str(ApiExpires);ApiSecret = 'Tu9CNn_04cQxvjdgGm3MBV7KsqxzkNMAw_3LtUuLUhqC--iX';Com = complete(Req,URI);Path = '/api/v1/order';Verb = 'POST';EncData = strcat(Verb,Path,ApiExpires,'?symbol=XBTUSD&side=Sell&orderQty=30&clOrdLinkID=SoL&ordType=Market&contingencyType=OneCancelsTheOther');signature = HMAC(ApiSecret,EncData,'SHA-256');signature = lower(signature);ApiSignature = matlab.net.http.HeaderField('api-signature',signature);ApiKey2 = matlab.net.http.HeaderField('api-key','C8VW3PArKaNoh04CE103hucF');ApiExpires2 = matlab.net.http.HeaderField('api-expires',ApiExpires);Header = [ApiExpires2,ApiKey2,ApiSignature];Req.Header = Header;
Why is this unauthorized when doing send(Req,URI)? (Testnet so do what you want with the keys)
Best Answer