v3-client
v3-client copied to clipboard
Issue with private stark key
Hello i'm using the client with node.js and i'm not able to place order. I think i haven't made any error because i can access every other endpoint like /account and /positions. The code and error is below :
const
{ DydxClient } = require('@dydxprotocol/v3-client')
const Web3 = require('web3')
const HTTP_HOST = 'https://api.dydx.exchange' const WS_HOST = 'wss://api.dydx.exchange/v3/ws'
// NOTE: Set up web3 however your prefer to authenticate to your Ethereum account. web3 = new Web3() web3.eth.accounts.wallet.add("");// I have put public stark key
async function Place_order(){
client = new DydxClient(HTTP_HOST, { web3 }) const apiCreds = await client.onboarding.recoverDefaultApiCredentials("0x54eBDa43c2ac7Ea6252CcD5dB54EFd53EF4d9Ffd")
client.starkPrivateKey = "";// I don't share it on git client.apiKeyCredentials = apiCreds;
const order = await client.private.createOrder( { positionId:"", // I don't share it on git market:"DOT-USD", side: "SELL", type: "LIMIT", postOnly: false, size: "1", price: "40", expiration: "2022-12-21T21:30:20.200Z", limitFee: "0.005" } ); console.log(order);
}; Place_order(); ` When i run it i get
(node:22700) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'match' of undefined
at Object.decToBn (/Users/romain/Desktop/GIT/dydx-mm/node_modules/@dydxprotocol/starkex-lib/build/src/lib/util.js:73:14)
at SignableOrder.calculateHash (/Users/romain/Desktop/GIT/dydx-mm/node_modules/@dydxprotocol/starkex-lib/build/src/signable/order.js:64:37)
at SignableOrder.getHashBN (/Users/romain/Desktop/GIT/dydx-mm/node_modules/@dydxprotocol/starkex-lib/build/src/signable/stark-signable.js:29:39)
at SignableOrder.sign (/Users/romain/Desktop/GIT/dydx-mm/node_modules/@dydxprotocol/starkex-lib/build/src/signable/stark-signable.js:37:35)
at Private.createOrder (/Users/romain/Desktop/GIT/dydx-mm/node_modules/@dydxprotocol/v3-client/build/src/modules/private.js:224:42)
at Market_Data (/Users/romain/Desktop/GIT/dydx-mm/PRIVATE/order.js:29:37)
(node:22700) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:22700) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
When i put no stark private key the classic warning appear "there is no starkprivate key warining".
check correct way to supply positionId
https://docs.dydx.exchange/?typescript#create-a-new-order
and you could find your positionId
via https://docs.dydx.exchange/?typescript#get-account
@rvie17 have you solved the problem? I have the same issue.
web3.eth.accounts.wallet.add("");// I have put public stark key No, eth private key goes here
positionId You can find correct positionId this from v3/account endpoint response
Hi
I have issues in createOrder function
const order: { order: OrderResponseObject } = await client.private.createOrder(
{
side: OrderSide.SELL,
type: OrderType.LIMIT,
timeInForce: TimeInForce.GTT,
postOnly: false,
size: '100',
price: '18000',
limitFee: '0.015',
expiration: '2023-02-21T21:30:20.200Z',
market: Market.BTC_USD
},
'1', // required for creating the order signature
);
Then met the follow error.
[1] Error: Order is not signed and client was not initialized with starkPrivateKey
[1] at Private.createOrder (#############\node_modules\@dydxprotocol\v3-client\build\src\modules\private.js:255:23)
[1] at #########l\dist\index.js:54:40
[1] at Generator.next (<anonymous>)
[1] at fulfilled (E:\works\bitoro_perpetual_tutorial\dist\index.js:5:58)
[1] at processTicksAndRejections (node:internal/process/task_queues:96:5)
What am I wrong? How to solve?