Always showed me 'Unauthorized'
ianhomew opened this issue · 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();
Try specifying timeInForce: 'GTT'
, without that you might get unauthorized back
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...
I have the same problem in testing Create A New Order, how do I test if the API signature is correct