@gbozee/ultimate 0.0.2-61 → 0.0.2-63

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.
@@ -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
  }[];
@@ -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
  };
@@ -55676,7 +55678,9 @@ function build_reduce_config(payload) {
55676
55678
  short_minimum_pnl = 0.0001,
55677
55679
  long_minimum_pnl = 0.0001,
55678
55680
  not_reduce = false,
55679
- _positions
55681
+ _positions,
55682
+ long_config,
55683
+ short_config
55680
55684
  } = payload;
55681
55685
  const long_position = _positions.find((x) => x.kind === "long");
55682
55686
  const short_position = _positions.find((x) => x.kind === "short");
@@ -55691,10 +55695,10 @@ function build_reduce_config(payload) {
55691
55695
  owner: account.owner,
55692
55696
  exchange: account.exchange,
55693
55697
  not_reduce,
55694
- reduce_ratio_long: long_position?.reduce_ratio || 0,
55695
- reduce_ratio_short: short_position?.reduce_ratio || 0,
55696
- use_full_long: long_position?.use_full || false,
55697
- use_full_short: short_position?.use_full || false
55698
+ reduce_ratio_long: long_config?.reduce_ratio || 0,
55699
+ reduce_ratio_short: short_config?.reduce_ratio || 0,
55700
+ use_full_long: long_config?.use_full || long_position?.use_full || false,
55701
+ use_full_short: short_config?.use_full || short_position?.use_full || false
55698
55702
  };
55699
55703
  }
