dydxprotocol/dydx-v3-python

Simple MARKET order failing with "Invalid signature for order"

hermesfreitas opened this issue · 4 comments

Error message do not say much. Python code is:

private_client = Client(
host='https://api.dydx.exchange',
api_key_credentials={
'key': CREDENTIAL_KEY,
'secret': CREDENTIAL_SECRET,
'passphrase': CREDENTIAL_PASSPHRASE
},
stark_private_key=STARK_KEY,
default_ethereum_address=ETHEREUM_ADDRESS,
)

order = private_client.private.create_order(
position_id=120,
market=MARKET_BTC_USD,
side=ORDER_SIDE_BUY,
order_type=ORDER_TYPE_MARKET,
post_only=False,
expiration_epoch_seconds=time.time() + 70,
limit_fee='0.002', # 0.02%
price='23230.00',
size='0.002',
time_in_force=TIME_IN_FORCE_IOC
)


DydxApiError: DydxApiError(status_code=400, response={'errors': [{'msg': 'Invalid signature for order'}]})

Tried without any success several combinations, always respecting the ORDER_TYPE_MARKET. Also, any reason for requiring the price in a market order request? This is similar to #137

For my case, I tried to place a limit order and got the same error "DydxApiError: DydxApiError(status_code=400, response={'errors': [{'msg': 'Invalid signature for order'}]})".
(I also wonder why we need price for market order request.)

At Japanese dYdX community, I got a suggestion to try with other account. Interestingly I didn't have any trouble with a new account. I could sign to my order with the same code.

Thanks for the insight! Was the new account created in Metamask?

I had the same issue. What I realize is if you've previously used an ETH account to onboard via DYDX's web interface, you should get the stark key from your browser's local storage (inspect element -> application) see bottom of this page: https://docs.dydx.community/dydx-governance/resources/market-maker-onboarding.

Calling onboarding.derive_stark_key after onboarding via web UI somehow generates a different set of stark key from the one in your browser's local storage which causes "Invalid Signature for order".

I didn't investigate why onboarding.derive_stark_key generates differently. But that's the cause.


On the other hand, if you went through the flow of creating user and deriving stark key programmatically first and then connect to DYDX's web UI via Metamask or others, the stark key would be the same.