dydxprotocol / dydx-v3-python

Python client for dYdX (API v3)
Apache License 2.0
306 stars 176 forks source link

{"msg":"Unauthorized"} + limitFee scale of 6 #210

Closed kgoderis closed 1 year ago

kgoderis commented 1 year ago

I am in the process of developing a java client for the dydx protocol, and I bumped in a few things when creating orders. FYI, the crypto side of life is working well, onboarding is not an issue, nor signature of messages in general

First, the official documentation needs a little clarification on the limitFee field in the requests. When the value in the request is not set to a scale of 6, then this yields to a signature error:

{"market":"ETH-USD","side":"BUY","type":"LIMIT","postOnly":false,"size":"1","price":"1500","limitFee":0.0015,"expiration":"2023-08-28T19:54:12.656Z","timeInForce":"GTT","reduceOnly":false,"clientId":"09201745303854937266","signature":"07739f9c45d725ad5d646d91fc9d3c32897ab93546cded42673eb5cbe0459e3704f2f86935ce9587425239809a9e981ba5db305b579976120c77ed482dc3d36b"} -> {"errors":[{"msg":"Invalid signature for order"}]}

When I properly send it as "0.001500" it works ok

Secondly, I get a lot of "Unauthorized" responses, and I don't know why. What is wrong will the following requests/response pairs?

    {"market":"ETH-USD","side":"BUY","type":"LIMIT","postOnly":false,"size":"1","price":"1","limitFee":0.100500,"expiration":"2023-08-28T16:52:13.299Z","timeInForce":"GTT","reduceOnly":false,"clientId":"54555415500057560768","signature":"0341f3ae72b6d050712f306da7888f8c3533d26226a5e0637bb7ab8b1405825503a95faf8b363f92a1cefac79f822bc44506e3cc7344353e2790df9209aab246"} 
    {"errors":[{"msg":"Unauthorized"}]} 

    {"market":"ETH-USD","side":"BUY","type":"LIMIT","postOnly":false,"size":"1","price":"1500","limitFee":0.001500,"expiration":"2023-08-28T19:57:05.178Z","timeInForce":"GTT","reduceOnly":false,"clientId":"83250094903912950698","signature":"05066cfec70d91b44754892ebe9b37a052fd8a646c9934f038c408c363ad44ae027b2d5da632c5f53bdfaeb4891378056b1e5ccd048d7a92e70a2b9765ca2b9b"} 
    {"errors":[{"msg":"Unauthorized"}]}     

    {"market":"ETH-USD","side":"BUY","type":"LIMIT","postOnly":false,"size":"1","price":"1500","limitFee":0.000500,"expiration":"2023-08-28T20:43:43.492Z","timeInForce":"GTT","reduceOnly":false,"clientId":"89903031330238567507","signature":"02d58b4c6f53c94aeec90867cf78cb9e6d2e8d3cea8f0f861a2a36feae06e821052b9097ca1af16c232e596288baa88cf1d9dcd31a4fd3016d0adbcd202fcdeb"} 
    {"errors":[{"msg":"Unauthorized"}]} 

I presume that Unauthorized is a catch-all for anything which is ok in terms of signature, but that seems to fail other checks. I have put in strange prices/sizes because I saw a bunch of those on the testnet order book, so somehow it must be possible to send these, right?

kgoderis commented 1 year ago

The API does expect a string for limitFee, and a bug in my code was obscured by the fact that size = 1 and price = 1