Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always showed me 'Unauthorized' #125

Open
ianhomew opened this issue Sep 20, 2021 · 3 comments
Open

Always showed me 'Unauthorized' #125

ianhomew opened this issue Sep 20, 2021 · 3 comments

Comments

@ianhomew
Copy link

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();
@askmike
Copy link

askmike commented Sep 30, 2021

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

@ianhomew
Copy link
Author

ianhomew commented Oct 5, 2021

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...

@zoo475698058
Copy link

zoo475698058 commented Apr 25, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants