v3-client icon indicating copy to clipboard operation
v3-client copied to clipboard

Always showed me 'Unauthorized'

Open ianhomew opened this issue 4 years ago • 3 comments

I have traded on dydx.exchange before I run this code. This code always showed me below:

AxiosServerError: 401: Unauthorized - {
  "errors": [
    {
      "msg": "Unauthorized"
    }
  ]
}

// I tried to call the cancel function and it work.
await client.private.cancelAllOrders() 

please help me with any ideas.


const main = async () => {

    let client = new DydxClient(HTTP_HOST, {
        web3: web3,
        apiTimeout: 3000,
        networkId: 1,
    })

    client.starkPrivateKey = await client.onboarding.deriveStarkKey(address)
    client.apiKeyCredentials = await client.onboarding.recoverDefaultApiCredentials(address)

    const timestamp = new Date().toISOString()
    const account_response = await client.private.getAccount(address)
    const position_id = account_response['account']['positionId']


    let OrderResponseObject = await client.private.createOrder(
        {
            market: 'ETH-USD',
            side: 'BUY',
            type: 'LIMIT',
            postOnly: false,
            size: '0.01',
            price: '1000',
            limitFee: '0.015',
            expiration: '2022-12-21T21:30:20.200Z',
            // cancelId: position_id,
            // signature: signature,
        },
        position_id, // required for creating the order signature
    )
    console.log(OrderResponseObject)

}

main();

ianhomew avatar Sep 20 '21 08:09 ianhomew

Try specifying timeInForce: 'GTT', without that you might get unauthorized back

askmike avatar Sep 30 '21 10:09 askmike

Try specifying timeInForce: 'GTT', without that you might get unauthorized back

I am so glad to get your reply. I will try later because of another question...

ianhomew avatar Oct 05 '21 16:10 ianhomew

I have the same problem in testing Create A New Order, how do I test if the API signature is correct

zoo475698058 avatar Apr 25 '22 07:04 zoo475698058