55700
55704
  function calculate_avg_entry2(kind, {
@@ -56928,13 +56932,25 @@ class ExchangeAccount {
56928
56932
  });
56929
56933
  const long_position = positions.find((x) => x.kind === "long");
56930
56934
  const short_position = positions.find((x) => x.kind === "short");
56935
+ const long_config = await this.getPositionConfig({
56936
+ symbol: payload.symbol,
56937
+ kind: "long"
56938
+ });
56939
+ const short_config = await this.getPositionConfig({
56940
+ symbol: payload.symbol,
56941
+ kind: "short"
56942
+ });
56931
56943
  const config2 = build_reduce_config({
56932
56944
  account: this.instance,
56933
56945
  symbol: payload.symbol,
56934
- _positions: positions
56946
+ _positions: positions,
56947
+ long_config,
56948
+ short_config
56935
56949
  });
56936
56950
  let long_target_pnl = payload.kind == "long" ? payload.target_pnl : 0;
56937
56951
  let short_target_pnl = payload.kind == "short" ? payload.target_pnl : 0;
56952
+ const long_sell_ratio = long_config.sell_ratio || long_position?.sell_ratio;
56953
+ const short_sell_ratio = short_config.sell_ratio || short_position?.sell_ratio;
56938
56954
  if (payload.as_dict) {
56939
56955
  return {
56940
56956
  long: {
@@ -56945,7 +56961,7 @@ class ExchangeAccount {
56945
56961
  not_reduce: config2?.not_reduce,
56946
56962
  ratio: config2?.reduce_ratio_long,
56947
56963
  use_full: payload.use_full ? payload.kind == "long" ? true : false : undefined,
56948
- sell_ratio: long_position?.sell_ratio
56964
+ sell_ratio: long_sell_ratio
56949
56965
  },
56950
56966
  short: {
56951
56967
  minimum_pnl: config2?.short_minimum_pnl || 0.0001,
@@ -56955,7 +56971,7 @@ class ExchangeAccount {
56955
56971
  not_reduce: config2?.not_reduce,
56956
56972
  ratio: config2?.reduce_ratio_short,
56957
56973
  use_full: payload.use_full ? payload.kind == "short" ? true : false : undefined,
56958
- sell_ratio: short_position?.sell_ratio
56974
+ sell_ratio: short_sell_ratio
56959
56975
  },
56960
56976
  trigger: {
56961
56977
  long: payload.trigger?.long ? config2.trigger_long : false,
@@ -57235,16 +57251,27 @@ class ExchangeAccount {
57235
57251
  });
57236
57252
  const long_position = positions.find((x) => x.kind === "long");
57237
57253
  const short_position = positions.find((x) => x.kind === "short");
57254
+ const long_config = await this.getPositionConfig({
57255
+ symbol,
57256
+ kind: "long"
57257
+ });
57258
+ const short_config = await this.getPositionConfig({
57259
+ symbol,
57260
+ kind: "short"
57261
+ });
57262
+ const focus_config = kind === "long" ? long_config : short_config;
57238
57263
  const focus_position = kind === "long" ? long_position : short_position;
57239
57264
  const track_position = kind === "long" ? short_position : long_position;
57240
- if (!focus_position.follow) {
57265
+ const follow = focus_config.follow || focus_position.follow;
57266
+ const threshold_qty = focus_config.threshold_qty || focus_position.threshold_qty;
57267
+ if (!follow) {
57241
57268
  return "No follow set";
57242
57269
  }
57243
57270
  let should_place_order = false;
57244
- if (focus_position.threshold_qty === 0) {
57271
+ if (threshold_qty === 0) {
57245
57272
  should_place_order = true;
57246
57273
  }
57247
- if (focus_position.threshold_qty > 0 && track_position.quantity >= focus_position.threshold_qty) {
57274
+ if (threshold_qty > 0 && track_position.quantity >= threshold_qty) {
57248
57275
  should_place_order = true;
57249
57276
  }
57250
57277
  if (track_position.quantity !== focus_position.quantity && focus_position.quantity < track_position.quantity && should_place_order) {
@@ -57497,14 +57524,29 @@ class ExchangeAccount {
57497
57524
  });
57498
57525
  const long_position = positions.find((x) => x.kind === "long");
57499
57526
  const short_position = positions.find((x) => x.kind === "short");
57500
- const strategy_instance = await this.getPositionStrategy();
57527
+ const long_config = await this.getPositionConfig({
57528
+ symbol,
57529
+ kind: "long"
57530
+ });
57531
+ const short_config = await this.getPositionConfig({
57532
+ symbol,
57533
+ kind: "short"
57534
+ });
57535
+ const focus_position = kind === "long" ? long_position : short_position;
57536
+ const focus_config = kind === "long" ? long_config : short_config;
57537
+ const short_tp_factor = short_config.profit_percent / long_config.profit_percent;
57538
+ const reduce_ratio = focus_config.reduce_ratio || focus_position?.reduce_ratio;
57539
+ const budget = focus_config.risk;
57540
+ const risk_reward = focus_config.risk_reward;
57541
+ const tp_percent = focus_config.profit_percent;
57542
+ const fee_percent = symbol_config.fee_percent;
57501
57543
  const strategy_config = {
57502
- tp_percent: strategy_instance?.tp_percent,
57503
- short_tp_factor: strategy_instance?.short_tp_factor,
57504
- fee_percent: strategy_instance?.fee_percent,
57505
- budget: strategy_instance?.budget,
57506
- risk_reward: strategy_instance?.risk_reward,
57507
- reduce_ratio: strategy_instance?.reduce_ratio,
57544
+ tp_percent,
57545
+ short_tp_factor,
57546
+ fee_percent,
57547
+ budget,
57548
+ risk_reward,
57549
+ reduce_ratio,
57508
57550
  global_config: symbol_config
57509
57551
  };
57510
57552
  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
- current_price?: number;
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
  };
@@ -55634,7 +55636,9 @@ function build_reduce_config(payload) {
55634
55636
  short_minimum_pnl = 0.0001,
55635
55637
  long_minimum_pnl = 0.0001,
55636
55638
  not_reduce = false,
55637
- _positions
55639
+ _positions,
55640
+ long_config,
55641
+ short_config
55638
55642
  } = payload;
55639
55643
  const long_position = _positions.find((x) => x.kind === "long");
55640
55644
  const short_position = _positions.find((x) => x.kind === "short");
@@ -55649,10 +55653,10 @@ function build_reduce_config(payload) {
55649
55653
  owner: account.owner,
55650
55654
  exchange: account.exchange,
55651
55655
  not_reduce,
55652
- reduce_ratio_long: long_position?.reduce_ratio || 0,
55653
- reduce_ratio_short: short_position?.reduce_ratio || 0,
55654
- use_full_long: long_position?.use_full || false,
55655
- use_full_short: short_position?.use_full || false
55656
+ reduce_ratio_long: long_config?.reduce_ratio || 0,
55657
+ reduce_ratio_short: short_config?.reduce_ratio || 0,
55658
+ use_full_long: long_config?.use_full || long_position?.use_full || false,
55659
+ use_full_short: short_config?.use_full || short_position?.use_full || false
55656
55660
  };
55657
55661
  }
55658
55662
  function calculate_avg_entry2(kind, {
@@ -56886,13 +56890,25 @@ class ExchangeAccount {
56886
56890
  });
56887
56891
  const long_position = positions.find((x) => x.kind === "long");
56888
56892
  const short_position = positions.find((x) => x.kind === "short");
56893
+ const long_config = await this.getPositionConfig({
56894
+ symbol: payload.symbol,
56895
+ kind: "long"
56896
+ });
56897
+ const short_config = await this.getPositionConfig({
56898
+ symbol: payload.symbol,
56899
+ kind: "short"
56900
+ });
56889
56901
  const config2 = build_reduce_config({
56890
56902
  account: this.instance,
56891
56903
  symbol: payload.symbol,
56892
- _positions: positions
56904
+ _positions: positions,
56905
+ long_config,
56906
+ short_config
56893
56907
  });
56894
56908
  let long_target_pnl = payload.kind == "long" ? payload.target_pnl : 0;
56895
56909
  let short_target_pnl = payload.kind == "short" ? payload.target_pnl : 0;
56910
+ const long_sell_ratio = long_config.sell_ratio || long_position?.sell_ratio;
56911
+ const short_sell_ratio = short_config.sell_ratio || short_position?.sell_ratio;
56896
56912
  if (payload.as_dict) {
56897
56913
  return {
56898
56914
  long: {
@@ -56903,7 +56919,7 @@ class ExchangeAccount {
56903
56919
  not_reduce: config2?.not_reduce,
56904
56920
  ratio: config2?.reduce_ratio_long,
56905
56921
  use_full: payload.use_full ? payload.kind == "long" ? true : false : undefined,
56906
- sell_ratio: long_position?.sell_ratio
56922
+ sell_ratio: long_sell_ratio
56907
56923
  },
56908
56924
  short: {
56909
56925
  minimum_pnl: config2?.short_minimum_pnl || 0.0001,
@@ -56913,7 +56929,7 @@ class ExchangeAccount {
56913
56929
  not_reduce: config2?.not_reduce,
56914
56930
  ratio: config2?.reduce_ratio_short,
56915
56931
  use_full: payload.use_full ? payload.kind == "short" ? true : false : undefined,
56916
- sell_ratio: short_position?.sell_ratio
56932
+ sell_ratio: short_sell_ratio
56917
56933
  },
56918
56934
  trigger: {
56919
56935
  long: payload.trigger?.long ? config2.trigger_long : false,
@@ -57193,16 +57209,27 @@ class ExchangeAccount {
57193
57209
  });
57194
57210
  const long_position = positions.find((x) => x.kind === "long");
57195
57211
  const short_position = positions.find((x) => x.kind === "short");
57212
+ const long_config = await this.getPositionConfig({
57213
+ symbol,
57214
+ kind: "long"
57215
+ });
57216
+ const short_config = await this.getPositionConfig({
57217
+ symbol,
57218
+ kind: "short"
57219
+ });
57220
+ const focus_config = kind === "long" ? long_config : short_config;
57196
57221
  const focus_position = kind === "long" ? long_position : short_position;
57197
57222
  const track_position = kind === "long" ? short_position : long_position;
57198
- if (!focus_position.follow) {
57223
+ const follow = focus_config.follow || focus_position.follow;
57224
+ const threshold_qty = focus_config.threshold_qty || focus_position.threshold_qty;
57225
+ if (!follow) {
57199
57226
  return "No follow set";
57200
57227
  }
57201
57228
  let should_place_order = false;
57202
- if (focus_position.threshold_qty === 0) {
57229
+ if (threshold_qty === 0) {
57203
57230
  should_place_order = true;
57204
57231
  }
57205
- if (focus_position.threshold_qty > 0 && track_position.quantity >= focus_position.threshold_qty) {
57232
+ if (threshold_qty > 0 && track_position.quantity >= threshold_qty) {
57206
57233
  should_place_order = true;
57207
57234
  }
57208
57235
  if (track_position.quantity !== focus_position.quantity && focus_position.quantity < track_position.quantity && should_place_order) {
@@ -57455,14 +57482,29 @@ class ExchangeAccount {
57455
57482
  });
57456
57483
  const long_position = positions.find((x) => x.kind === "long");
57457
57484
  const short_position = positions.find((x) => x.kind === "short");
57458
- const strategy_instance = await this.getPositionStrategy();
57485
+ const long_config = await this.getPositionConfig({
57486
+ symbol,
57487
+ kind: "long"
57488
+ });
57489
+ const short_config = await this.getPositionConfig({
57490
+ symbol,
57491
+ kind: "short"
57492
+ });
57493
+ const focus_position = kind === "long" ? long_position : short_position;
57494
+ const focus_config = kind === "long" ? long_config : short_config;
57495
+ const short_tp_factor = short_config.profit_percent / long_config.profit_percent;
57496
+ const reduce_ratio = focus_config.reduce_ratio || focus_position?.reduce_ratio;
57497
+ const budget = focus_config.risk;
57498
+ const risk_reward = focus_config.risk_reward;
57499
+ const tp_percent = focus_config.profit_percent;
57500
+ const fee_percent = symbol_config.fee_percent;
57459
57501
  const strategy_config = {
57460
- tp_percent: strategy_instance?.tp_percent,
57461
- short_tp_factor: strategy_instance?.short_tp_factor,
57462
- fee_percent: strategy_instance?.fee_percent,
57463
- budget: strategy_instance?.budget,
57464
- risk_reward: strategy_instance?.risk_reward,
57465
- reduce_ratio: strategy_instance?.reduce_ratio,
57502
+ tp_percent,
57503
+ short_tp_factor,
57504
+ fee_percent,
57505
+ budget,
57506
+ risk_reward,
57507
+ reduce_ratio,
57466
57508
  global_config: symbol_config
57467
57509
  };
57468
57510
  const strategy = new Strategy({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-61",
4
+ "version": "0.0.2-63",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",