@gbozee/ultimate 0.0.2-60 → 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.
@@ -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
  };
@@ -56928,32 +56930,44 @@ 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,
56934
56944
  _positions: positions
56935
56945
  });
56946
+ let long_target_pnl = payload.kind == "long" ? payload.target_pnl : 0;
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;
56936
56950
  if (payload.as_dict) {
56937
56951
  return {
56938
56952
  long: {
56939
56953
  minimum_pnl: config2?.long_minimum_pnl || 0.0001,
56940
56954
  max_size: 0.003,
56941
- profit: config2?.long_profit,
56955
+ profit: long_target_pnl || config2?.long_profit,
56942
56956
  increase: false,
56943
56957
  not_reduce: config2?.not_reduce,
56944
56958
  ratio: config2?.reduce_ratio_long,
56945
56959
  use_full: payload.use_full ? payload.kind == "long" ? true : false : undefined,
56946
- sell_ratio: long_position?.sell_ratio
56960
+ sell_ratio: long_sell_ratio
56947
56961
  },
56948
56962
  short: {
56949
56963
  minimum_pnl: config2?.short_minimum_pnl || 0.0001,
56950
56964
  max_size: 0.003,
56951
- profit: config2?.short_profit,
56965
+ profit: short_target_pnl || config2?.short_profit,
56952
56966
  increase: false,
56953
56967
  not_reduce: config2?.not_reduce,
56954
56968
  ratio: config2?.reduce_ratio_short,
56955
56969
  use_full: payload.use_full ? payload.kind == "short" ? true : false : undefined,
56956
- sell_ratio: short_position?.sell_ratio
56970
+ sell_ratio: short_sell_ratio
56957
56971
  },
56958
56972
  trigger: {
56959
56973
  long: payload.trigger?.long ? config2.trigger_long : false,
@@ -57010,7 +57024,7 @@ class ExchangeAccount {
57010
57024
  }, accountInfo, trigger2, this.exchange);
57011
57025
  }
57012
57026
  async placeProfitAndStop(payload) {
57013
- const { symbol, trigger: trigger2, refresh, kind } = payload;
57027
+ const { symbol, trigger: trigger2, refresh, kind, target_pnl } = payload;
57014
57028
  if (refresh) {
57015
57029
  await this.syncAccount({
57016
57030
  symbol,
@@ -57024,7 +57038,9 @@ class ExchangeAccount {
57024
57038
  trigger: {
57025
57039
  long: trigger2 || false,
57026
57040
  short: trigger2 || false
57027
- }
57041
+ },
57042
+ kind,
57043
+ target_pnl
57028
57044
  });
57029
57045
  if (!kind) {
57030
57046
  await this.updateConfigPnl({
@@ -57231,16 +57247,27 @@ class ExchangeAccount {
57231
57247
  });
57232
57248
  const long_position = positions.find((x) => x.kind === "long");
57233
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;
57234
57259
  const focus_position = kind === "long" ? long_position : short_position;
57235
57260
  const track_position = kind === "long" ? short_position : long_position;
57236
- if (!focus_position.follow) {
57261
+ const follow = focus_config.follow || focus_position.follow;
57262
+ const threshold_qty = focus_config.threshold_qty || focus_position.threshold_qty;
57263
+ if (!follow) {
57237
57264
  return "No follow set";
57238
57265
  }
57239
57266
  let should_place_order = false;
57240
- if (focus_position.threshold_qty === 0) {
57267
+ if (threshold_qty === 0) {
57241
57268
  should_place_order = true;
57242
57269
  }
57243
- if (focus_position.threshold_qty > 0 && track_position.quantity >= focus_position.threshold_qty) {
57270
+ if (threshold_qty > 0 && track_position.quantity >= threshold_qty) {
57244
57271
  should_place_order = true;
57245
57272
  }
57246
57273
  if (track_position.quantity !== focus_position.quantity && focus_position.quantity < track_position.quantity && should_place_order) {
@@ -57493,14 +57520,29 @@ class ExchangeAccount {
57493
57520
  });
57494
57521
  const long_position = positions.find((x) => x.kind === "long");
57495
57522
  const short_position = positions.find((x) => x.kind === "short");
57496
- const strategy_instance = await this.getPositionStrategy();
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;
57497
57539
  const strategy_config = {
57498
- tp_percent: strategy_instance?.tp_percent,
57499
- short_tp_factor: strategy_instance?.short_tp_factor,
57500
- fee_percent: strategy_instance?.fee_percent,
57501
- budget: strategy_instance?.budget,
57502
- risk_reward: strategy_instance?.risk_reward,
57503
- reduce_ratio: strategy_instance?.reduce_ratio,
57540
+ tp_percent,
57541
+ short_tp_factor,
57542
+ fee_percent,
57543
+ budget,
57544
+ risk_reward,
57545
+ reduce_ratio,
57504
57546
  global_config: symbol_config
57505
57547
  };
57506
57548
  const strategy = new Strategy({
@@ -58073,7 +58115,8 @@ class ExchangeAccount {
58073
58115
  raw: _raw,
58074
58116
  cancel,
58075
58117
  stop,
58076
- ignore_config
58118
+ ignore_config,
58119
+ target_pnl
58077
58120
  } = payload;
58078
58121
  if (cancel) {
58079
58122
  await this.cancelOrders({
@@ -58102,7 +58145,8 @@ class ExchangeAccount {
58102
58145
  if (tp) {
58103
58146
  await this.placeProfitAndStop({
58104
58147
  symbol,
58105
- trigger: true
58148
+ trigger: true,
58149
+ target_pnl
58106
58150
  });
58107
58151
  }
58108
58152
  return [];
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
  }[];
@@ -1221,6 +1235,7 @@ declare class ExchangeAccount$1 {
1221
1235
  symbol: string;
1222
1236
  kind?: "long" | "short";
1223
1237
  as_dict?: boolean;
1238
+ target_pnl?: number;
1224
1239
  trigger?: {
1225
1240
  long: boolean;
1226
1241
  short: boolean;
@@ -1290,6 +1305,7 @@ declare class ExchangeAccount$1 {
1290
1305
  trigger?: boolean;
1291
1306
  refresh?: boolean;
1292
1307
  kind?: "long" | "short";
1308
+ target_pnl?: number;
1293
1309
  }): Promise<any>;
1294
1310
  reEnterPositionOnEmpty(symbol: string): Promise<void>;
1295
1311
  generate_config_params(payload: {
@@ -1424,6 +1440,7 @@ declare class ExchangeAccount$1 {
1424
1440
  raw?: boolean;
1425
1441
  cancel?: boolean;
1426
1442
  ignore_config?: boolean;
1443
+ target_pnl?: number;
1427
1444
  }): Promise<any>;
1428
1445
  updateConfigPnl(payload: {
1429
1446
  symbol: string;
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,32 +56888,44 @@ 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,
56892
56902
  _positions: positions
56893
56903
  });
56904
+ let long_target_pnl = payload.kind == "long" ? payload.target_pnl : 0;
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;
56894
56908
  if (payload.as_dict) {
56895
56909
  return {
56896
56910
  long: {
56897
56911
  minimum_pnl: config2?.long_minimum_pnl || 0.0001,
56898
56912
  max_size: 0.003,
56899
- profit: config2?.long_profit,
56913
+ profit: long_target_pnl || config2?.long_profit,
56900
56914
  increase: false,
56901
56915
  not_reduce: config2?.not_reduce,
56902
56916
  ratio: config2?.reduce_ratio_long,
56903
56917
  use_full: payload.use_full ? payload.kind == "long" ? true : false : undefined,
56904
- sell_ratio: long_position?.sell_ratio
56918
+ sell_ratio: long_sell_ratio
56905
56919
  },
56906
56920
  short: {
56907
56921
  minimum_pnl: config2?.short_minimum_pnl || 0.0001,
56908
56922
  max_size: 0.003,
56909
- profit: config2?.short_profit,
56923
+ profit: short_target_pnl || config2?.short_profit,
56910
56924
  increase: false,
56911
56925
  not_reduce: config2?.not_reduce,
56912
56926
  ratio: config2?.reduce_ratio_short,
56913
56927
  use_full: payload.use_full ? payload.kind == "short" ? true : false : undefined,
56914
- sell_ratio: short_position?.sell_ratio
56928
+ sell_ratio: short_sell_ratio
56915
56929
  },
56916
56930
  trigger: {
56917
56931
  long: payload.trigger?.long ? config2.trigger_long : false,
@@ -56968,7 +56982,7 @@ class ExchangeAccount {
56968
56982
  }, accountInfo, trigger2, this.exchange);
56969
56983
  }
56970
56984
  async placeProfitAndStop(payload) {
56971
- const { symbol, trigger: trigger2, refresh, kind } = payload;
56985
+ const { symbol, trigger: trigger2, refresh, kind, target_pnl } = payload;
56972
56986
  if (refresh) {
56973
56987
  await this.syncAccount({
56974
56988
  symbol,
@@ -56982,7 +56996,9 @@ class ExchangeAccount {
56982
56996
  trigger: {
56983
56997
  long: trigger2 || false,
56984
56998
  short: trigger2 || false
56985
- }
56999
+ },
57000
+ kind,
57001
+ target_pnl
56986
57002
  });
56987
57003
  if (!kind) {
56988
57004
  await this.updateConfigPnl({
@@ -57189,16 +57205,27 @@ class ExchangeAccount {
57189
57205
  });
57190
57206
  const long_position = positions.find((x) => x.kind === "long");
57191
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;
57192
57217
  const focus_position = kind === "long" ? long_position : short_position;
57193
57218
  const track_position = kind === "long" ? short_position : long_position;
57194
- if (!focus_position.follow) {
57219
+ const follow = focus_config.follow || focus_position.follow;
57220
+ const threshold_qty = focus_config.threshold_qty || focus_position.threshold_qty;
57221
+ if (!follow) {
57195
57222
  return "No follow set";
57196
57223
  }
57197
57224
  let should_place_order = false;
57198
- if (focus_position.threshold_qty === 0) {
57225
+ if (threshold_qty === 0) {
57199
57226
  should_place_order = true;
57200
57227
  }
57201
- if (focus_position.threshold_qty > 0 && track_position.quantity >= focus_position.threshold_qty) {
57228
+ if (threshold_qty > 0 && track_position.quantity >= threshold_qty) {
57202
57229
  should_place_order = true;
57203
57230
  }
57204
57231
  if (track_position.quantity !== focus_position.quantity && focus_position.quantity < track_position.quantity && should_place_order) {
@@ -57451,14 +57478,29 @@ class ExchangeAccount {
57451
57478
  });
57452
57479
  const long_position = positions.find((x) => x.kind === "long");
57453
57480
  const short_position = positions.find((x) => x.kind === "short");
57454
- const strategy_instance = await this.getPositionStrategy();
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;
57455
57497
  const strategy_config = {
57456
- tp_percent: strategy_instance?.tp_percent,
57457
- short_tp_factor: strategy_instance?.short_tp_factor,
57458
- fee_percent: strategy_instance?.fee_percent,
57459
- budget: strategy_instance?.budget,
57460
- risk_reward: strategy_instance?.risk_reward,
57461
- reduce_ratio: strategy_instance?.reduce_ratio,
57498
+ tp_percent,
57499
+ short_tp_factor,
57500
+ fee_percent,
57501
+ budget,
57502
+ risk_reward,
57503
+ reduce_ratio,
57462
57504
  global_config: symbol_config
57463
57505
  };
57464
57506
  const strategy = new Strategy({
@@ -58031,7 +58073,8 @@ class ExchangeAccount {
58031
58073
  raw: _raw,
58032
58074
  cancel,
58033
58075
  stop,
58034
- ignore_config
58076
+ ignore_config,
58077
+ target_pnl
58035
58078
  } = payload;
58036
58079
  if (cancel) {
58037
58080
  await this.cancelOrders({
@@ -58060,7 +58103,8 @@ class ExchangeAccount {
58060
58103
  if (tp) {
58061
58104
  await this.placeProfitAndStop({
58062
58105
  symbol,
58063
- trigger: true
58106
+ trigger: true,
58107
+ target_pnl
58064
58108
  });
58065
58109
  }
58066
58110
  return [];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-60",
4
+ "version": "0.0.2-62",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",