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

CancelOrderByClientId not working? #18

Open
leofisG opened this issue Dec 4, 2020 · 2 comments
Open

CancelOrderByClientId not working? #18

leofisG opened this issue Dec 4, 2020 · 2 comments

Comments

@leofisG
Copy link
Contributor

leofisG commented Dec 4, 2020

    const connection = new Connection('...');
    const marketAddress = new PublicKey('...');
    const programAccount = new PublicKey("...");
    let market = await Market.load(connection, marketAddress,  { skipPreflight: false, confirmations: 0 }, programAccount);

    const owner = new Account(...)
    const payer = new PublicKey(...)

    const openOrders = await market.findOpenOrdersAccountsForOwner(connection, payer)
    for (const openOrder of openOrders) {
        console.log(openOrder)
        await market.cancelOrderByClientId(connection, owner, openOrder, 0)
    }

And it's telling me:

(node:10605) UnhandledPromiseRejectionWarning: TypeError: src.toArrayLike is not a function
    at BNLayout.encode (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/layout.js:44:33)
    at Structure.encode (/home/wangge/serum_exp/node_modules/buffer-layout/lib/Layout.js:1272:26)
    at VariantLayout.encode (/home/wangge/serum_exp/node_modules/buffer-layout/lib/Layout.js:1914:19)
    at Union.encode (/home/wangge/serum_exp/node_modules/buffer-layout/lib/Layout.js:1730:16)
    at VersionedLayout.encode (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/layout.js:94:31)
    at encodeInstruction (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/instructions.js:41:50)
    at Function.cancelOrderByClientId (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/instructions.js:156:19)
    at Market.makeCancelOrderByClientIdTransaction (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/market.js:412:56)
    at Market.cancelOrderByClientId (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/market.js:407:40)
    at main (file:///home/wangge/serum_exp/index.js:24:22)
(node:10605) 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:10605) [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.

If it's due to the error on my side, it will be really appreciated if someone can provide a working example. Many thanks~

@leofisG
Copy link
Contributor Author

leofisG commented Dec 5, 2020

It turns out that it's an error on my end. So basically the above error is caused by the clientId argument should be a BN instead of a number.

Furthermore, client Id of 0 gets ignored. And it will reports InstructionError(0, Custom(16778880)). So I think the order must have a non-zero client id for it to be able to get cancelled.

If the user supplies an id that doesn't exist in the open order, say the order book only has an order with client id 22, but the client tries to cancel 23 it will throw an InstructionError(0, Custom(41)) corresponding to ClientIdNotFound(here).

Also, I think this error only get thrown if there are no (whether cancelled or not) orders from the given OpenOrdersAccount.
So say, I used to have an order with client Id, say, 22 but it got cancelled. If I want to cancel it again, it will not throw Custom(41) error.

@leofisG
Copy link
Contributor Author

leofisG commented Dec 5, 2020

Actually not sure if we want to support 0 as a valid client id, maybe easier to understand if 0 can also work instead of producing an error....
Or at least output an error on the client side say something like it should be non-zero.

@leofisG leofisG reopened this Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant