Skip to content

Commit

Permalink
New fn updateOpenOrdersSync (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipzeta authored Sep 18, 2023
1 parent 6c7e872 commit 022f091
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Version changes are pinned to SDK releases.

## Unreleased

## [1.10.3] 2023-09-18

- New function updateOpenOrdersSync() in CrossClient. ([#272](https://github.com/zetamarkets/sdk/pull/272))

## [1.10.2] 2023-09-15

- Bugfix: Unsubscribe from orderbooks on Exchange.close(). ([#271](https://github.com/zetamarkets/sdk/pull/271))
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.10.2",
"version": "1.10.3",
"description": "Zeta SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
34 changes: 18 additions & 16 deletions src/cross-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2360,24 +2360,22 @@ export class CrossClient {
return this._positions.get(asset);
}

public async updateOrders() {
public updateOpenOrdersSync() {
if (this._account == null) {
console.log("User has no margin account, cannot update orders.");
return;
}

let orders = [];

await Promise.all(
Exchange.assets.map(async (asset) => {
let market = Exchange.getPerpMarket(asset);
orders.push(
market.getOrdersForAccount(
this._openOrdersAccounts[assetToIndex(asset)]
)
);
})
);
Exchange.assets.forEach((asset) => {
let market = Exchange.getPerpMarket(asset);
orders.push(
market.getOrdersForAccount(
this._openOrdersAccounts[assetToIndex(asset)]
)
);
});

let allOrders = [].concat(...orders);
let allOrdersFiltered = allOrders.filter(function (order: types.Order) {
Expand All @@ -2395,16 +2393,20 @@ export class CrossClient {
);
});
let ordersByAsset = new Map();
await Promise.all(
Exchange.assets.map(async (asset) => {
ordersByAsset.set(asset, []);
})
);

Exchange.assets.forEach((asset) => {
ordersByAsset.set(asset, []);
});

for (var order of allOrdersFiltered) {
ordersByAsset.get(order.asset).push(order);
}

this._orders = ordersByAsset;
}

public async updateOrders() {
this.updateOpenOrdersSync();

let triggerOrderBits = [];

Expand Down

0 comments on commit 022f091

Please sign in to comment.