From 1a995c691acd63a8988612646225f69ea6fb2d87 Mon Sep 17 00:00:00 2001 From: Binye Barwe Date: Fri, 2 Feb 2024 20:02:35 +0800 Subject: [PATCH] add placeOrders to the sdk --- package.json | 2 +- ts/client/src/client.ts | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f61667138..3f9155713 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@openbook-dex/openbook-v2", - "version": "0.1.8", + "version": "0.1.9", "description": "Typescript Client for openbook-v2 program.", "repository": "https://github.com/openbook-dex/openbook-v2/", "author": { diff --git a/ts/client/src/client.ts b/ts/client/src/client.ts index 6e6fb1464..8ee2c0fe1 100644 --- a/ts/client/src/client.ts +++ b/ts/client/src/client.ts @@ -803,6 +803,49 @@ export class OpenBookV2Client { return [ix, signers]; } + // Use OrderType from './utils/utils' for orderType + public async placeOrdersIx( + openOrdersPublicKey: PublicKey, + marketPublicKey: PublicKey, + market: MarketAccount, + userBaseAccount: PublicKey, + userQuoteAccount: PublicKey, + openOrdersAdmin: PublicKey | null, + orderType: PlaceOrderType, + bids: PlaceMultipleOrdersArgs[], + asks: PlaceMultipleOrdersArgs[], + limit: number = 12, + openOrdersDelegate?: Keypair, + ): Promise<[TransactionInstruction, Signer[]]> { + const ix = await this.program.methods + .placeOrders(orderType, bids, asks, limit) + .accounts({ + signer: + openOrdersDelegate != null + ? openOrdersDelegate.publicKey + : this.walletPk, + asks: market.asks, + bids: market.bids, + marketQuoteVault: market.marketQuoteVault, + marketBaseVault: market.marketBaseVault, + eventHeap: market.eventHeap, + market: marketPublicKey, + openOrdersAccount: openOrdersPublicKey, + oracleA: market.oracleA.key, + oracleB: market.oracleB.key, + userBaseAccount, + userQuoteAccount, + tokenProgram: TOKEN_PROGRAM_ID, + openOrdersAdmin, + }) + .instruction(); + const signers: Signer[] = []; + if (openOrdersDelegate != null) { + signers.push(openOrdersDelegate); + } + return [ix, signers]; + } + public async cancelOrderById( openOrdersPublicKey: PublicKey, openOrdersAccount: OpenOrdersAccount,