@lifi/perps-sdk 0.0.0-preview-8effdce → 0.0.0-preview-dba4b08
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/cjs/math/fills.d.ts.map +1 -1
- package/dist/cjs/math/fills.js +15 -14
- package/dist/cjs/math/fills.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/math/fills.d.ts +5 -1
- package/dist/esm/math/fills.d.ts.map +1 -1
- package/dist/esm/math/fills.js +20 -15
- package/dist/esm/math/fills.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/math/fills.d.ts +5 -1
- package/dist/types/math/fills.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/math/fills.ts +24 -15
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fills.d.ts","sourceRoot":"","sources":["../../../src/math/fills.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,SAAS,EACV,MAAM,mBAAmB,CAAA;AAQ1B,OAAO,EAAE,kBAAkB,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"fills.d.ts","sourceRoot":"","sources":["../../../src/math/fills.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,SAAS,EACV,MAAM,mBAAmB,CAAA;AAQ1B,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAc7B,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,aAAa,GAChB,kBAAkB,CAqCpB;AAUD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,GAC5C,kBAAkB,CAYpB"}
|
package/dist/cjs/math/fills.js
CHANGED
|
@@ -5,41 +5,42 @@ exports.classifyFillFromPosition = classifyFillFromPosition;
|
|
|
5
5
|
exports.classifyFill = classifyFill;
|
|
6
6
|
const perps_types_1 = require("@lifi/perps-types");
|
|
7
7
|
Object.defineProperty(exports, "FillClassification", { enumerable: true, get: function () { return perps_types_1.FillClassification; } });
|
|
8
|
-
const
|
|
8
|
+
const requireDecimal_js_1 = require("../decimal/requireDecimal.js");
|
|
9
9
|
function classifyFillFromPosition(startPosition, side, sz) {
|
|
10
|
-
const start =
|
|
11
|
-
const
|
|
12
|
-
const end = start
|
|
13
|
-
if (start
|
|
14
|
-
return end
|
|
10
|
+
const start = (0, requireDecimal_js_1.requireDecimal)(startPosition, 'classifyFillFromPosition(startPosition)');
|
|
11
|
+
const size = (0, requireDecimal_js_1.requireDecimal)(sz, 'classifyFillFromPosition(sz)');
|
|
12
|
+
const end = side === 'B' ? start.plus(size) : start.minus(size);
|
|
13
|
+
if (start.eq(0)) {
|
|
14
|
+
return end.gt(0)
|
|
15
15
|
? perps_types_1.FillClassification.OPENED_LONG
|
|
16
16
|
: perps_types_1.FillClassification.OPENED_SHORT;
|
|
17
17
|
}
|
|
18
|
-
if (start
|
|
19
|
-
if (end
|
|
18
|
+
if (start.gt(0)) {
|
|
19
|
+
if (end.eq(0)) {
|
|
20
20
|
return perps_types_1.FillClassification.CLOSED_LONG;
|
|
21
21
|
}
|
|
22
|
-
if (end
|
|
22
|
+
if (end.lt(0)) {
|
|
23
23
|
return perps_types_1.FillClassification.SWITCHED_SHORT;
|
|
24
24
|
}
|
|
25
|
-
if (end
|
|
25
|
+
if (end.gt(start)) {
|
|
26
26
|
return perps_types_1.FillClassification.INCREASED_LONG;
|
|
27
27
|
}
|
|
28
28
|
return perps_types_1.FillClassification.REDUCED_LONG;
|
|
29
29
|
}
|
|
30
|
-
if (end
|
|
30
|
+
if (end.eq(0)) {
|
|
31
31
|
return perps_types_1.FillClassification.CLOSED_SHORT;
|
|
32
32
|
}
|
|
33
|
-
if (end
|
|
33
|
+
if (end.gt(0)) {
|
|
34
34
|
return perps_types_1.FillClassification.SWITCHED_LONG;
|
|
35
35
|
}
|
|
36
|
-
if (end
|
|
36
|
+
if (end.lt(start)) {
|
|
37
37
|
return perps_types_1.FillClassification.INCREASED_SHORT;
|
|
38
38
|
}
|
|
39
39
|
return perps_types_1.FillClassification.REDUCED_SHORT;
|
|
40
40
|
}
|
|
41
41
|
function classifyFill(side, realizedPnl) {
|
|
42
|
-
const isClose = realizedPnl != null &&
|
|
42
|
+
const isClose = realizedPnl != null &&
|
|
43
|
+
!(0, requireDecimal_js_1.requireDecimal)(realizedPnl, 'classifyFill(realizedPnl)').eq(0);
|
|
43
44
|
if (side === perps_types_1.OrderSide.BUY) {
|
|
44
45
|
return isClose
|
|
45
46
|
? perps_types_1.FillClassification.CLOSED_SHORT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fills.js","sourceRoot":"","sources":["../../../src/math/fills.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"fills.js","sourceRoot":"","sources":["../../../src/math/fills.ts"],"names":[],"mappings":";;;AA0BA,4DAyCC;AAUD,oCAeC;AA5FD,mDAI0B;AAQjB,mGAVP,gCAAkB,OAUO;AAP3B,oEAA6D;AAqB7D,SAAgB,wBAAwB,CACtC,aAA4B,EAC5B,IAAY,EACZ,EAAiB;IAEjB,MAAM,KAAK,GAAG,IAAA,kCAAc,EAC1B,aAAa,EACb,yCAAyC,CAC1C,CAAA;IACD,MAAM,IAAI,GAAG,IAAA,kCAAc,EAAC,EAAE,EAAE,8BAA8B,CAAC,CAAA;IAC/D,MAAM,GAAG,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAE/D,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAA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CAAC,gCAAkB,CAAC,YAAY;YACjC,CAAC,CAAC,gCAAkB,CAAC,WAAW,CAAA;IACpC,CAAC;IACD,OAAO,OAAO;QACZ,CAAC,CAAC,gCAAkB,CAAC,WAAW;QAChC,CAAC,CAAC,gCAAkB,CAAC,YAAY,CAAA;AACrC,CAAC"}
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
package/dist/esm/math/fills.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ export { FillClassification };
|
|
|
12
12
|
* @param startPosition Signed position held BEFORE this fill (`> 0` long,
|
|
13
13
|
* `< 0` short, `0` flat).
|
|
14
14
|
* @param side Hyperliquid-style: `'B'` for buy, anything else for sell.
|
|
15
|
-
* @param sz Unsigned fill size
|
|
15
|
+
* @param sz Unsigned fill size.
|
|
16
|
+
* @throws {PerpsError} `ValidationError` when `startPosition` or `sz` is not a
|
|
17
|
+
* decimal string.
|
|
16
18
|
* @public
|
|
17
19
|
*/
|
|
18
20
|
export declare function classifyFillFromPosition(startPosition: DecimalString, side: string, sz: DecimalString): FillClassification;
|
|
@@ -20,6 +22,8 @@ export declare function classifyFillFromPosition(startPosition: DecimalString, s
|
|
|
20
22
|
* Classify a fill as open or close based on realizedPnl.
|
|
21
23
|
* @deprecated Use `Fill.classification` instead — it uses startPosition
|
|
22
24
|
* for accurate open/increase/reduce/close/reverse classification.
|
|
25
|
+
* @throws {PerpsError} `ValidationError` when `realizedPnl` is a string that
|
|
26
|
+
* is not a decimal string.
|
|
23
27
|
* @public
|
|
24
28
|
*/
|
|
25
29
|
export declare function classifyFill(side: OrderSide, realizedPnl: DecimalString | null | undefined): FillClassification;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fills.d.ts","sourceRoot":"","sources":["../../../src/math/fills.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,SAAS,EACV,MAAM,mBAAmB,CAAA;AAG1B;;;;GAIG;AACH,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B
|
|
1
|
+
{"version":3,"file":"fills.d.ts","sourceRoot":"","sources":["../../../src/math/fills.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,SAAS,EACV,MAAM,mBAAmB,CAAA;AAG1B;;;;GAIG;AACH,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,aAAa,GAChB,kBAAkB,CAqCpB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,GAC5C,kBAAkB,CAYpB"}
|
package/dist/esm/math/fills.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FillClassification, OrderSide, } from '@lifi/perps-types';
|
|
2
|
-
import {
|
|
2
|
+
import { requireDecimal } from '../decimal/requireDecimal.js';
|
|
3
3
|
/**
|
|
4
4
|
* Re-exported fill taxonomy used by {@link classifyFillFromPosition}.
|
|
5
5
|
*
|
|
@@ -13,37 +13,39 @@ export { FillClassification };
|
|
|
13
13
|
* @param startPosition Signed position held BEFORE this fill (`> 0` long,
|
|
14
14
|
* `< 0` short, `0` flat).
|
|
15
15
|
* @param side Hyperliquid-style: `'B'` for buy, anything else for sell.
|
|
16
|
-
* @param sz Unsigned fill size
|
|
16
|
+
* @param sz Unsigned fill size.
|
|
17
|
+
* @throws {PerpsError} `ValidationError` when `startPosition` or `sz` is not a
|
|
18
|
+
* decimal string.
|
|
17
19
|
* @public
|
|
18
20
|
*/
|
|
19
21
|
export function classifyFillFromPosition(startPosition, side, sz) {
|
|
20
|
-
const start =
|
|
21
|
-
const
|
|
22
|
-
const end = start
|
|
23
|
-
if (start
|
|
24
|
-
return end
|
|
22
|
+
const start = requireDecimal(startPosition, 'classifyFillFromPosition(startPosition)');
|
|
23
|
+
const size = requireDecimal(sz, 'classifyFillFromPosition(sz)');
|
|
24
|
+
const end = side === 'B' ? start.plus(size) : start.minus(size);
|
|
25
|
+
if (start.eq(0)) {
|
|
26
|
+
return end.gt(0)
|
|
25
27
|
? FillClassification.OPENED_LONG
|
|
26
28
|
: FillClassification.OPENED_SHORT;
|
|
27
29
|
}
|
|
28
|
-
if (start
|
|
29
|
-
if (end
|
|
30
|
+
if (start.gt(0)) {
|
|
31
|
+
if (end.eq(0)) {
|
|
30
32
|
return FillClassification.CLOSED_LONG;
|
|
31
33
|
}
|
|
32
|
-
if (end
|
|
34
|
+
if (end.lt(0)) {
|
|
33
35
|
return FillClassification.SWITCHED_SHORT;
|
|
34
36
|
}
|
|
35
|
-
if (end
|
|
37
|
+
if (end.gt(start)) {
|
|
36
38
|
return FillClassification.INCREASED_LONG;
|
|
37
39
|
}
|
|
38
40
|
return FillClassification.REDUCED_LONG;
|
|
39
41
|
}
|
|
40
|
-
if (end
|
|
42
|
+
if (end.eq(0)) {
|
|
41
43
|
return FillClassification.CLOSED_SHORT;
|
|
42
44
|
}
|
|
43
|
-
if (end
|
|
45
|
+
if (end.gt(0)) {
|
|
44
46
|
return FillClassification.SWITCHED_LONG;
|
|
45
47
|
}
|
|
46
|
-
if (end
|
|
48
|
+
if (end.lt(start)) {
|
|
47
49
|
return FillClassification.INCREASED_SHORT;
|
|
48
50
|
}
|
|
49
51
|
return FillClassification.REDUCED_SHORT;
|
|
@@ -52,10 +54,13 @@ export function classifyFillFromPosition(startPosition, side, sz) {
|
|
|
52
54
|
* Classify a fill as open or close based on realizedPnl.
|
|
53
55
|
* @deprecated Use `Fill.classification` instead — it uses startPosition
|
|
54
56
|
* for accurate open/increase/reduce/close/reverse classification.
|
|
57
|
+
* @throws {PerpsError} `ValidationError` when `realizedPnl` is a string that
|
|
58
|
+
* is not a decimal string.
|
|
55
59
|
* @public
|
|
56
60
|
*/
|
|
57
61
|
export function classifyFill(side, realizedPnl) {
|
|
58
|
-
const isClose = realizedPnl != null &&
|
|
62
|
+
const isClose = realizedPnl != null &&
|
|
63
|
+
!requireDecimal(realizedPnl, 'classifyFill(realizedPnl)').eq(0);
|
|
59
64
|
if (side === OrderSide.BUY) {
|
|
60
65
|
return isClose
|
|
61
66
|
? FillClassification.CLOSED_SHORT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fills.js","sourceRoot":"","sources":["../../../src/math/fills.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,SAAS,GACV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fills.js","sourceRoot":"","sources":["../../../src/math/fills.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,SAAS,GACV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAE7D;;;;GAIG;AACH,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,wBAAwB,CACtC,aAA4B,EAC5B,IAAY,EACZ,EAAiB;IAEjB,MAAM,KAAK,GAAG,cAAc,CAC1B,aAAa,EACb,yCAAyC,CAC1C,CAAA;IACD,MAAM,IAAI,GAAG,cAAc,CAAC,EAAE,EAAE,8BAA8B,CAAC,CAAA;IAC/D,MAAM,GAAG,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAE/D,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChB,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;YACd,CAAC,CAAC,kBAAkB,CAAC,WAAW;YAChC,CAAC,CAAC,kBAAkB,CAAC,YAAY,C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AAkB,CAAC,WAAW;QAChC,CAAC,CAAC,kBAAkB,CAAC,YAAY,CAAA;AACrC,CAAC"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
|
@@ -12,7 +12,9 @@ export { FillClassification };
|
|
|
12
12
|
* @param startPosition Signed position held BEFORE this fill (`> 0` long,
|
|
13
13
|
* `< 0` short, `0` flat).
|
|
14
14
|
* @param side Hyperliquid-style: `'B'` for buy, anything else for sell.
|
|
15
|
-
* @param sz Unsigned fill size
|
|
15
|
+
* @param sz Unsigned fill size.
|
|
16
|
+
* @throws {PerpsError} `ValidationError` when `startPosition` or `sz` is not a
|
|
17
|
+
* decimal string.
|
|
16
18
|
* @public
|
|
17
19
|
*/
|
|
18
20
|
export declare function classifyFillFromPosition(startPosition: DecimalString, side: string, sz: DecimalString): FillClassification;
|
|
@@ -20,6 +22,8 @@ export declare function classifyFillFromPosition(startPosition: DecimalString, s
|
|
|
20
22
|
* Classify a fill as open or close based on realizedPnl.
|
|
21
23
|
* @deprecated Use `Fill.classification` instead — it uses startPosition
|
|
22
24
|
* for accurate open/increase/reduce/close/reverse classification.
|
|
25
|
+
* @throws {PerpsError} `ValidationError` when `realizedPnl` is a string that
|
|
26
|
+
* is not a decimal string.
|
|
23
27
|
* @public
|
|
24
28
|
*/
|
|
25
29
|
export declare function classifyFill(side: OrderSide, realizedPnl: DecimalString | null | undefined): FillClassification;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fills.d.ts","sourceRoot":"","sources":["../../../src/math/fills.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,SAAS,EACV,MAAM,mBAAmB,CAAA;AAG1B;;;;GAIG;AACH,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B
|
|
1
|
+
{"version":3,"file":"fills.d.ts","sourceRoot":"","sources":["../../../src/math/fills.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,SAAS,EACV,MAAM,mBAAmB,CAAA;AAG1B;;;;GAIG;AACH,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,aAAa,GAChB,kBAAkB,CAqCpB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,GAC5C,kBAAkB,CAYpB"}
|
package/dist/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-dba4b08",
|
|
4
4
|
"description": "LI.FI Perps SDK for perpetuals trading",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"big.js": "^7.0.1",
|
|
47
47
|
"partysocket": "^1.1.19",
|
|
48
48
|
"viem": "^2.55.18",
|
|
49
|
-
"@lifi/perps-types": "^
|
|
49
|
+
"@lifi/perps-types": "^20.2.0"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
package/src/math/fills.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
FillClassification,
|
|
4
4
|
OrderSide,
|
|
5
5
|
} from '@lifi/perps-types'
|
|
6
|
-
import {
|
|
6
|
+
import { requireDecimal } from '../decimal/requireDecimal.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Re-exported fill taxonomy used by {@link classifyFillFromPosition}.
|
|
@@ -19,7 +19,9 @@ export { FillClassification }
|
|
|
19
19
|
* @param startPosition Signed position held BEFORE this fill (`> 0` long,
|
|
20
20
|
* `< 0` short, `0` flat).
|
|
21
21
|
* @param side Hyperliquid-style: `'B'` for buy, anything else for sell.
|
|
22
|
-
* @param sz Unsigned fill size
|
|
22
|
+
* @param sz Unsigned fill size.
|
|
23
|
+
* @throws {PerpsError} `ValidationError` when `startPosition` or `sz` is not a
|
|
24
|
+
* decimal string.
|
|
23
25
|
* @public
|
|
24
26
|
*/
|
|
25
27
|
export function classifyFillFromPosition(
|
|
@@ -27,36 +29,39 @@ export function classifyFillFromPosition(
|
|
|
27
29
|
side: string,
|
|
28
30
|
sz: DecimalString
|
|
29
31
|
): FillClassification {
|
|
30
|
-
const start =
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const start = requireDecimal(
|
|
33
|
+
startPosition,
|
|
34
|
+
'classifyFillFromPosition(startPosition)'
|
|
35
|
+
)
|
|
36
|
+
const size = requireDecimal(sz, 'classifyFillFromPosition(sz)')
|
|
37
|
+
const end = side === 'B' ? start.plus(size) : start.minus(size)
|
|
33
38
|
|
|
34
|
-
if (start
|
|
35
|
-
return end
|
|
39
|
+
if (start.eq(0)) {
|
|
40
|
+
return end.gt(0)
|
|
36
41
|
? FillClassification.OPENED_LONG
|
|
37
42
|
: FillClassification.OPENED_SHORT
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
if (start
|
|
41
|
-
if (end
|
|
45
|
+
if (start.gt(0)) {
|
|
46
|
+
if (end.eq(0)) {
|
|
42
47
|
return FillClassification.CLOSED_LONG
|
|
43
48
|
}
|
|
44
|
-
if (end
|
|
49
|
+
if (end.lt(0)) {
|
|
45
50
|
return FillClassification.SWITCHED_SHORT
|
|
46
51
|
}
|
|
47
|
-
if (end
|
|
52
|
+
if (end.gt(start)) {
|
|
48
53
|
return FillClassification.INCREASED_LONG
|
|
49
54
|
}
|
|
50
55
|
return FillClassification.REDUCED_LONG
|
|
51
56
|
}
|
|
52
57
|
|
|
53
|
-
if (end
|
|
58
|
+
if (end.eq(0)) {
|
|
54
59
|
return FillClassification.CLOSED_SHORT
|
|
55
60
|
}
|
|
56
|
-
if (end
|
|
61
|
+
if (end.gt(0)) {
|
|
57
62
|
return FillClassification.SWITCHED_LONG
|
|
58
63
|
}
|
|
59
|
-
if (end
|
|
64
|
+
if (end.lt(start)) {
|
|
60
65
|
return FillClassification.INCREASED_SHORT
|
|
61
66
|
}
|
|
62
67
|
return FillClassification.REDUCED_SHORT
|
|
@@ -66,13 +71,17 @@ export function classifyFillFromPosition(
|
|
|
66
71
|
* Classify a fill as open or close based on realizedPnl.
|
|
67
72
|
* @deprecated Use `Fill.classification` instead — it uses startPosition
|
|
68
73
|
* for accurate open/increase/reduce/close/reverse classification.
|
|
74
|
+
* @throws {PerpsError} `ValidationError` when `realizedPnl` is a string that
|
|
75
|
+
* is not a decimal string.
|
|
69
76
|
* @public
|
|
70
77
|
*/
|
|
71
78
|
export function classifyFill(
|
|
72
79
|
side: OrderSide,
|
|
73
80
|
realizedPnl: DecimalString | null | undefined
|
|
74
81
|
): FillClassification {
|
|
75
|
-
const isClose =
|
|
82
|
+
const isClose =
|
|
83
|
+
realizedPnl != null &&
|
|
84
|
+
!requireDecimal(realizedPnl, 'classifyFill(realizedPnl)').eq(0)
|
|
76
85
|
if (side === OrderSide.BUY) {
|
|
77
86
|
return isClose
|
|
78
87
|
? FillClassification.CLOSED_SHORT
|
package/src/version.ts
CHANGED