@gbozee/ultimate 0.0.2-61 → 0.0.2-62
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/frontend-index.d.ts +6 -0
- package/dist/frontend-index.js +3 -1
- package/dist/index.cjs +51 -13
- package/dist/index.d.ts +15 -1
- package/dist/index.js +51 -13
- package/package.json +1 -1
package/dist/frontend-index.d.ts
CHANGED
|
@@ -432,13 +432,16 @@ export declare class Strategy {
|
|
|
432
432
|
[x: string]: number | {
|
|
433
433
|
entry: number;
|
|
434
434
|
quantity: number;
|
|
435
|
+
diff?: undefined;
|
|
435
436
|
} | {
|
|
436
437
|
[x: string]: number;
|
|
438
|
+
diff: number;
|
|
437
439
|
entry?: undefined;
|
|
438
440
|
quantity?: undefined;
|
|
439
441
|
};
|
|
440
442
|
pnl: {
|
|
441
443
|
[x: string]: number;
|
|
444
|
+
diff: number;
|
|
442
445
|
};
|
|
443
446
|
spread: number;
|
|
444
447
|
};
|
|
@@ -450,13 +453,16 @@ export declare class Strategy {
|
|
|
450
453
|
[x: string]: number | {
|
|
451
454
|
entry: number;
|
|
452
455
|
quantity: number;
|
|
456
|
+
diff?: undefined;
|
|
453
457
|
} | {
|
|
454
458
|
[x: string]: number;
|
|
459
|
+
diff: number;
|
|
455
460
|
entry?: undefined;
|
|
456
461
|
quantity?: undefined;
|
|
457
462
|
};
|
|
458
463
|
pnl: {
|
|
459
464
|
[x: string]: number;
|
|
465
|
+
diff: number;
|
|
460
466
|
};
|
|
461
467
|
spread: number;
|
|
462
468
|
}[];
|
package/dist/frontend-index.js
CHANGED
|
@@ -1871,6 +1871,7 @@ class Strategy {
|
|
|
1871
1871
|
const ratio = expected_loss / actual_loss;
|
|
1872
1872
|
const loss_quantity = this.to_df(ratio * reverse_position.quantity);
|
|
1873
1873
|
const remaining_quantity = this.to_df(reverse_position.quantity - loss_quantity);
|
|
1874
|
+
const diff = focus_pnl - expected_loss;
|
|
1874
1875
|
return {
|
|
1875
1876
|
[kind]: {
|
|
1876
1877
|
entry: focus_tp,
|
|
@@ -1882,7 +1883,8 @@ class Strategy {
|
|
|
1882
1883
|
},
|
|
1883
1884
|
pnl: {
|
|
1884
1885
|
[kind]: focus_pnl,
|
|
1885
|
-
[reverse_kind]: -expected_loss
|
|
1886
|
+
[reverse_kind]: -expected_loss,
|
|
1887
|
+
diff
|
|
1886
1888
|
},
|
|
1887
1889
|
spread: this.to_f(Math.abs(focus_tp - reverse_position.entry) * remaining_quantity)
|
|
1888
1890
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -53771,6 +53771,7 @@ class Strategy {
|
|
|
53771
53771
|
const ratio = expected_loss / actual_loss;
|
|
53772
53772
|
const loss_quantity = this.to_df(ratio * reverse_position.quantity);
|
|
53773
53773
|
const remaining_quantity = this.to_df(reverse_position.quantity - loss_quantity);
|
|
53774
|
+
const diff = focus_pnl - expected_loss;
|
|
53774
53775
|
return {
|
|
53775
53776
|
[kind]: {
|
|
53776
53777
|
entry: focus_tp,
|
|
@@ -53782,7 +53783,8 @@ class Strategy {
|
|
|
53782
53783
|
},
|
|
53783
53784
|
pnl: {
|
|
53784
53785
|
[kind]: focus_pnl,
|
|
53785
|
-
[reverse_kind]: -expected_loss
|
|
53786
|
+
[reverse_kind]: -expected_loss,
|
|
53787
|
+
diff
|
|
53786
53788
|
},
|
|
53787
53789
|
spread: this.to_f(Math.abs(focus_tp - reverse_position.entry) * remaining_quantity)
|
|
53788
53790
|
};
|
|
@@ -56928,6 +56930,14 @@ class ExchangeAccount {
|
|
|
56928
56930
|
});
|
|
56929
56931
|
const long_position = positions.find((x) => x.kind === "long");
|
|
56930
56932
|
const short_position = positions.find((x) => x.kind === "short");
|
|
56933
|
+
const long_config = await this.getPositionConfig({
|
|
56934
|
+
symbol: payload.symbol,
|
|
56935
|
+
kind: "long"
|
|
56936
|
+
});
|
|
56937
|
+
const short_config = await this.getPositionConfig({
|
|
56938
|
+
symbol: payload.symbol,
|
|
56939
|
+
kind: "short"
|
|
56940
|
+
});
|
|
56931
56941
|
const config2 = build_reduce_config({
|
|
56932
56942
|
account: this.instance,
|
|
56933
56943
|
symbol: payload.symbol,
|
|
@@ -56935,6 +56945,8 @@ class ExchangeAccount {
|
|
|
56935
56945
|
});
|
|
56936
56946
|
let long_target_pnl = payload.kind == "long" ? payload.target_pnl : 0;
|
|
56937
56947
|
let short_target_pnl = payload.kind == "short" ? payload.target_pnl : 0;
|
|
56948
|
+
const long_sell_ratio = long_config.sell_ratio || long_position?.sell_ratio;
|
|
56949
|
+
const short_sell_ratio = short_config.sell_ratio || short_position?.sell_ratio;
|
|
56938
56950
|
if (payload.as_dict) {
|
|
56939
56951
|
return {
|
|
56940
56952
|
long: {
|
|
@@ -56945,7 +56957,7 @@ class ExchangeAccount {
|
|
|
56945
56957
|
not_reduce: config2?.not_reduce,
|
|
56946
56958
|
ratio: config2?.reduce_ratio_long,
|
|
56947
56959
|
use_full: payload.use_full ? payload.kind == "long" ? true : false : undefined,
|
|
56948
|
-
sell_ratio:
|
|
56960
|
+
sell_ratio: long_sell_ratio
|
|
56949
56961
|
},
|
|
56950
56962
|
short: {
|
|
56951
56963
|
minimum_pnl: config2?.short_minimum_pnl || 0.0001,
|
|
@@ -56955,7 +56967,7 @@ class ExchangeAccount {
|
|
|
56955
56967
|
not_reduce: config2?.not_reduce,
|
|
56956
56968
|
ratio: config2?.reduce_ratio_short,
|
|
56957
56969
|
use_full: payload.use_full ? payload.kind == "short" ? true : false : undefined,
|
|
56958
|
-
sell_ratio:
|
|
56970
|
+
sell_ratio: short_sell_ratio
|
|
56959
56971
|
},
|
|
56960
56972
|
trigger: {
|
|
56961
56973
|
long: payload.trigger?.long ? config2.trigger_long : false,
|
|
@@ -57235,16 +57247,27 @@ class ExchangeAccount {
|
|
|
57235
57247
|
});
|
|
57236
57248
|
const long_position = positions.find((x) => x.kind === "long");
|
|
57237
57249
|
const short_position = positions.find((x) => x.kind === "short");
|
|
57250
|
+
const long_config = await this.getPositionConfig({
|
|
57251
|
+
symbol,
|
|
57252
|
+
kind: "long"
|
|
57253
|
+
});
|
|
57254
|
+
const short_config = await this.getPositionConfig({
|
|
57255
|
+
symbol,
|
|
57256
|
+
kind: "short"
|
|
57257
|
+
});
|
|
57258
|
+
const focus_config = kind === "long" ? long_config : short_config;
|
|
57238
57259
|
const focus_position = kind === "long" ? long_position : short_position;
|
|
57239
57260
|
const track_position = kind === "long" ? short_position : long_position;
|
|
57240
|
-
|
|
57261
|
+
const follow = focus_config.follow || focus_position.follow;
|
|
57262
|
+
const threshold_qty = focus_config.threshold_qty || focus_position.threshold_qty;
|
|
57263
|
+
if (!follow) {
|
|
57241
57264
|
return "No follow set";
|
|
57242
57265
|
}
|
|
57243
57266
|
let should_place_order = false;
|
|
57244
|
-
if (
|
|
57267
|
+
if (threshold_qty === 0) {
|
|
57245
57268
|
should_place_order = true;
|
|
57246
57269
|
}
|
|
57247
|
-
if (
|
|
57270
|
+
if (threshold_qty > 0 && track_position.quantity >= threshold_qty) {
|
|
57248
57271
|
should_place_order = true;
|
|
57249
57272
|
}
|
|
57250
57273
|
if (track_position.quantity !== focus_position.quantity && focus_position.quantity < track_position.quantity && should_place_order) {
|
|
@@ -57497,14 +57520,29 @@ class ExchangeAccount {
|
|
|
57497
57520
|
});
|
|
57498
57521
|
const long_position = positions.find((x) => x.kind === "long");
|
|
57499
57522
|
const short_position = positions.find((x) => x.kind === "short");
|
|
57500
|
-
const
|
|
57523
|
+
const long_config = await this.getPositionConfig({
|
|
57524
|
+
symbol,
|
|
57525
|
+
kind: "long"
|
|
57526
|
+
});
|
|
57527
|
+
const short_config = await this.getPositionConfig({
|
|
57528
|
+
symbol,
|
|
57529
|
+
kind: "short"
|
|
57530
|
+
});
|
|
57531
|
+
const focus_position = kind === "long" ? long_position : short_position;
|
|
57532
|
+
const focus_config = kind === "long" ? long_config : short_config;
|
|
57533
|
+
const short_tp_factor = short_config.profit_percent / long_config.profit_percent;
|
|
57534
|
+
const reduce_ratio = focus_config.reduce_ratio || focus_position?.reduce_ratio;
|
|
57535
|
+
const budget = focus_config.risk;
|
|
57536
|
+
const risk_reward = focus_config.risk_reward;
|
|
57537
|
+
const tp_percent = focus_config.profit_percent;
|
|
57538
|
+
const fee_percent = symbol_config.fee_percent;
|
|
57501
57539
|
const strategy_config = {
|
|
57502
|
-
tp_percent
|
|
57503
|
-
short_tp_factor
|
|
57504
|
-
fee_percent
|
|
57505
|
-
budget
|
|
57506
|
-
risk_reward
|
|
57507
|
-
reduce_ratio
|
|
57540
|
+
tp_percent,
|
|
57541
|
+
short_tp_factor,
|
|
57542
|
+
fee_percent,
|
|
57543
|
+
budget,
|
|
57544
|
+
risk_reward,
|
|
57545
|
+
reduce_ratio,
|
|
57508
57546
|
global_config: symbol_config
|
|
57509
57547
|
};
|
|
57510
57548
|
const strategy = new Strategy({
|
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ export interface SymbolConfig extends BaseSystemFields {
|
|
|
53
53
|
leverage?: number;
|
|
54
54
|
candle_count?: number;
|
|
55
55
|
interval?: any;
|
|
56
|
+
fee_percent?: number;
|
|
56
57
|
}
|
|
57
58
|
export interface ScheduledTrade extends BaseSystemFields {
|
|
58
59
|
symbol: string;
|
|
@@ -65,7 +66,10 @@ export interface ScheduledTrade extends BaseSystemFields {
|
|
|
65
66
|
profit_percent?: number;
|
|
66
67
|
place_tp?: boolean;
|
|
67
68
|
kind?: "long" | "short";
|
|
68
|
-
|
|
69
|
+
follow?: boolean | 1 | 0;
|
|
70
|
+
reduce_ratio?: number;
|
|
71
|
+
sell_ratio?: number;
|
|
72
|
+
threshold_qty?: number;
|
|
69
73
|
}
|
|
70
74
|
export interface AccountStrategy extends BaseSystemFields {
|
|
71
75
|
account: string;
|
|
@@ -109,6 +113,10 @@ export interface PositionsView {
|
|
|
109
113
|
leverage?: any;
|
|
110
114
|
avg_liquidation?: any;
|
|
111
115
|
balance?: any;
|
|
116
|
+
reduce_ratio?: number;
|
|
117
|
+
sell_ratio?: number;
|
|
118
|
+
threshold_qty?: number;
|
|
119
|
+
follow?: boolean | 1 | 0;
|
|
112
120
|
}
|
|
113
121
|
export interface BullishMarket extends RecordModel {
|
|
114
122
|
id: string;
|
|
@@ -578,13 +586,16 @@ export declare class Strategy {
|
|
|
578
586
|
[x: string]: number | {
|
|
579
587
|
entry: number;
|
|
580
588
|
quantity: number;
|
|
589
|
+
diff?: undefined;
|
|
581
590
|
} | {
|
|
582
591
|
[x: string]: number;
|
|
592
|
+
diff: number;
|
|
583
593
|
entry?: undefined;
|
|
584
594
|
quantity?: undefined;
|
|
585
595
|
};
|
|
586
596
|
pnl: {
|
|
587
597
|
[x: string]: number;
|
|
598
|
+
diff: number;
|
|
588
599
|
};
|
|
589
600
|
spread: number;
|
|
590
601
|
};
|
|
@@ -596,13 +607,16 @@ export declare class Strategy {
|
|
|
596
607
|
[x: string]: number | {
|
|
597
608
|
entry: number;
|
|
598
609
|
quantity: number;
|
|
610
|
+
diff?: undefined;
|
|
599
611
|
} | {
|
|
600
612
|
[x: string]: number;
|
|
613
|
+
diff: number;
|
|
601
614
|
entry?: undefined;
|
|
602
615
|
quantity?: undefined;
|
|
603
616
|
};
|
|
604
617
|
pnl: {
|
|
605
618
|
[x: string]: number;
|
|
619
|
+
diff: number;
|
|
606
620
|
};
|
|
607
621
|
spread: number;
|
|
608
622
|
}[];
|
package/dist/index.js
CHANGED
|
@@ -53729,6 +53729,7 @@ class Strategy {
|
|
|
53729
53729
|
const ratio = expected_loss / actual_loss;
|
|
53730
53730
|
const loss_quantity = this.to_df(ratio * reverse_position.quantity);
|
|
53731
53731
|
const remaining_quantity = this.to_df(reverse_position.quantity - loss_quantity);
|
|
53732
|
+
const diff = focus_pnl - expected_loss;
|
|
53732
53733
|
return {
|
|
53733
53734
|
[kind]: {
|
|
53734
53735
|
entry: focus_tp,
|
|
@@ -53740,7 +53741,8 @@ class Strategy {
|
|
|
53740
53741
|
},
|
|
53741
53742
|
pnl: {
|
|
53742
53743
|
[kind]: focus_pnl,
|
|
53743
|
-
[reverse_kind]: -expected_loss
|
|
53744
|
+
[reverse_kind]: -expected_loss,
|
|
53745
|
+
diff
|
|
53744
53746
|
},
|
|
53745
53747
|
spread: this.to_f(Math.abs(focus_tp - reverse_position.entry) * remaining_quantity)
|
|
53746
53748
|
};
|
|
@@ -56886,6 +56888,14 @@ class ExchangeAccount {
|
|
|
56886
56888
|
});
|
|
56887
56889
|
const long_position = positions.find((x) => x.kind === "long");
|
|
56888
56890
|
const short_position = positions.find((x) => x.kind === "short");
|
|
56891
|
+
const long_config = await this.getPositionConfig({
|
|
56892
|
+
symbol: payload.symbol,
|
|
56893
|
+
kind: "long"
|
|
56894
|
+
});
|
|
56895
|
+
const short_config = await this.getPositionConfig({
|
|
56896
|
+
symbol: payload.symbol,
|
|
56897
|
+
kind: "short"
|
|
56898
|
+
});
|
|
56889
56899
|
const config2 = build_reduce_config({
|
|
56890
56900
|
account: this.instance,
|
|
56891
56901
|
symbol: payload.symbol,
|
|
@@ -56893,6 +56903,8 @@ class ExchangeAccount {
|
|
|
56893
56903
|
});
|
|
56894
56904
|
let long_target_pnl = payload.kind == "long" ? payload.target_pnl : 0;
|
|
56895
56905
|
let short_target_pnl = payload.kind == "short" ? payload.target_pnl : 0;
|
|
56906
|
+
const long_sell_ratio = long_config.sell_ratio || long_position?.sell_ratio;
|
|
56907
|
+
const short_sell_ratio = short_config.sell_ratio || short_position?.sell_ratio;
|
|
56896
56908
|
if (payload.as_dict) {
|
|
56897
56909
|
return {
|
|
56898
56910
|
long: {
|
|
@@ -56903,7 +56915,7 @@ class ExchangeAccount {
|
|
|
56903
56915
|
not_reduce: config2?.not_reduce,
|
|
56904
56916
|
ratio: config2?.reduce_ratio_long,
|
|
56905
56917
|
use_full: payload.use_full ? payload.kind == "long" ? true : false : undefined,
|
|
56906
|
-
sell_ratio:
|
|
56918
|
+
sell_ratio: long_sell_ratio
|
|
56907
56919
|
},
|
|
56908
56920
|
short: {
|
|
56909
56921
|
minimum_pnl: config2?.short_minimum_pnl || 0.0001,
|
|
@@ -56913,7 +56925,7 @@ class ExchangeAccount {
|
|
|
56913
56925
|
not_reduce: config2?.not_reduce,
|
|
56914
56926
|
ratio: config2?.reduce_ratio_short,
|
|
56915
56927
|
use_full: payload.use_full ? payload.kind == "short" ? true : false : undefined,
|
|
56916
|
-
sell_ratio:
|
|
56928
|
+
sell_ratio: short_sell_ratio
|
|
56917
56929
|
},
|
|
56918
56930
|
trigger: {
|
|
56919
56931
|
long: payload.trigger?.long ? config2.trigger_long : false,
|
|
@@ -57193,16 +57205,27 @@ class ExchangeAccount {
|
|
|
57193
57205
|
});
|
|
57194
57206
|
const long_position = positions.find((x) => x.kind === "long");
|
|
57195
57207
|
const short_position = positions.find((x) => x.kind === "short");
|
|
57208
|
+
const long_config = await this.getPositionConfig({
|
|
57209
|
+
symbol,
|
|
57210
|
+
kind: "long"
|
|
57211
|
+
});
|
|
57212
|
+
const short_config = await this.getPositionConfig({
|
|
57213
|
+
symbol,
|
|
57214
|
+
kind: "short"
|
|
57215
|
+
});
|
|
57216
|
+
const focus_config = kind === "long" ? long_config : short_config;
|
|
57196
57217
|
const focus_position = kind === "long" ? long_position : short_position;
|
|
57197
57218
|
const track_position = kind === "long" ? short_position : long_position;
|
|
57198
|
-
|
|
57219
|
+
const follow = focus_config.follow || focus_position.follow;
|
|
57220
|
+
const threshold_qty = focus_config.threshold_qty || focus_position.threshold_qty;
|
|
57221
|
+
if (!follow) {
|
|
57199
57222
|
return "No follow set";
|
|
57200
57223
|
}
|
|
57201
57224
|
let should_place_order = false;
|
|
57202
|
-
if (
|
|
57225
|
+
if (threshold_qty === 0) {
|
|
57203
57226
|
should_place_order = true;
|
|
57204
57227
|
}
|
|
57205
|
-
if (
|
|
57228
|
+
if (threshold_qty > 0 && track_position.quantity >= threshold_qty) {
|
|
57206
57229
|
should_place_order = true;
|
|
57207
57230
|
}
|
|
57208
57231
|
if (track_position.quantity !== focus_position.quantity && focus_position.quantity < track_position.quantity && should_place_order) {
|
|
@@ -57455,14 +57478,29 @@ class ExchangeAccount {
|
|
|
57455
57478
|
});
|
|
57456
57479
|
const long_position = positions.find((x) => x.kind === "long");
|
|
57457
57480
|
const short_position = positions.find((x) => x.kind === "short");
|
|
57458
|
-
const
|
|
57481
|
+
const long_config = await this.getPositionConfig({
|
|
57482
|
+
symbol,
|
|
57483
|
+
kind: "long"
|
|
57484
|
+
});
|
|
57485
|
+
const short_config = await this.getPositionConfig({
|
|
57486
|
+
symbol,
|
|
57487
|
+
kind: "short"
|
|
57488
|
+
});
|
|
57489
|
+
const focus_position = kind === "long" ? long_position : short_position;
|
|
57490
|
+
const focus_config = kind === "long" ? long_config : short_config;
|
|
57491
|
+
const short_tp_factor = short_config.profit_percent / long_config.profit_percent;
|
|
57492
|
+
const reduce_ratio = focus_config.reduce_ratio || focus_position?.reduce_ratio;
|
|
57493
|
+
const budget = focus_config.risk;
|
|
57494
|
+
const risk_reward = focus_config.risk_reward;
|
|
57495
|
+
const tp_percent = focus_config.profit_percent;
|
|
57496
|
+
const fee_percent = symbol_config.fee_percent;
|
|
57459
57497
|
const strategy_config = {
|
|
57460
|
-
tp_percent
|
|
57461
|
-
short_tp_factor
|
|
57462
|
-
fee_percent
|
|
57463
|
-
budget
|
|
57464
|
-
risk_reward
|
|
57465
|
-
reduce_ratio
|
|
57498
|
+
tp_percent,
|
|
57499
|
+
short_tp_factor,
|
|
57500
|
+
fee_percent,
|
|
57501
|
+
budget,
|
|
57502
|
+
risk_reward,
|
|
57503
|
+
reduce_ratio,
|
|
57466
57504
|
global_config: symbol_config
|
|
57467
57505
|
};
|
|
57468
57506
|
const strategy = new Strategy({
|