@gbozee/ultimate 0.0.2-166 → 0.0.2-168

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/index.cjs CHANGED
@@ -60856,12 +60856,18 @@ class ExchangePosition {
60856
60856
  exchange_account;
60857
60857
  app_db;
60858
60858
  instance;
60859
+ orders;
60859
60860
  constructor(payload) {
60860
60861
  this.symbol_config = payload.symbol_config;
60861
60862
  this.exchange = payload.exchange;
60862
60863
  this.app_db = payload.app_db;
60863
60864
  this.instance = payload.instance;
60864
60865
  this.exchange_account = payload.exchange_account;
60866
+ this.orders = payload.orders || {
60867
+ entries: [],
60868
+ stop_orders: [],
60869
+ tp_orders: []
60870
+ };
60865
60871
  }
60866
60872
  async initialize() {
60867
60873
  const proxy = await this.getProxyForAccount();
@@ -61790,17 +61796,68 @@ class ExchangePosition {
61790
61796
  });
61791
61797
  }
61792
61798
  const last_order = focus_position.instance.last_order;
61793
- const take_profit = this.instance.take_profit;
61794
- if (this.kind === "short" && last_order && take_profit) {
61795
- const reduce_ratio = take_profit < last_order ? 1 : 0;
61796
- await this.getConfig({
61797
- params: {
61798
- reduce_ratio
61799
+ let take_profit;
61800
+ if (this.instance.take_profit) {
61801
+ take_profit = to_f(this.instance.take_profit, this.symbol_config.price_places);
61802
+ if (this.kind === "short" && last_order && take_profit) {
61803
+ const reduce_ratio = take_profit < last_order ? 1 : 0;
61804
+ await this.getConfig({
61805
+ params: {
61806
+ reduce_ratio
61807
+ }
61808
+ });
61809
+ }
61810
+ if (this.instance.quantity > 0) {
61811
+ if (focus_position.kind === "long" && focus_position.instance.stop_loss && take_profit > focus_position.appConfig.stop && focus_position.instance.stop_loss?.price < take_profit) {
61812
+ await focus_position.cancelExchangeOrder({
61813
+ type: "stop"
61814
+ });
61799
61815
  }
61800
- });
61816
+ if (focus_position.kind === "short" && focus_position.instance.stop_loss && take_profit < focus_position.appConfig.stop && focus_position.instance.stop_loss?.price > take_profit) {
61817
+ await focus_position.cancelExchangeOrder({
61818
+ type: "stop"
61819
+ });
61820
+ }
61821
+ }
61801
61822
  }
61802
61823
  return { profit_percent, take_profit, last_order };
61803
61824
  }
61825
+ getOrders(payload) {
61826
+ const { type = "limit" } = payload;
61827
+ if (type === "limit") {
61828
+ return this.orders.entries.map(convert_to_exchange_order);
61829
+ }
61830
+ if (type === "stop") {
61831
+ return this.orders.stop_orders.map(convert_to_exchange_order);
61832
+ }
61833
+ if (type === "tp") {
61834
+ return this.orders.tp_orders.map(convert_to_exchange_order);
61835
+ }
61836
+ }
61837
+ async cancelExchangeOrder(payload) {
61838
+ const { type, refresh = true } = payload;
61839
+ const orders = this.getOrders({ type });
61840
+ const result = await this.exchange.cancelOrders({
61841
+ symbol: this.symbol,
61842
+ orders: orders.map((x) => x.order_id)
61843
+ });
61844
+ if (refresh) {
61845
+ await this.refresh(true);
61846
+ }
61847
+ return result;
61848
+ }
61849
+ }
61850
+ function convert_to_exchange_order(order) {
61851
+ return {
61852
+ symbol: order.symbol,
61853
+ price: order.price,
61854
+ quantity: order.quantity,
61855
+ kind: order.kind,
61856
+ side: order.side,
61857
+ stop: order.stop,
61858
+ order_id: order.order_id,
61859
+ triggerPrice: order.triggerPrice
61860
+ };
61804
61861
  }
