@typus/typus-perp-sdk 1.1.24 → 1.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { TOKEN } from "@typus/typus-sdk/dist/src/constants";
2
- export type actionType = "Place Order" | "Cancel Order" | "Order Filled (Open Position)" | "Order Filled (Close Position)" | "Realized PnL" | "Modify Collateral" | "Exercise Position" | "Liquidation" | "Force Cancel Order" | "Force Close Position" | "Swap" | "Realize Funding";
2
+ export type actionType = "Place Order" | "Cancel Order" | "Order Filled (Open Position)" | "Order Filled (Increase Position)" | "Order Filled (Close Position)" | "Realized PnL" | "Modify Collateral" | "Exercise Position" | "Liquidation" | "Force Cancel Order" | "Force Close Position" | "Swap" | "Realize Funding";
3
3
  export type sideType = "Long" | "Short";
4
4
  export type orderType = "Market" | "Limit" | "Take Profit" | "Stop Loss";
5
5
  export type statusType = "Open" | "Filled" | "Canceled";
@@ -21,6 +21,8 @@ export interface Event {
21
21
  timestamp: string;
22
22
  tx_digest: string;
23
23
  dov_index: string | undefined;
24
+ reduce_only?: boolean;
25
+ is_stop_order?: boolean;
24
26
  sender: "user" | "cranker";
25
27
  }
26
28
  export declare function parseUserHistory(raw_events: any): Promise<Event[]>;
@@ -84,7 +84,7 @@ function parseUserHistory(raw_events) {
84
84
  return __generator(this, function (_a) {
85
85
  events = [];
86
86
  raw_events.forEach(function (event) {
87
- var _a, _b, _c, _d;
87
+ var _a, _b, _c, _d, _e, _f;
88
88
  var type = event.contents.type.repr;
89
89
  if (type.endsWith("PythPrice")) {
90
90
  return;
@@ -96,7 +96,7 @@ function parseUserHistory(raw_events) {
96
96
  // console.log(tx_digest);
97
97
  // console.log(json);
98
98
  // console.log(timestamp);
99
- var _e = __read(type.split("::"), 3), pkg = _e[0], mod = _e[1], name = _e[2];
99
+ var _g = __read(type.split("::"), 3), pkg = _g[0], mod = _g[1], name = _g[2];
100
100
  switch (name) {
101
101
  case structs_2.CreateTradingOrderEvent.$typeName.split("::")[2]:
102
102
  case structs_2.CreateTradingOrderWithBidReceiptsEvent.$typeName.split("::")[2]:
@@ -141,6 +141,8 @@ function parseUserHistory(raw_events) {
141
141
  timestamp: timestamp,
142
142
  tx_digest: tx_digest,
143
143
  dov_index: json.dov_index,
144
+ reduce_only: json.reduce_only,
145
+ is_stop_order: json.is_stop_order,
144
146
  sender: "user",
145
147
  };
146
148
  events.push(e);
@@ -163,6 +165,14 @@ function parseUserHistory(raw_events) {
163
165
  action = "Order Filled (Close Position)";
164
166
  related = events.findLast(function (e) { return e.position_id === json.linked_position_id && e.market === market; });
165
167
  // the "Place Order" is emit after Order Filled if filled immediately
168
+ var relatedRawEvent = raw_events.find(function (e) {
169
+ var type = e.contents.type.repr;
170
+ var _a = __read(type.split("::"), 3), pkg = _a[0], mod = _a[1], name = _a[2];
171
+ return name === (related === null || related === void 0 ? void 0 : related.typeName) && e.transactionBlock.digest === (related === null || related === void 0 ? void 0 : related.tx_digest) && (related === null || related === void 0 ? void 0 : related.order_id) === json.order_id;
172
+ });
173
+ if (((_b = (_a = relatedRawEvent === null || relatedRawEvent === void 0 ? void 0 : relatedRawEvent.contents) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.reduce_only) === false) {
174
+ action = "Order Filled (Increase Position)";
175
+ }
166
176
  if (realized_pnl > 0) {
167
177
  collateral = (realized_amount - realized_trading_fee) / Math.pow(10, (0, constants_1.assetToDecimal)(collateral_token));
168
178
  }
@@ -176,7 +186,7 @@ function parseUserHistory(raw_events) {
176
186
  action: action,
177
187
  typeName: name,
178
188
  order_id: json.order_id,
179
- position_id: (_a = json.linked_position_id) !== null && _a !== void 0 ? _a : json.new_position_id,
189
+ position_id: (_c = json.linked_position_id) !== null && _c !== void 0 ? _c : json.new_position_id,
180
190
  market: market,
181
191
  side: json.position_side ? "Long" : "Short",
182
192
  order_type: related === null || related === void 0 ? void 0 : related.order_type,
@@ -201,7 +211,7 @@ function parseUserHistory(raw_events) {
201
211
  if (index !== -1) {
202
212
  // true => user paid to pool
203
213
  var remaining_collateral_amount = json.remaining_collateral_amount / Math.pow(10, (0, constants_1.assetToDecimal)(events[index].collateral_token));
204
- events[index] = __assign(__assign({}, events[index]), { collateral: remaining_collateral_amount + ((_b = events[index].collateral) !== null && _b !== void 0 ? _b : 0) });
214
+ events[index] = __assign(__assign({}, events[index]), { collateral: remaining_collateral_amount + ((_d = events[index].collateral) !== null && _d !== void 0 ? _d : 0) });
205
215
  }
206
216
  break;
207
217
  case structs_1.RealizeFundingEvent.$typeName.split("::")[2]:
@@ -221,7 +231,7 @@ function parseUserHistory(raw_events) {
221
231
  // console.log(index);
222
232
  if (index !== -1) {
223
233
  // true => user paid to pool
224
- events[index] = __assign(__assign({}, events[index]), { collateral: (_c = events[index].collateral) !== null && _c !== void 0 ? _c : 0 - realized_funding_fee, realized_pnl: (_d = events[index].realized_pnl) !== null && _d !== void 0 ? _d : 0 - realized_funding_fee_usd });
234
+ events[index] = __assign(__assign({}, events[index]), { collateral: (_e = events[index].collateral) !== null && _e !== void 0 ? _e : 0 - realized_funding_fee, realized_pnl: (_f = events[index].realized_pnl) !== null && _f !== void 0 ? _f : 0 - realized_funding_fee_usd });
225
235
  }
226
236
  var e = {
227
237
  action: "Realize Funding",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.1.24",
3
+ "version": "1.1.26",
4
4
  "repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
5
5
  "author": "Typus",
6
6
  "description": "typus perp sdk",