Skip to content

Commit

Permalink
preixs to place order and create place trigger order ix (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinlau20100 authored Jan 22, 2024
1 parent 0ba8e7b commit 52a321b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
Version changes are pinned to SDK releases.

## [1.18.4]

- Add preixs to cross client place order and create place trigger order ix. ([#341](https://github.com/zetamarkets/sdk/pull/341))

## [1.18.3]

- Add fake cancel optionality for get max trade size. ([#338](https://github.com/zetamarkets/sdk/pull/338))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zetamarkets/sdk",
"repository": "https://github.com/zetamarkets/sdk/",
"version": "1.18.3",
"version": "1.18.4",
"description": "Zeta SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
52 changes: 51 additions & 1 deletion src/cross-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,8 @@ export class CrossClient {
price: number,
size: number,
side: types.Side,
options: types.OrderOptions = types.defaultOrderOptions()
options: types.OrderOptions = types.defaultOrderOptions(),
preIxs: TransactionInstruction[] = []
): Promise<TransactionSignature> {
let tx = new Transaction();
let assetIndex = assetToIndex(asset);
Expand All @@ -1054,6 +1055,10 @@ export class CrossClient {
openOrdersPda = this._openOrdersAccounts[assetIndex];
}

if (preIxs.length > 0) {
tx.add(...preIxs);
}

let tifOffsetToUse = utils.getTIFOffset(market, options.tifOptions);

let orderIx = instructions.placePerpOrderV4Ix(
Expand Down Expand Up @@ -1222,6 +1227,51 @@ export class CrossClient {
return txId;
}

/*
* Note: When using this you must pass in the trigger order bit yourself, you can do this by calling
* CrossClient.findAvailableTriggerOrderBit(),
* If you need to create more than one instruction atomically
* put in consecutvie nubmers for triggerOrderBit
*/
public createPlaceTriggerOrderIx(
asset: Asset,
orderPrice: number,
size: number,
side: types.Side,
triggerPrice: number,
triggerDirection: types.TriggerDirection = types.getDefaultTriggerDirection(
side
),
triggerTimestamp: anchor.BN,
orderType: types.OrderType,
triggerOrderBit: number,
options: types.TriggerOrderOptions = types.defaultTriggerOrderOptions()
): TransactionInstruction {
let assetIndex = assets.assetToIndex(asset);

if (this._openOrdersAccounts[assetIndex].equals(PublicKey.default)) {
throw Error("User has no open orders account.");
}
let openOrdersPda = this._openOrdersAccounts[assetIndex];

return instructions.placeTriggerOrderIx(
asset,
orderPrice,
triggerPrice,
triggerDirection,
triggerTimestamp,
triggerOrderBit,
size,
side,
orderType,
options.reduceOnly != undefined ? options.reduceOnly : false,
options.tag,
this.accountAddress,
this._provider.wallet.publicKey,
openOrdersPda
);
}

public async cancelAllTriggerOrders(asset: Asset | undefined) {
let orders = [];
if (asset == undefined) {
Expand Down

0 comments on commit 52a321b

Please sign in to comment.