@typus/typus-perp-sdk 1.1.10 → 1.1.11

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" | "Realized Funding";
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";
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";
@@ -153,20 +153,23 @@ function parseUserHistory(raw_events) {
153
153
  var price = json.filled_price;
154
154
  var action;
155
155
  var related;
156
+ var collateral;
157
+ var realized_trading_fee = Number(json.realized_trading_fee) + Number(json.realized_borrow_fee);
158
+ var realized_fee_in_usd = Number(json.realized_fee_in_usd) / Math.pow(10, 9);
159
+ var realized_amount = json.realized_amount_sign ? Number(json.realized_amount) : -Number(json.realized_amount);
160
+ // console.log(realized_amount);
161
+ var realized_pnl = realized_trading_fee > 0 ? ((realized_amount - realized_trading_fee) * realized_fee_in_usd) / realized_trading_fee : 0;
156
162
  if (json.linked_position_id != undefined) {
157
163
  action = "Order Filled (Close Position)";
158
164
  related = events.findLast(function (e) { return e.position_id === json.linked_position_id && e.market === market; });
159
165
  // the "Place Order" is emit after Order Filled if filled immediately
166
+ collateral = (realized_amount - realized_trading_fee) / Math.pow(10, (0, constants_1.assetToDecimal)(collateral_token));
160
167
  }
161
168
  else {
162
169
  action = "Order Filled (Open Position)";
163
170
  related = events.findLast(function (e) { return e.order_id === json.order_id && e.market === market; });
171
+ collateral = related === null || related === void 0 ? void 0 : related.collateral;
164
172
  }
165
- var realized_trading_fee = Number(json.realized_trading_fee) + Number(json.realized_borrow_fee);
166
- var realized_fee_in_usd = Number(json.realized_fee_in_usd) / Math.pow(10, 9);
167
- var realized_amount = json.realized_amount_sign ? Number(json.realized_amount) : -Number(json.realized_amount);
168
- // console.log(realized_amount);
169
- var realized_pnl = realized_trading_fee > 0 ? ((realized_amount - realized_trading_fee) * realized_fee_in_usd) / realized_trading_fee : 0;
170
173
  var e = {
171
174
  action: action,
172
175
  typeName: name,
@@ -178,7 +181,7 @@ function parseUserHistory(raw_events) {
178
181
  status: "Filled",
179
182
  size: size,
180
183
  base_token: base_token,
181
- collateral: related === null || related === void 0 ? void 0 : related.collateral, // TODO: check for option collateral
184
+ collateral: collateral, // TODO: check for option collateral
182
185
  collateral_token: collateral_token,
183
186
  price: Number(price) / Math.pow(10, 8), // WARNING: fixed decimal
184
187
  realized_pnl: realized_pnl,
@@ -196,7 +199,7 @@ function parseUserHistory(raw_events) {
196
199
  if (index !== -1) {
197
200
  // true => user paid to pool
198
201
  var remaining_collateral_amount = json.remaining_collateral_amount / Math.pow(10, (0, constants_1.assetToDecimal)(events[index].collateral_token));
199
- events[index] = __assign(__assign({}, events[index]), { collateral: remaining_collateral_amount + Math.max(0, events[index].realized_pnl) });
202
+ events[index] = __assign(__assign({}, events[index]), { collateral: remaining_collateral_amount + Math.max(0, events[index].collateral) });
200
203
  }
201
204
  break;
202
205
  case structs_1.RealizeFundingEvent.$typeName.split("::")[2]:
@@ -223,7 +226,7 @@ function parseUserHistory(raw_events) {
223
226
  ? -json.realized_funding_fee_usd / Math.pow(10, 9)
224
227
  : json.realized_funding_fee_usd / Math.pow(10, 9);
225
228
  var e = {
226
- action: "Realized Funding",
229
+ action: "Realize Funding",
227
230
  typeName: name,
228
231
  order_id: undefined,
229
232
  position_id: json.position_id,
@@ -444,7 +447,7 @@ function getRealizeFundingFromSentio(userAddress, startTimestamp, events) {
444
447
  realizeFunding = datas.map(function (x) {
445
448
  var base_token = toToken(x.base_token);
446
449
  var txHistory = {
447
- action: "Realized Funding",
450
+ action: "Realize Funding",
448
451
  typeName: "RealizeFundingEvent",
449
452
  order_id: undefined,
450
453
  position_id: x.position_id,
@@ -466,7 +469,7 @@ function getRealizeFundingFromSentio(userAddress, startTimestamp, events) {
466
469
  return txHistory;
467
470
  });
468
471
  // deduplicate
469
- realizeFunding = realizeFunding.filter(function (x) { return events.findIndex(function (y) { return y.tx_digest == x.tx_digest && y.action == "Realized Funding"; }) == -1; });
472
+ realizeFunding = realizeFunding.filter(function (x) { return events.findIndex(function (y) { return y.tx_digest == x.tx_digest && y.action == "Realize Funding"; }) == -1; });
470
473
  realizeFunding = realizeFunding.map(function (x) {
471
474
  // find related position
472
475
  var related = events.find(function (e) { return e.position_id === x.position_id && e.market === x.market; });
@@ -504,7 +507,7 @@ function getRemovePositionFromSentio(userAddress, startTimestamp, events) {
504
507
  if (index !== -1) {
505
508
  // true => user paid to pool
506
509
  var remaining_collateral_amount = x.remaining_collateral_amount;
507
- events[index] = __assign(__assign({}, events[index]), { collateral: remaining_collateral_amount + Math.max(0, events[index].realized_pnl) });
510
+ events[index] = __assign(__assign({}, events[index]), { collateral: remaining_collateral_amount + Math.max(0, events[index].collateral) });
508
511
  }
509
512
  });
510
513
  return [2 /*return*/, events];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
5
5
  "author": "Typus",
6
6
  "description": "typus perp sdk",