serum-ts icon indicating copy to clipboard operation
serum-ts copied to clipboard

Sometimes get error's when creating a new order

Open Gsuz opened this issue 3 years ago • 4 comments

Sometimes new order fails with the following:

Transaction simulation failed: Error processing Instruction 0: custom program error: 0x22 Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin invoke [1] Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin consumed 8970 of 200000 compute units Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin failed: custom program error: 0x22 /Users/borkur/Desktop/Coding/server-sunny/node_modules/@solana/web3.js/lib/index.cjs.js:4882 throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs); ^

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x22 at Connection.sendEncodedTransaction (/Users/borkur/Desktop/Coding/server-sunny/node_modules/@solana/web3.js/lib/index.cjs.js:4882:13) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Connection.sendRawTransaction (/Users/borkur/Desktop/Coding/server-sunny/node_modules/@solana/web3.js/lib/index.cjs.js:4840:20) at async Connection.sendTransaction (/Users/borkur/Desktop/Coding/server-sunny/node_modules/@solana/web3.js/lib/index.cjs.js:4830:12) at async Market._sendTransaction (/Users/borkur/Desktop/Coding/server-sunny/node_modules/@project-serum/serum/lib/market.js:504:27) at async Market.placeOrder (/Users/borkur/Desktop/Coding/server-sunny/node_modules/@project-serum/serum/lib/market.js:249:16) at async Timeout.startServer [as _onTimeout] (file:///Users/borkur/Desktop/Coding/server-sunny/server-sunny.js:215:5) { logs: [ 'Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin invoke [1]', 'Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin consumed 8970 of 200000 compute units', 'Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin failed: custom program error: 0x22' ] }

Gsuz avatar Sep 10 '21 16:09 Gsuz

My code is from the example:

await market.placeOrder(connection, {
  owner,
  payer: quoteTokenAddress,
  side: "buy", // 'buy' or 'sell'
  price: 0.11,
  size: 2500,
  orderType: "postOnly", // 'limit', 'ioc', 'postOnly'
});

Gsuz avatar Sep 10 '21 16:09 Gsuz

Not sure, but I think the 'simulation failed' errors are related to some kind of backend RPC issue caused by congestion. That's why it's intermittent. The solution is to run your own validator, but I know that's an expensive answer.

dahifi avatar Sep 12 '21 00:09 dahifi

Can I simply connect to another validator that's less used?

Gsuz avatar Sep 12 '21 10:09 Gsuz

I face the similar issue.

 let result_place_order = await market.placeOrder(connection, {
    owner,
    payer,
    side: 'buy', // 'buy' or 'sell'
    price: 10,
    size: 0.1,
    orderType: 'limit', // 'limit', 'ioc', 'postOnly'
  });
  console.log("Place order result: ", result_place_order)

When connection pointing to https://api.mainnet-beta.solana.com/ it always fails.

(node:91704) UnhandledPromiseRejectionWarning: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x1000760
    at Connection.sendEncodedTransaction (/Users/jiaming/my_project/crypto-trading/node-try/node_modules/@solana/web3.js/lib/index.cjs.js:6936:13)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Connection.sendRawTransaction (/Users/jiaming/my_project/crypto-trading/node-try/node_modules/@solana/web3.js/lib/index.cjs.js:6897:20)
    at async Connection.sendTransaction (/Users/jiaming/my_project/crypto-trading/node-try/node_modules/@solana/web3.js/lib/index.cjs.js:6887:12)
    at async Market._sendTransaction (/Users/jiaming/my_project/crypto-trading/node-try/node_modules/@project-serum/serum/lib/market.js:510:27)
    at async Market.placeOrder (/Users/jiaming/my_project/crypto-trading/node-try/node_modules/@project-serum/serum/lib/market.js:251:16)
    at async run_serum (/Users/jiaming/my_project/crypto-trading/node-try/serum-test.js:47:28)
(node:91704) 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: 1)
(node:91704) [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 change the connection to https://solana-api.projectserum.com/, the order goes through.

In this case, I cannot connect to my own validator to place order.

jimmyntu avatar May 13 '22 05:05 jimmyntu