@typus/typus-perp-sdk 1.0.41 → 1.0.42
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.
- package/dist/src/user/history.js +17 -5
- package/package.json +1 -1
package/dist/src/user/history.js
CHANGED
|
@@ -119,6 +119,7 @@ function parseUserHistory(raw_events) {
|
|
|
119
119
|
var market;
|
|
120
120
|
var size;
|
|
121
121
|
var collateral;
|
|
122
|
+
var reverseSide;
|
|
122
123
|
var order_type;
|
|
123
124
|
var price;
|
|
124
125
|
var action;
|
|
@@ -138,6 +139,7 @@ function parseUserHistory(raw_events) {
|
|
|
138
139
|
collateral = -(Number(json.collateral_in_deposit_token) / Math.pow(10, (0, constants_1.assetToDecimal)(collateral_token)));
|
|
139
140
|
}
|
|
140
141
|
order_type = checkOrderType(json.filled, json.reduce_only, json.is_stop_order);
|
|
142
|
+
reverseSide = (order_type === "Stop Loss" || order_type === "Take Profit") && json.linked_position_id;
|
|
141
143
|
price = json.filled ? json.filled_price : json.trigger_price;
|
|
142
144
|
e = {
|
|
143
145
|
action: "Place Order",
|
|
@@ -145,7 +147,7 @@ function parseUserHistory(raw_events) {
|
|
|
145
147
|
order_id: json.order_id,
|
|
146
148
|
position_id: json.linked_position_id,
|
|
147
149
|
market: market,
|
|
148
|
-
side: json.is_long ? "Long" : "Short",
|
|
150
|
+
side: reverseSide ? (json.is_long ? "Short" : "Long") : json.is_long ? "Long" : "Short",
|
|
149
151
|
order_type: order_type,
|
|
150
152
|
status: json.filled ? "Filled" : "Open",
|
|
151
153
|
size: size,
|
|
@@ -260,13 +262,20 @@ function parseUserHistory(raw_events) {
|
|
|
260
262
|
});
|
|
261
263
|
order_type = checkOrderType(related.contents.json.filled, related.contents.json.reduce_only, related.contents.json.is_stop_order);
|
|
262
264
|
size = Number(related.contents.json.size) / Math.pow(10, (0, constants_1.assetToDecimal)(base_token));
|
|
265
|
+
reverseSide = (order_type === "Stop Loss" || order_type === "Take Profit") && json.linked_position_id;
|
|
263
266
|
e = {
|
|
264
267
|
action: "Cancel Order",
|
|
265
268
|
typeName: name,
|
|
266
269
|
order_id: json.order_id,
|
|
267
270
|
position_id: related.contents.json.linked_position_id,
|
|
268
271
|
market: market,
|
|
269
|
-
side:
|
|
272
|
+
side: reverseSide
|
|
273
|
+
? related.contents.json.is_long
|
|
274
|
+
? "Short"
|
|
275
|
+
: "Long"
|
|
276
|
+
: related.contents.json.is_long
|
|
277
|
+
? "Long"
|
|
278
|
+
: "Short",
|
|
270
279
|
order_type: order_type,
|
|
271
280
|
status: "Canceled",
|
|
272
281
|
size: size,
|
|
@@ -290,11 +299,13 @@ function parseUserHistory(raw_events) {
|
|
|
290
299
|
var eventType = e.contents.type.repr.split("::")[2];
|
|
291
300
|
var orderFilledEvent = structs_1.OrderFilledEvent.$typeName.split("::")[2];
|
|
292
301
|
var checkEventType = eventType == orderFilledEvent;
|
|
302
|
+
//console.log(e);
|
|
293
303
|
return (checkEventType &&
|
|
294
304
|
rawEventJson.new_position_id == json.position_id &&
|
|
295
|
-
rawEventJson.symbol.base_token.name == json.base_token.name
|
|
305
|
+
rawEventJson.symbol.base_token.name == json.base_token.name &&
|
|
306
|
+
rawEventJson.linked_position_id == null);
|
|
296
307
|
});
|
|
297
|
-
size = Number(related.contents.json.
|
|
308
|
+
size = Number(related.contents.json.filled_size) / Math.pow(10, (0, constants_1.assetToDecimal)(base_token));
|
|
298
309
|
if (json.increased_collateral_amount) {
|
|
299
310
|
collateral = Number(json.increased_collateral_amount);
|
|
300
311
|
}
|
|
@@ -320,6 +331,7 @@ function parseUserHistory(raw_events) {
|
|
|
320
331
|
tx_digest: tx_digest,
|
|
321
332
|
};
|
|
322
333
|
events.push(e);
|
|
334
|
+
//console.log(e, related, related.contents.json.symbol, base_token, assetToDecimal(base_token));
|
|
323
335
|
break;
|
|
324
336
|
case structs_3.SwapEvent.$typeName.split("::")[2]:
|
|
325
337
|
var from_token = (0, constants_1.typeArgToAsset)(json.from_token_type.name);
|
|
@@ -337,7 +349,7 @@ function parseUserHistory(raw_events) {
|
|
|
337
349
|
status: "Filled",
|
|
338
350
|
size: Number(json.actual_to_amount) / Math.pow(10, (0, constants_1.assetToDecimal)(to_token)),
|
|
339
351
|
base_token: to_token,
|
|
340
|
-
collateral: Number(json.from_amount) / Math.pow(10, (0, constants_1.assetToDecimal)(from_token)),
|
|
352
|
+
collateral: -Number(json.from_amount) / Math.pow(10, (0, constants_1.assetToDecimal)(from_token)),
|
|
341
353
|
collateral_token: from_token,
|
|
342
354
|
price: from_price / to_price,
|
|
343
355
|
realized_pnl: -Number(json.fee_amount_usd) / Math.pow(10, 9),
|