dydxprotocol / dydx-v3-python

Python client for dYdX (API v3)
Apache License 2.0
304 stars 174 forks source link

order submission gets an error: Invalid signature for order. #206

Closed saleh-mir closed 1 year ago

saleh-mir commented 1 year ago

Hi there,

I only get this error when submitting an order. it's working fine for other endpoints such as fetching the balance.

This is my code for creating a client:

Client(
    network_id=5,
    host=hostIp,
    api_key_credentials={
          'key': '********e-1682-*****-a11e-********3107b',
          'secret': 'e***1n-******RuFIWN1-sWpJ*****_*****dR',
          'passphrase': '*****LdeofeDM*****Mm',
          'legacySigning': False,
          'walletType': "METAMASK",
          'walletAddress': '0x1c4643B******AF1E6D1*****9855c08989****',
      },
    default_ethereum_address='0x1c4643B******AF1E6D1*****9855c08989****',
    stark_private_key='05f4de**********6f9c********422399c48********cc37c*****8f8'
)

And this is my code for submitting the order:

res = self.client.private.create_order(
    market=order.symbol,
    side=order.side.upper(),
    order_type=self.jesse_to_dydx_order_type(order.type),
    post_only=False,
    size=str(abs(order.qty)),
    price=str(order_price),
    time_in_force=time_in_force,
    trigger_price=jh.str_or_none(trigger_price),
    client_id=order.id,
    reduce_only=order.reduce_only,
    limit_fee='0.01',
    position_id=self.vars['position_id'],
    expiration_epoch_seconds=int(time.time() + 16934400)
)

This code worked a few months ago but now gets this error:

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

It's as if the Stark private key has expired. to ensure I get the new keys from the browser console of the DYDX website.

saleh-mir commented 1 year ago

I was using the wrong network ID. make sure to use the right one for testnet and mainnet.

oussamabng commented 4 months ago

@saleh-mir what is the right one for testnet?

saleh-mir commented 4 months ago

@oussamabng

@saleh-mir what is the right one for testnet?

NETWORK_ID_MAINNET = 1 NETWORK_ID_GOERLI = 5

myuniswap2000 commented 4 months ago

Hello, where can I get information about api_key_credentials? @saleh-mir

saleh-mir commented 4 months ago

@myuniswap2000 Hi: https://docs.jesse.trade/docs/supported-exchanges/exchange-setup-guide#dydx