dydxprotocol/v3-client

Create Order - Invalid signature for order

Closed this issue · 3 comments

Hi team,

I have successfully connected my testnet account to the websocket example. However, I cannot seem to place an order as am met with "Invalid signature for order".

Have tried getting this to work for hours and hours and just cannot seem to figure it out.

Would it be possible to add a REST API in the examples folder for creating an order?

CODE I AM USING BELOW >>

const { DydxClient } = require("@dydxprotocol/v3-client");
const Web3 = require("web3");
const privateKey = ;
const account = ;
const HTTP_HOST = "https://api.stage.dydx.exchange";
const networkId = 3;
const web3 = new Web3();

web3.eth.accounts.wallet.add(privateKey);

const main = async () => {
client = new DydxClient(HTTP_HOST, { web3, networkId });

const apiCreds = await client.onboarding.recoverDefaultApiCredentials(
account
);

const starkCreds = await client.onboarding.deriveStarkKey(account);

client.apiKeyCredentials = apiCreds;

client.starkPrivateKey = starkCreds.privateKey;

const timestamp = new Date().toISOString();

const params = {
market: "LINK-USD",
side: "BUY",
type: "LIMIT",
postOnly: false,
size: "1",
price: "400",
limitFee: "0.015",
expiration: "2022-12-21T21:30:20.200Z",
timeInForce: "GTT",
};

const signature = client.private.sign({
requestPath: "/v3/orders",
method: "POST",
isoTimestamp: timestamp,
data: params,
});

const expiration = new Date();
expiration.setDate(expiration.getDate() + 1);

const marketOrder = await client.private.createOrder(
{
market: "LINK-USD",
side: "BUY",
type: "LIMIT",
postOnly: false,
size: "1",
price: "400",
limitFee: "0.015",
expiration: "2022-12-21T21:30:20.200Z",
timeInForce: "GTT",
signature: signature,
},
"1" // required for creating the order signature
);
};

main();

I have finally figured it out. When using the Stark private key, you do not need a signature.

This was a very painful process to find out and needed to go right into the Python code. Luckily there was a comment which gave it away in the Python repository.

I have a similar issue.

I get this error message when calling createFastWithdrawal. I didn't include any signature as I have correctly set stark private key to the client.

Were you able to try to call this function?

Did u manage to find the solution? even i am getting the same error