61805
61862
 
61806
61863
  // src/exchange-account.ts
@@ -61854,8 +61911,7 @@ class ExchangeAccount {
61854
61911
  async initializePositions(payload) {
61855
61912
  const raw_positions = await this.syncAccount({
61856
61913
  update: payload.update,
61857
- symbol: payload.symbol,
61858
- live_refresh: payload.update
61914
+ symbol: payload.symbol
61859
61915
  });
61860
61916
  const positions = await this.syncAccount({
61861
61917
  symbol: payload.symbol,
@@ -61864,6 +61920,9 @@ class ExchangeAccount {
61864
61920
  const symbol_config = await this.recomputeSymbolConfig({
61865
61921
  symbol: payload.symbol
61866
61922
  });
61923
+ const active_account = await this.getActiveAccount({
61924
+ symbol: payload.symbol
61925
+ });
61867
61926
  const long_position = positions.find((x) => x.kind === "long");
61868
61927
  const short_position = positions.find((x) => x.kind === "short");
61869
61928
  this.long_position = new ExchangePosition({
@@ -61872,6 +61931,7 @@ class ExchangeAccount {
61872
61931
  exchange_account: this,
61873
61932
  instance: long_position,
61874
61933
  app_db: this.app_db,
61934
+ orders: active_account.orders.long,
61875
61935
  without_view: raw_positions.find((x) => x.kind === "long")
61876
61936
  });
61877
61937
  await this.long_position.initialize();
@@ -61881,6 +61941,7 @@ class ExchangeAccount {
61881
61941
  exchange_account: this,
61882
61942
  instance: short_position,
61883
61943
  app_db: this.app_db,
61944
+ orders: active_account.orders.short,
61884
61945
  without_view: raw_positions.find((x) => x.kind === "short")
61885
61946
  });
61886
61947
  await this.short_position.initialize();
@@ -63267,6 +63328,7 @@ class ExchangeAccount {
63267
63328
  const opposite_config = focus_position.getOppositeConfig({
63268
63329
  ratio: reward_factor
63269
63330
  });
63331
+ console.log("opposite_config", opposite_config);
63270
63332
  const reverse_config = await reversePosition.getConfig();
63271
63333
  if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
63272
63334
  console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
package/dist/index.d.ts CHANGED
@@ -1706,12 +1706,27 @@ export declare function constructAppConfig(payload: {
1706
1706
  kelly_prediction_model: string;
1707
1707
  };
1708
1708
  }): AppConfig;
1709
+ export type ExchangeOrder = {
1710
+ symbol: string;
1711
+ price: number;
1712
+ quantity: number;
1713
+ kind: "long" | "short";
1714
+ side: "buy" | "sell";
1715
+ stop: number;
1716
+ order_id: string;
1717
+ triggerPrice?: number;
1718
+ };
1709
1719
  export declare class ExchangePosition {
1710
1720
  exchange: BaseExchange;
1711
1721
  symbol_config: SymbolConfig;
1712
1722
  exchange_account: ExchangeAccount$1;
1713
1723
  private app_db;
1714
1724
  private instance;
1725
+ orders: {
1726
+ entries: ExchangeOrder[];
1727
+ stop_orders: ExchangeOrder[];
1728
+ tp_orders: ExchangeOrder[];
1729
+ };
1715
1730
  constructor(payload: {
1716
1731
  exchange: BaseExchange;
1717
1732
  app_db: AppDatabase;
@@ -1719,6 +1734,11 @@ export declare class ExchangePosition {
1719
1734
  instance: PositionsView;
1720
1735
  exchange_account: ExchangeAccount$1;
1721
1736
  without_view?: PositionsView;
1737
+ orders?: {
1738
+ entries: any[];
1739
+ stop_orders: any[];
1740
+ tp_orders: any[];
1741
+ };
1722
1742
  });
1723
1743
  initialize(): Promise<void>;
1724
1744
  getInstance(): PositionsView;
@@ -2029,9 +2049,25 @@ export declare class ExchangePosition {
2029
2049
  focus_position: ExchangePosition;
2030
2050
  }): Promise<{
2031
2051
  profit_percent: number;
2032
- take_profit: any;
2052
+ take_profit: number;
2033
2053
  last_order: number;
2034
2054
  }>;
2055
+ getOrders(payload: {
2056
+ type?: "limit" | "stop" | "tp";
2057
+ }): {
2058
+ symbol: any;
2059
+ price: any;
2060
+ quantity: any;
2061
+ kind: any;
2062
+ side: any;
2063
+ stop: any;
2064
+ order_id: any;
2065
+ triggerPrice: any;
2066
+ }[];
2067
+ cancelExchangeOrder(payload: {
2068
+ type: "limit" | "stop" | "tp";
2069
+ refresh?: boolean;
2070
+ }): Promise<any>;
2035
2071
  }
2036
2072
  declare class ExchangeAccount$1 {
2037
2073
  instance: {
package/dist/index.js CHANGED
@@ -60801,12 +60801,18 @@ class ExchangePosition {
60801
60801
  exchange_account;
60802
60802
  app_db;
60803
60803
  instance;
60804
+ orders;
60804
60805
  constructor(payload) {
60805
60806
  this.symbol_config = payload.symbol_config;
60806
60807
  this.exchange = payload.exchange;
60807
60808
  this.app_db = payload.app_db;
60808
60809
  this.instance = payload.instance;
60809
60810
  this.exchange_account = payload.exchange_account;
60811
+ this.orders = payload.orders || {
60812
+ entries: [],
60813
+ stop_orders: [],
60814
+ tp_orders: []
60815
+ };
60810
60816
  }
60811
60817
  async initialize() {
60812
60818
  const proxy = await this.getProxyForAccount();
@@ -61735,17 +61741,68 @@ class ExchangePosition {
61735
61741
  });
61736
61742
  }
61737
61743
  const last_order = focus_position.instance.last_order;
61738
- const take_profit = this.instance.take_profit;
61739
- if (this.kind === "short" && last_order && take_profit) {
61740
- const reduce_ratio = take_profit < last_order ? 1 : 0;
61741
- await this.getConfig({
61742
- params: {
61743
- reduce_ratio
61744
+ let take_profit;
61745
+ if (this.instance.take_profit) {
61746
+ take_profit = to_f(this.instance.take_profit, this.symbol_config.price_places);
61747
+ if (this.kind === "short" && last_order && take_profit) {
61748
+ const reduce_ratio = take_profit < last_order ? 1 : 0;
61749
+ await this.getConfig({
61750
+ params: {
61751
+ reduce_ratio
61752
+ }
61753
+ });
61754
+ }
61755
+ if (this.instance.quantity > 0) {
61756
+ if (focus_position.kind === "long" && focus_position.instance.stop_loss && take_profit > focus_position.appConfig.stop && focus_position.instance.stop_loss?.price < take_profit) {
61757
+ await focus_position.cancelExchangeOrder({
61758
+ type: "stop"
61759
+ });
61744
61760
  }
61745
- });
61761
+ if (focus_position.kind === "short" && focus_position.instance.stop_loss && take_profit < focus_position.appConfig.stop && focus_position.instance.stop_loss?.price > take_profit) {
61762
+ await focus_position.cancelExchangeOrder({
61763
+ type: "stop"
61764
+ });
61765
+ }
61766
+ }
61746
61767
  }
61747
61768
  return { profit_percent, take_profit, last_order };
61748
61769
  }
61770
+ getOrders(payload) {
61771
+ const { type = "limit" } = payload;
61772
+ if (type === "limit") {
61773
+ return this.orders.entries.map(convert_to_exchange_order);
61774
+ }
61775
+ if (type === "stop") {
61776
+ return this.orders.stop_orders.map(convert_to_exchange_order);
61777
+ }
61778
+ if (type === "tp") {
61779
+ return this.orders.tp_orders.map(convert_to_exchange_order);
61780
+ }
61781
+ }
61782
+ async cancelExchangeOrder(payload) {
61783
+ const { type, refresh = true } = payload;
61784
+ const orders = this.getOrders({ type });
61785
+ const result = await this.exchange.cancelOrders({
61786
+ symbol: this.symbol,
61787
+ orders: orders.map((x) => x.order_id)
61788
+ });
61789
+ if (refresh) {
61790
+ await this.refresh(true);
61791
+ }
61792
+ return result;
61793
+ }
61794
+ }
61795
+ function convert_to_exchange_order(order) {
61796
+ return {
61797
+ symbol: order.symbol,
61798
+ price: order.price,
61799
+ quantity: order.quantity,
61800
+ kind: order.kind,
61801
+ side: order.side,
61802
+ stop: order.stop,
61803
+ order_id: order.order_id,
61804
+ triggerPrice: order.triggerPrice
61805
+ };
61749
61806
  }
61750
61807
 
61751
61808
  // src/exchange-account.ts
@@ -61799,8 +61856,7 @@ class ExchangeAccount {
61799
61856
  async initializePositions(payload) {
61800
61857
  const raw_positions = await this.syncAccount({
61801
61858
  update: payload.update,
61802
- symbol: payload.symbol,
61803
- live_refresh: payload.update
61859
+ symbol: payload.symbol
61804
61860
  });
61805
61861
  const positions = await this.syncAccount({
61806
61862
  symbol: payload.symbol,
@@ -61809,6 +61865,9 @@ class ExchangeAccount {
61809
61865
  const symbol_config = await this.recomputeSymbolConfig({
61810
61866
  symbol: payload.symbol
61811
61867
  });
61868
+ const active_account = await this.getActiveAccount({
61869
+ symbol: payload.symbol
61870
+ });
61812
61871
  const long_position = positions.find((x) => x.kind === "long");
61813
61872
  const short_position = positions.find((x) => x.kind === "short");
61814
61873
  this.long_position = new ExchangePosition({
@@ -61817,6 +61876,7 @@ class ExchangeAccount {
61817
61876
  exchange_account: this,
61818
61877
  instance: long_position,
61819
61878
  app_db: this.app_db,
61879
+ orders: active_account.orders.long,
61820
61880
  without_view: raw_positions.find((x) => x.kind === "long")
61821
61881
  });
61822
61882
  await this.long_position.initialize();
@@ -61826,6 +61886,7 @@ class ExchangeAccount {
61826
61886
  exchange_account: this,
61827
61887
  instance: short_position,
61828
61888
  app_db: this.app_db,
61889
+ orders: active_account.orders.short,
61829
61890
  without_view: raw_positions.find((x) => x.kind === "short")
61830
61891
  });
61831
61892
  await this.short_position.initialize();
@@ -63212,6 +63273,7 @@ class ExchangeAccount {
63212
63273
  const opposite_config = focus_position.getOppositeConfig({
63213
63274
  ratio: reward_factor
63214
63275
  });
63276
+ console.log("opposite_config", opposite_config);
63215
63277
  const reverse_config = await reversePosition.getConfig();
63216
63278
  if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
63217
63279
  console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
@@ -67529,12 +67529,18 @@ class ExchangePosition {
67529
67529
  exchange_account;
67530
67530
  app_db;
67531
67531
  instance;
67532
+ orders;
67532
67533
  constructor(payload) {
67533
67534
  this.symbol_config = payload.symbol_config;
67534
67535
  this.exchange = payload.exchange;
67535
67536
  this.app_db = payload.app_db;
67536
67537
  this.instance = payload.instance;
67537
67538
  this.exchange_account = payload.exchange_account;
67539
+ this.orders = payload.orders || {
67540
+ entries: [],
67541
+ stop_orders: [],
67542
+ tp_orders: []
67543
+ };
67538
67544
  }
67539
67545
  async initialize() {
67540
67546
  const proxy = await this.getProxyForAccount();
@@ -68463,17 +68469,68 @@ class ExchangePosition {
68463
68469
  });
68464
68470
  }
68465
68471
  const last_order = focus_position.instance.last_order;
68466
- const take_profit = this.instance.take_profit;
68467
- if (this.kind === "short" && last_order && take_profit) {
68468
- const reduce_ratio = take_profit < last_order ? 1 : 0;
68469
- await this.getConfig({
68470
- params: {
68471
- reduce_ratio
68472
+ let take_profit;
68473
+ if (this.instance.take_profit) {
68474
+ take_profit = to_f(this.instance.take_profit, this.symbol_config.price_places);
68475
+ if (this.kind === "short" && last_order && take_profit) {
68476
+ const reduce_ratio = take_profit < last_order ? 1 : 0;
68477
+ await this.getConfig({
68478
+ params: {
68479
+ reduce_ratio
68480
+ }
68481
+ });
68482
+ }
68483
+ if (this.instance.quantity > 0) {
68484
+ if (focus_position.kind === "long" && focus_position.instance.stop_loss && take_profit > focus_position.appConfig.stop && focus_position.instance.stop_loss?.price < take_profit) {
68485
+ await focus_position.cancelExchangeOrder({
68486
+ type: "stop"
68487
+ });
68472
68488
  }
68473
- });
68489
+ if (focus_position.kind === "short" && focus_position.instance.stop_loss && take_profit < focus_position.appConfig.stop && focus_position.instance.stop_loss?.price > take_profit) {
68490
+ await focus_position.cancelExchangeOrder({
68491
+ type: "stop"
68492
+ });
68493
+ }
68494
+ }
68474
68495
  }
68475
68496
  return { profit_percent, take_profit, last_order };
68476
68497
  }
68498
+ getOrders(payload) {
68499
+ const { type = "limit" } = payload;
68500
+ if (type === "limit") {
68501
+ return this.orders.entries.map(convert_to_exchange_order);
68502
+ }
68503
+ if (type === "stop") {
68504
+ return this.orders.stop_orders.map(convert_to_exchange_order);
68505
+ }
68506
+ if (type === "tp") {
68507
+ return this.orders.tp_orders.map(convert_to_exchange_order);
68508
+ }
68509
+ }
68510
+ async cancelExchangeOrder(payload) {
68511
+ const { type, refresh = true } = payload;
68512
+ const orders = this.getOrders({ type });
68513
+ const result = await this.exchange.cancelOrders({
68514
+ symbol: this.symbol,
68515
+ orders: orders.map((x) => x.order_id)
68516
+ });
68517
+ if (refresh) {
68518
+ await this.refresh(true);
68519
+ }
68520
+ return result;
68521
+ }
68522
+ }
68523
+ function convert_to_exchange_order(order) {
68524
+ return {
68525
+ symbol: order.symbol,
68526
+ price: order.price,
68527
+ quantity: order.quantity,
68528
+ kind: order.kind,
68529
+ side: order.side,
68530
+ stop: order.stop,
68531
+ order_id: order.order_id,
68532
+ triggerPrice: order.triggerPrice
68533
+ };
68477
68534
  }
68478
68535
 
68479
68536
  // src/exchange-account.ts
@@ -68527,8 +68584,7 @@ class ExchangeAccount {
68527
68584
  async initializePositions(payload) {
68528
68585
  const raw_positions = await this.syncAccount({
68529
68586
  update: payload.update,
68530
- symbol: payload.symbol,
68531
- live_refresh: payload.update
68587
+ symbol: payload.symbol
68532
68588
  });
68533
68589
  const positions = await this.syncAccount({
68534
68590
  symbol: payload.symbol,
@@ -68537,6 +68593,9 @@ class ExchangeAccount {
68537
68593
  const symbol_config = await this.recomputeSymbolConfig({
68538
68594
  symbol: payload.symbol
68539
68595
  });
68596
+ const active_account = await this.getActiveAccount({
68597
+ symbol: payload.symbol
68598
+ });
68540
68599
  const long_position = positions.find((x) => x.kind === "long");
68541
68600
  const short_position = positions.find((x) => x.kind === "short");
68542
68601
  this.long_position = new ExchangePosition({
@@ -68545,6 +68604,7 @@ class ExchangeAccount {
68545
68604
  exchange_account: this,
68546
68605
  instance: long_position,
68547
68606
  app_db: this.app_db,
68607
+ orders: active_account.orders.long,
68548
68608
  without_view: raw_positions.find((x) => x.kind === "long")
68549
68609
  });
68550
68610
  await this.long_position.initialize();
@@ -68554,6 +68614,7 @@ class ExchangeAccount {
68554
68614
  exchange_account: this,
68555
68615
  instance: short_position,
68556
68616
  app_db: this.app_db,
68617
+ orders: active_account.orders.short,
68557
68618
  without_view: raw_positions.find((x) => x.kind === "short")
68558
68619
  });
68559
68620
  await this.short_position.initialize();
@@ -69940,6 +70001,7 @@ class ExchangeAccount {
69940
70001
  const opposite_config = focus_position.getOppositeConfig({
69941
70002
  ratio: reward_factor
69942
70003
  });
70004
+ console.log("opposite_config", opposite_config);
69943
70005
  const reverse_config = await reversePosition.getConfig();
69944
70006
  if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
69945
70007
  console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
@@ -67506,12 +67506,18 @@ class ExchangePosition {
67506
67506
  exchange_account;
67507
67507
  app_db;
67508
67508
  instance;
67509
+ orders;
67509
67510
  constructor(payload) {
67510
67511
  this.symbol_config = payload.symbol_config;
67511
67512
  this.exchange = payload.exchange;
67512
67513
  this.app_db = payload.app_db;
67513
67514
  this.instance = payload.instance;
67514
67515
  this.exchange_account = payload.exchange_account;
67516
+ this.orders = payload.orders || {
67517
+ entries: [],
67518
+ stop_orders: [],
67519
+ tp_orders: []
67520
+ };
67515
67521
  }
67516
67522
  async initialize() {
67517
67523
  const proxy = await this.getProxyForAccount();
@@ -68440,17 +68446,68 @@ class ExchangePosition {
68440
68446
  });
68441
68447
  }
68442
68448
  const last_order = focus_position.instance.last_order;
68443
- const take_profit = this.instance.take_profit;
68444
- if (this.kind === "short" && last_order && take_profit) {
68445
- const reduce_ratio = take_profit < last_order ? 1 : 0;
68446
- await this.getConfig({
68447
- params: {
68448
- reduce_ratio
68449
+ let take_profit;
68450
+ if (this.instance.take_profit) {
68451
+ take_profit = to_f(this.instance.take_profit, this.symbol_config.price_places);
68452
+ if (this.kind === "short" && last_order && take_profit) {
68453
+ const reduce_ratio = take_profit < last_order ? 1 : 0;
68454
+ await this.getConfig({
68455
+ params: {
68456
+ reduce_ratio
68457
+ }
68458
+ });
68459
+ }
68460
+ if (this.instance.quantity > 0) {
68461
+ if (focus_position.kind === "long" && focus_position.instance.stop_loss && take_profit > focus_position.appConfig.stop && focus_position.instance.stop_loss?.price < take_profit) {
68462
+ await focus_position.cancelExchangeOrder({
68463
+ type: "stop"
68464
+ });
68449
68465
  }
68450
- });
68466
+ if (focus_position.kind === "short" && focus_position.instance.stop_loss && take_profit < focus_position.appConfig.stop && focus_position.instance.stop_loss?.price > take_profit) {
68467
+ await focus_position.cancelExchangeOrder({
68468
+ type: "stop"
68469
+ });
68470
+ }
68471
+ }
68451
68472
  }
68452
68473
  return { profit_percent, take_profit, last_order };
68453
68474
  }
68475
+ getOrders(payload) {
68476
+ const { type = "limit" } = payload;
68477
+ if (type === "limit") {
68478
+ return this.orders.entries.map(convert_to_exchange_order);
68479
+ }
68480
+ if (type === "stop") {
68481
+ return this.orders.stop_orders.map(convert_to_exchange_order);
68482
+ }
68483
+ if (type === "tp") {
68484
+ return this.orders.tp_orders.map(convert_to_exchange_order);
68485
+ }
68486
+ }
68487
+ async cancelExchangeOrder(payload) {
68488
+ const { type, refresh = true } = payload;
68489
+ const orders = this.getOrders({ type });
68490
+ const result = await this.exchange.cancelOrders({
68491
+ symbol: this.symbol,
68492
+ orders: orders.map((x) => x.order_id)
68493
+ });
68494
+ if (refresh) {
68495
+ await this.refresh(true);
68496
+ }
68497
+ return result;
68498
+ }
68499
+ }
68500
+ function convert_to_exchange_order(order) {
68501
+ return {
68502
+ symbol: order.symbol,
68503
+ price: order.price,
68504
+ quantity: order.quantity,
68505
+ kind: order.kind,
68506
+ side: order.side,
68507
+ stop: order.stop,
68508
+ order_id: order.order_id,
68509
+ triggerPrice: order.triggerPrice
68510
+ };
68454
68511
  }
68455
68512
 
68456
68513
  // src/exchange-account.ts
@@ -68504,8 +68561,7 @@ class ExchangeAccount {
68504
68561
  async initializePositions(payload) {
68505
68562
  const raw_positions = await this.syncAccount({
68506
68563
  update: payload.update,
68507
- symbol: payload.symbol,
68508
- live_refresh: payload.update
68564
+ symbol: payload.symbol
68509
68565
  });
68510
68566
  const positions = await this.syncAccount({
68511
68567
  symbol: payload.symbol,
@@ -68514,6 +68570,9 @@ class ExchangeAccount {
68514
68570
  const symbol_config = await this.recomputeSymbolConfig({
68515
68571
  symbol: payload.symbol
68516
68572
  });
68573
+ const active_account = await this.getActiveAccount({
68574
+ symbol: payload.symbol
68575
+ });
68517
68576
  const long_position = positions.find((x) => x.kind === "long");
68518
68577
  const short_position = positions.find((x) => x.kind === "short");
68519
68578
  this.long_position = new ExchangePosition({
@@ -68522,6 +68581,7 @@ class ExchangeAccount {
68522
68581
  exchange_account: this,
68523
68582
  instance: long_position,
68524
68583
  app_db: this.app_db,
68584
+ orders: active_account.orders.long,
68525
68585
  without_view: raw_positions.find((x) => x.kind === "long")
68526
68586
  });
68527
68587
  await this.long_position.initialize();
@@ -68531,6 +68591,7 @@ class ExchangeAccount {
68531
68591
  exchange_account: this,
68532
68592
  instance: short_position,
68533
68593
  app_db: this.app_db,
68594
+ orders: active_account.orders.short,
68534
68595
  without_view: raw_positions.find((x) => x.kind === "short")
68535
68596
  });
68536
68597
  await this.short_position.initialize();
@@ -69917,6 +69978,7 @@ class ExchangeAccount {
69917
69978
  const opposite_config = focus_position.getOppositeConfig({
69918
69979
  ratio: reward_factor
69919
69980
  });
69981
+ console.log("opposite_config", opposite_config);
69920
69982
  const reverse_config = await reversePosition.getConfig();
69921
69983
  if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
69922
69984
  console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-166",
4
+ "version": "0.0.2-168",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",