@gbozee/ultimate 0.0.2-9 → 0.0.2-90

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.d.ts CHANGED
@@ -2,9 +2,156 @@
2
2
 
3
3
  import { HttpsProxyAgent } from 'https-proxy-agent';
4
4
  import PocketBase from 'pocketbase';
5
- import { RecordModel } from 'pocketbase';
5
+ import { RecordModel as PocketBaseRecordModel } from 'pocketbase';
6
6
  import { SocksProxyAgent } from 'socks-proxy-agent';
7
7
 
8
+ export type RecordModel = PocketBaseRecordModel;
9
+ export interface BaseSystemFields {
10
+ id: string;
11
+ created: string;
12
+ updated: string;
13
+ }
14
+ export interface ExchangeAccount extends BaseSystemFields {
15
+ exchange: "binance" | "bybit";
16
+ owner: string;
17
+ email?: string;
18
+ user?: string;
19
+ usdt?: number;
20
+ usdc?: number;
21
+ proxy?: string;
22
+ bullish?: boolean;
23
+ bearish?: boolean;
24
+ movePercent?: number;
25
+ totalRisk?: number;
26
+ max_non_essential?: number;
27
+ profit_percent?: number;
28
+ risk_reward?: number;
29
+ exclude_coins?: {
30
+ bullish?: string[];
31
+ };
32
+ include_delisted?: boolean;
33
+ }
34
+ export interface Order extends BaseSystemFields {
35
+ symbol: string;
36
+ account: string;
37
+ kind: "long" | "short";
38
+ price: number;
39
+ quantity: number;
40
+ side: "sell" | "buy";
41
+ stop: number;
42
+ order_id: string;
43
+ }
44
+ export interface SymbolConfig extends BaseSystemFields {
45
+ symbol: string;
46
+ support?: number;
47
+ resistance?: number;
48
+ stop_percent?: number;
49
+ price_places?: string;
50
+ decimal_places?: string;
51
+ min_size?: number;
52
+ weight?: number;
53
+ leverage?: number;
54
+ candle_count?: number;
55
+ interval?: any;
56
+ fee_percent?: number;
57
+ }
58
+ export interface ScheduledTrade extends BaseSystemFields {
59
+ symbol: string;
60
+ account: string;
61
+ profit?: number;
62
+ risk?: number;
63
+ entry?: number;
64
+ stop?: number;
65
+ risk_reward?: number;
66
+ profit_percent?: number;
67
+ place_tp?: boolean;
68
+ kind?: "long" | "short";
69
+ follow?: boolean | 1 | 0;
70
+ reduce_ratio?: number;
71
+ sell_ratio?: number;
72
+ threshold_qty?: number;
73
+ pause_tp?: boolean;
74
+ }
75
+ export interface AccountStrategy extends BaseSystemFields {
76
+ account: string;
77
+ symbol: string;
78
+ risk?: number;
79
+ reward_factor?: number;
80
+ kind?: "long" | "short";
81
+ support?: number;
82
+ resistance?: number;
83
+ running?: boolean;
84
+ }
85
+ interface Proxy$1 extends BaseSystemFields {
86
+ ip_address?: string;
87
+ type?: "http" | "socks5";
88
+ }
89
+ export interface TradeBlockTracking extends BaseSystemFields {
90
+ account?: string;
91
+ symbol?: string;
92
+ running?: boolean;
93
+ }
94
+ export interface PositionsView {
95
+ id: string;
96
+ symbol?: any;
97
+ entry?: any;
98
+ quantity?: any;
99
+ take_profit?: any;
100
+ account?: any;
101
+ kind?: any;
102
+ target_pnl?: number;
103
+ liquidation?: number;
104
+ avg_price?: number;
105
+ avg_qty?: number;
106
+ next_order?: number;
107
+ last_order?: number;
108
+ config?: any;
109
+ stop_loss?: {
110
+ price: number;
111
+ quantity: number;
112
+ };
113
+ stop_pnl?: any;
114
+ leverage?: any;
115
+ avg_liquidation?: any;
116
+ balance?: any;
117
+ reduce_ratio?: number;
118
+ sell_ratio?: number;
119
+ threshold_qty?: number;
120
+ follow?: boolean | 1 | 0;
121
+ current_price?: number;
122
+ usd_balance?: number;
123
+ }
124
+ export interface BullishMarket extends RecordModel {
125
+ id: string;
126
+ symbol: string;
127
+ risk: number;
128
+ }
129
+ export interface WindingDownMarket extends RecordModel {
130
+ id: string;
131
+ symbol: string;
132
+ risk_reward: number;
133
+ }
134
+ export type GlobalConfig = {
135
+ profit_percent: number;
136
+ symbol: string;
137
+ profit: number;
138
+ risk: number;
139
+ stop_percent: number;
140
+ kind: "long" | "short";
141
+ reduce_percent: number;
142
+ support: number;
143
+ resistance: number;
144
+ price_places: string;
145
+ decimal_places: string;
146
+ min_size: number;
147
+ accounts: {
148
+ owner: string;
149
+ exchange?: string;
150
+ }[];
151
+ risk_reward: number;
152
+ reverse_factor: number;
153
+ leverage?: number;
154
+ };
8
155
  interface Position$1 {
9
156
  id: number;
10
157
  kind: "long" | "short";
@@ -85,10 +232,15 @@ export interface BaseExchange {
85
232
  count: number;
86
233
  raw?: boolean;
87
234
  }): Promise<any>;
88
- getExchangeAccountInfo(account: {
89
- owner: string;
90
- exchange: string;
91
- }, symbol: string): Promise<any>;
235
+ getExchangeAccountInfo(options: {
236
+ price_places?: string;
237
+ decimal_places?: string;
238
+ account: {
239
+ owner: string;
240
+ exchange: string;
241
+ };
242
+ symbol: string;
243
+ }): Promise<any>;
92
244
  cancelOrders(payload: {
93
245
  symbol: string;
94
246
  orders: number[];
@@ -98,6 +250,7 @@ export interface BaseExchange {
98
250
  take_profit: number;
99
251
  kind: "long" | "short";
100
252
  cancel?: boolean;
253
+ quantity?: number;
101
254
  price_places?: string;
102
255
  decimal_places?: string;
103
256
  }): Promise<any>;
@@ -121,110 +274,78 @@ export interface BaseExchange {
121
274
  symbol: string;
122
275
  leverage: number;
123
276
  }): Promise<any>;
124
- }
125
- export interface BaseSystemFields {
126
- id: string;
127
- created: string;
128
- updated: string;
129
- }
130
- export interface ExchangeAccount extends BaseSystemFields {
131
- exchange: "binance" | "bybit";
132
- owner: string;
133
- email?: string;
134
- user?: string;
135
- usdt?: number;
136
- usdc?: number;
137
- proxy?: string;
138
- }
139
- export interface SymbolConfig extends BaseSystemFields {
140
- symbol: string;
141
- support?: number;
142
- resistance?: number;
143
- stop_percent?: number;
144
- price_places?: string;
145
- decimal_places?: string;
146
- min_size?: number;
147
- weight?: number;
148
- leverage?: number;
149
- }
150
- export interface ScheduledTrade extends BaseSystemFields {
151
- symbol: string;
152
- account: string;
153
- profit?: number;
154
- risk?: number;
155
- entry?: number;
156
- stop?: number;
157
- risk_reward?: number;
158
- profit_percent?: number;
159
- place_tp?: boolean;
160
- kind?: "long" | "short";
161
- current_price?: number;
162
- }
163
- export interface Strategy extends BaseSystemFields {
164
- name: string;
165
- short_risk_factor?: number;
166
- long_risk_factor?: number;
167
- profit_percent?: number;
168
- cancel_short?: boolean;
169
- cancel_long?: boolean;
170
- recompute_short_config?: boolean;
171
- update_stop_loss?: boolean;
172
- liquidation_as_entry?: boolean;
173
- stop_as_entry?: boolean;
174
- tp_as_stop?: boolean;
175
- entry_as_stop?: boolean;
176
- place_stop?: boolean;
177
- save_config?: boolean;
178
- }
179
- interface Proxy$1 extends BaseSystemFields {
180
- ip_address?: string;
181
- type?: "http" | "socks5";
182
- }
183
- export interface TradeBlockTracking extends BaseSystemFields {
184
- account?: string;
185
- symbol?: string;
186
- running?: boolean;
187
- }
188
- export interface PositionsView {
189
- id: string;
190
- symbol?: any;
191
- entry?: any;
192
- quantity?: any;
193
- take_profit?: any;
194
- account?: any;
195
- kind?: any;
196
- target_pnl?: number;
197
- liquidation?: number;
198
- avg_price?: number;
199
- avg_qty?: number;
200
- next_order?: number;
201
- last_order?: number;
202
- config?: any;
203
- stop_loss?: {
204
- price: number;
277
+ generateConfig(payload: {
278
+ symbol: string;
279
+ interval?: any;
280
+ limit?: number;
281
+ }): Promise<any>;
282
+ checkDelistedMovers(payload: {
283
+ movePercent: number;
284
+ include_delisted?: boolean;
285
+ }): Promise<any>;
286
+ closePosition(payload: {
287
+ symbol: string;
288
+ kind: "long" | "short";
289
+ price_places?: string;
290
+ decimal_places?: string;
291
+ }): Promise<any>;
292
+ getAllOpenSymbols(): Promise<string[]>;
293
+ createLimitPurchaseOrders(payload: {
294
+ orders: any[];
295
+ kind: "long" | "short";
296
+ decimal_places?: string;
297
+ price_places?: string;
298
+ symbol: string;
299
+ }): Promise<any>;
300
+ getDelistedSpotSymbols(): Promise<any>;
301
+ getOpenPositions(): Promise<any>;
302
+ crossAccountTransfer(payload: {
303
+ from: {
304
+ owner: string;
305
+ wallet: string;
306
+ };
307
+ to: {
308
+ owner: string;
309
+ wallet: string;
310
+ };
311
+ asset: string;
312
+ amount: number;
313
+ }): Promise<any>;
314
+ placeMarketOrder(payload: {
315
+ symbol: string;
316
+ kind: "long" | "short";
205
317
  quantity: number;
206
- };
207
- stop_pnl?: any;
208
- leverage?: any;
209
- avg_liquidation?: any;
210
- balance?: any;
211
- }
212
- export interface BullishMarket extends RecordModel {
213
- id: string;
214
- symbol: string;
215
- risk: number;
216
- }
217
- export interface WindingDownMarket extends RecordModel {
218
- id: string;
219
- symbol: string;
318
+ price_places?: string;
319
+ decimal_places?: string;
320
+ }): Promise<any>;
220
321
  }
322
+ declare function initPocketBaseClient(proxy_credentials: {
323
+ host: string;
324
+ email: string;
325
+ password: string;
326
+ auto_cancellation?: boolean;
327
+ }): Promise<PocketBase>;
221
328
  export type ExchangeType = {
222
329
  owner: string;
223
330
  exchange: string;
224
331
  };
225
332
  export declare class AppDatabase {
226
- private pb;
333
+ pb: PocketBase;
227
334
  constructor(pb: PocketBase);
335
+ getCredentials(password: string): any;
336
+ saveCredentials(password: string, credentials: any): Promise<void>;
337
+ addNewCredential(password: string, payload: {
338
+ name: string;
339
+ exchange: string;
340
+ api_key: string;
341
+ api_secret: string;
342
+ }): Promise<void>;
343
+ getAccountWithActivePositions(): Promise<import("pocketbase").RecordModel[]>;
344
+ getAllSymbolsFromPositions(options?: {
345
+ no_position?: boolean;
346
+ kind?: "long" | "short";
347
+ custom_filter?: string;
348
+ }): Promise<any[]>;
228
349
  createOrUpdateLiveExchangeInstance(payload: {
229
350
  account: ExchangeType;
230
351
  symbol: string;
@@ -236,17 +357,25 @@ export declare class AppDatabase {
236
357
  data?: any;
237
358
  }): Promise<import("pocketbase").RecordModel>;
238
359
  getProxyForAccount(account: ExchangeType): Promise<HttpsProxyAgent<`http://${string}`> | SocksProxyAgent>;
360
+ getAccounts(): Promise<ExchangeAccount[]>;
361
+ getAllSymbolConfigs(payload?: {
362
+ with_positions?: boolean;
363
+ custom_filter?: string;
364
+ }): Promise<SymbolConfig[]>;
239
365
  get_exchange_db_instance(account: ExchangeType): Promise<ExchangeAccount & {
240
366
  expand?: {
241
367
  proxy: Proxy$1;
242
368
  };
243
369
  }>;
244
- getPositions(account: ExchangeType, options: {
245
- symbol: string;
370
+ getPositions(options: {
371
+ account?: ExchangeType;
372
+ symbol?: string;
246
373
  as_view?: boolean;
374
+ custom_filter?: string;
247
375
  }): Promise<(PositionsView & {
248
376
  expand?: {
249
377
  config: ScheduledTrade;
378
+ account: ExchangeAccount;
250
379
  };
251
380
  })[]>;
252
381
  private _createOrUpdatePosition;
@@ -258,6 +387,7 @@ export declare class AppDatabase {
258
387
  }): Promise<(PositionsView & {
259
388
  expand?: {
260
389
  config: ScheduledTrade;
390
+ account: ExchangeAccount;
261
391
  };
262
392
  })[]>;
263
393
  update_db_position(position: any, payload: any): Promise<import("pocketbase").RecordModel>;
@@ -269,7 +399,7 @@ export declare class AppDatabase {
269
399
  getOrders(account: ExchangeType, options: {
270
400
  symbol: string;
271
401
  kind: "long" | "short";
272
- }): Promise<import("pocketbase").RecordModel[]>;
402
+ }): Promise<Order[]>;
273
403
  deleteAndRecreateOrders(account: ExchangeType, options: {
274
404
  symbol: string;
275
405
  kind: "long" | "short";
@@ -282,7 +412,32 @@ export declare class AppDatabase {
282
412
  stop: number;
283
413
  order_id: string;
284
414
  triggerPrice?: number;
285
- }>): Promise<import("pocketbase").RecordModel[]>;
415
+ }>): Promise<Order[]>;
416
+ deleteAndBulCreateAllOrders(payload: {
417
+ account: ExchangeType & {
418
+ id: string;
419
+ };
420
+ symbol: string;
421
+ all_orders: Array<{
422
+ symbol: string;
423
+ price: number;
424
+ quantity: number;
425
+ kind: "long" | "short";
426
+ side: "buy" | "sell";
427
+ stop: number;
428
+ order_id: string;
429
+ triggerPrice?: number;
430
+ }>;
431
+ }): Promise<void>;
432
+ cancelLimitOrders(payload: {
433
+ symbol: string;
434
+ kind: "long" | "short";
435
+ account: ExchangeType;
436
+ cancelExchangeOrders: (payload: {
437
+ symbol: string;
438
+ orders: number[];
439
+ }) => Promise<any>;
440
+ }): Promise<void>;
286
441
  cancelOrders(payload: {
287
442
  cancelExchangeOrders: (payload: {
288
443
  symbol: string;
@@ -310,30 +465,49 @@ export declare class AppDatabase {
310
465
  message?: undefined;
311
466
  exchange_result?: undefined;
312
467
  }>;
468
+ getMoverExchangeInstances(): Promise<ExchangeAccount[]>;
469
+ updateScheduledTrade(id: string, payload: any): Promise<import("pocketbase").RecordModel>;
470
+ getPositionsToAutoFollow(): Promise<(Position$1 & {
471
+ expand: {
472
+ account: ExchangeAccount;
473
+ };
474
+ })[]>;
313
475
  createOrUpdatePositionConfig(db_position: any, payload: {
314
476
  entry: number;
315
477
  stop: number;
316
478
  risk_reward: number;
317
479
  risk: number;
318
480
  profit_percent?: number;
319
- }): Promise<void>;
481
+ place_tp?: boolean;
482
+ profit?: number;
483
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
320
484
  getPositionConfig(payload: {
321
485
  symbol: string;
322
486
  kind: "long" | "short";
323
487
  account: ExchangeType;
324
- }): Promise<import("pocketbase").RecordModel>;
325
- getPositionStrategy(account: ExchangeType): Promise<{
326
- strategy_instance: Strategy;
327
- focus_account: ExchangeAccount;
328
- }>;
329
- createOrUpdateWindingDownMarket(symbol: string): Promise<import("pocketbase").RecordModel>;
330
- getWindingDownMarkets(): Promise<WindingDownMarket[]>;
331
- getBullishMarkets(options?: {
332
- new_markets: Array<{
333
- symbol: string;
488
+ }): Promise<ScheduledTrade | null>;
489
+ getRunningAccountStrategies(): Promise<(AccountStrategy & {
490
+ expand?: {
491
+ account: ExchangeAccount;
492
+ };
493
+ })[]>;
494
+ getAccountStrategy(payload: {
495
+ symbol: string;
496
+ account: ExchangeType;
497
+ }): Promise<AccountStrategy>;
498
+ createOrUpdateWindingDownMarket(payload: {
499
+ symbol: string;
500
+ risk_reward?: number;
501
+ }): Promise<import("pocketbase").RecordModel>;
502
+ getWindingDownMarkets(symbol?: string): Promise<WindingDownMarket[]>;
503
+ getBullishMarket(symbol: string): Promise<BullishMarket>;
504
+ getBullishMarkets(options?: {
505
+ new_markets: Array<{
506
+ symbol: string;
334
507
  percent: number;
335
508
  }>;
336
509
  totalRisk: number;
510
+ max_count?: number;
337
511
  }): Promise<{
338
512
  updated_bullish: BullishMarket[];
339
513
  moved_to_winding: WindingDownMarket[];
@@ -352,18 +526,337 @@ export declare class AppDatabase {
352
526
  updated: number;
353
527
  created: number;
354
528
  } | SymbolConfig[]>;
355
- unwindSymbolFromDB(symbol: string): Promise<void>;
529
+ unwindSymbolFromDB(symbol: string): Promise<boolean>;
530
+ hasExistingPosition(symbol: string): Promise<import("pocketbase").RecordModel[]>;
531
+ hasExistingOrders(symbol: string): Promise<import("pocketbase").RecordModel[]>;
532
+ removeSymbolFromUnwindingMarkets(symbol: string): Promise<boolean>;
533
+ removePosition(position: any): Promise<void>;
534
+ removePositionConfig(position: any): Promise<void>;
535
+ }
536
+ export type StrategyPosition = {
537
+ entry: number;
538
+ quantity: number;
539
+ avg_price?: number;
540
+ };
541
+ export type GapCloserResult = {
542
+ avg_entry: number;
543
+ avg_size: number;
544
+ loss: number;
545
+ stop: number;
546
+ stop_quantity: number;
547
+ re_entry_quantity: number;
548
+ initial_pnl: number;
549
+ tp: number;
550
+ incurred_loss: number;
551
+ pnl: number;
552
+ remaining_quantity: number;
553
+ };
554
+ export type Config = {
555
+ tp_percent: number;
556
+ short_tp_factor: number;
557
+ fee_percent?: number;
558
+ budget: number;
559
+ risk_reward: number;
560
+ reduce_ratio: number;
561
+ global_config: GlobalConfig;
562
+ };
563
+ export declare class Strategy {
564
+ position: {
565
+ long: StrategyPosition;
566
+ short: StrategyPosition;
567
+ };
568
+ dominant_position?: "long" | "short";
569
+ config: Config;
570
+ constructor(payload: {
571
+ long: StrategyPosition;
572
+ short: StrategyPosition;
573
+ config: Config;
574
+ dominant_position?: "long" | "short";
575
+ });
576
+ get price_places(): string;
577
+ get decimal_places(): string;
578
+ to_f(price: number): number;
579
+ to_df(quantity: number): number;
580
+ pnl(kind: "long" | "short", _position?: StrategyPosition): number;
581
+ tp(kind: "long" | "short"): number;
582
+ calculate_fee(position: {
583
+ price: number;
584
+ quantity: number;
585
+ }): number;
586
+ get long_tp(): number;
587
+ get short_tp(): number;
588
+ generateGapClosingAlgorithm(payload: {
589
+ kind: "long" | "short";
590
+ ignore_entries?: boolean;
591
+ reduce_ratio?: number;
592
+ sell_factor?: number;
593
+ }): {
594
+ last_entry: any;
595
+ first_entry: any;
596
+ threshold: any;
597
+ risk: number;
598
+ risk_reward: number;
599
+ spread: number;
600
+ gap_loss: number;
601
+ net_profit: number;
602
+ long: GapCloserResult;
603
+ short: GapCloserResult;
604
+ };
605
+ gapCloserHelper(payload: {
606
+ risk: number;
607
+ entries?: any[];
608
+ kind: "long" | "short";
609
+ sell_factor?: number;
610
+ reduce_ratio?: number;
611
+ }): {
612
+ risk: number;
613
+ risk_reward: number;
614
+ spread: number;
615
+ gap_loss: number;
616
+ net_profit: number;
617
+ long: GapCloserResult;
618
+ short: GapCloserResult;
619
+ };
620
+ runIterations(payload: {
621
+ kind: "long" | "short";
622
+ iterations: number;
623
+ risk_reward?: number;
624
+ ignore_entries?: boolean;
625
+ reduce_ratio?: number;
626
+ sell_factor?: number;
627
+ }): {
628
+ last_entry: any;
629
+ first_entry: any;
630
+ threshold: any;
631
+ risk: number;
632
+ risk_reward: number;
633
+ spread: number;
634
+ gap_loss: number;
635
+ net_profit: number;
636
+ long: GapCloserResult;
637
+ short: GapCloserResult;
638
+ }[];
639
+ getPositionAfterTp(payload: {
640
+ kind: "long" | "short";
641
+ include_fees?: boolean;
642
+ }): {
643
+ [x: string]: number | {
644
+ entry: number;
645
+ quantity: number;
646
+ diff?: undefined;
647
+ } | {
648
+ [x: string]: number;
649
+ diff: number;
650
+ entry?: undefined;
651
+ quantity?: undefined;
652
+ };
653
+ pnl: {
654
+ [x: string]: number;
655
+ diff: number;
656
+ };
657
+ spread: number;
658
+ };
659
+ getPositionAfterIteration(payload: {
660
+ kind: "long" | "short";
661
+ iterations: number;
662
+ with_fees?: boolean;
663
+ }): {
664
+ [x: string]: number | {
665
+ entry: number;
666
+ quantity: number;
667
+ diff?: undefined;
668
+ } | {
669
+ [x: string]: number;
670
+ diff: number;
671
+ entry?: undefined;
672
+ quantity?: undefined;
673
+ };
674
+ pnl: {
675
+ [x: string]: number;
676
+ diff: number;
677
+ };
678
+ spread: number;
679
+ }[];
680
+ /**To be used as one of the agent tools eventually since
681
+ * it is something that can be triggered continously without
682
+ * any risk
683
+ */
684
+ generateOppositeTrades(payload: {
685
+ kind: "long" | "short";
686
+ risk_factor?: number;
687
+ avg_entry?: number;
688
+ }): {
689
+ avg: {
690
+ entry: number;
691
+ price: number;
692
+ quantity: number;
693
+ };
694
+ loss: number;
695
+ profit_percent: number;
696
+ fee: number;
697
+ risk_per_trade: number;
698
+ risk_reward: number;
699
+ symbol?: string;
700
+ focus: number;
701
+ budget: number;
702
+ support: number;
703
+ resistance: number;
704
+ percent_change: number;
705
+ tradeSplit?: number;
706
+ take_profit?: number;
707
+ kind: "long" | "short";
708
+ entry: number;
709
+ stop: number;
710
+ min_size: number;
711
+ price_places?: string;
712
+ strategy?: "quantity" | "entry";
713
+ as_array?: boolean;
714
+ decimal_places?: string;
715
+ min_profit?: number;
716
+ raw?: boolean;
717
+ gap?: number;
718
+ rr?: number;
719
+ max_size?: number;
720
+ };
356
721
  }
357
- export interface CodeNode {
722
+ export type SignalConfigType = {
723
+ focus: number;
724
+ budget: number;
725
+ percent_change?: number;
726
+ price_places?: string;
727
+ decimal_places?: string;
728
+ zone_risk?: number;
729
+ fee?: number;
730
+ support?: number;
731
+ risk_reward?: number;
732
+ resistance?: number;
733
+ risk_per_trade?: number;
734
+ increase_size?: boolean;
735
+ additional_increase?: number;
736
+ minimum_pnl?: number;
737
+ take_profit?: number;
738
+ increase_position?: boolean;
739
+ minimum_size?: number;
740
+ first_order_size?: number;
741
+ gap?: number;
742
+ max_size?: number;
743
+ };
744
+ declare class Signal {
745
+ focus: number;
746
+ budget: number;
747
+ percent_change: number;
748
+ price_places: string;
749
+ decimal_places: string;
750
+ zone_risk: number;
751
+ fee: number;
752
+ support?: number;
753
+ risk_reward: number;
754
+ resistance?: number;
755
+ risk_per_trade?: number;
756
+ increase_size: boolean;
757
+ additional_increase: number;
358
758
  minimum_pnl: number;
759
+ take_profit?: number;
760
+ increase_position: boolean;
761
+ minimum_size: any;
762
+ first_order_size: number;
763
+ gap: number;
359
764
  max_size: number;
360
- profit: number;
361
- ratio?: number;
362
- increase: boolean;
363
- not_reduce?: boolean;
364
- reduce_ratio?: number;
365
- use_full?: boolean;
765
+ constructor({ focus, budget, percent_change, price_places, decimal_places, zone_risk, fee, support, risk_reward, resistance, risk_per_trade, increase_size, additional_increase, minimum_pnl, take_profit, increase_position, minimum_size, first_order_size, gap, max_size, }: SignalConfigType);
766
+ build_entry({ current_price, stop_loss, pnl, stop_percent, kind, risk, no_of_trades, take_profit, }: {
767
+ take_profit?: number;
768
+ no_of_trades?: number;
769
+ current_price: number;
770
+ stop_loss?: number;
771
+ kind?: "long" | "short";
772
+ risk: number;
773
+ stop_percent?: number;
774
+ pnl?: number;
775
+ }): any;
776
+ get risk(): number;
777
+ get min_trades(): number;
778
+ get min_price(): number;
779
+ build_opposite_order({ current_price, kind, }: {
780
+ current_price: number;
781
+ kind?: "long" | "short";
782
+ }): any;
783
+ special_build_orders({ current_price, kind, }: {
784
+ current_price: number;
785
+ kind?: "long" | "short";
786
+ }): any;
787
+ build_orders({ current_price, kind, limit, replace_focus, max_index, min_index, }: {
788
+ current_price: number;
789
+ kind?: "long" | "short";
790
+ limit?: boolean;
791
+ replace_focus?: boolean;
792
+ max_index?: number;
793
+ min_index?: number;
794
+ }): any;
795
+ build_orders_old({ current_price, kind, limit, replace_focus, max_index, min_index, }: {
796
+ current_price: number;
797
+ kind?: "long" | "short";
798
+ limit?: boolean;
799
+ replace_focus?: boolean;
800
+ max_index?: number;
801
+ min_index?: number;
802
+ }): any;
803
+ get_bulk_trade_zones({ current_price, kind, limit, }: {
804
+ current_price: number;
805
+ kind?: "long" | "short";
806
+ limit?: boolean;
807
+ }): any;
808
+ get_future_zones({ current_price, kind, raw, }: {
809
+ raw?: boolean;
810
+ current_price: number;
811
+ kind?: "long" | "short";
812
+ }): number[];
813
+ to_f(value: number, places?: string): number;
814
+ get_margin_zones({ current_price, kind, }: {
815
+ current_price: number;
816
+ kind?: "long" | "short";
817
+ }): number[][];
818
+ get_margin_range(current_price: number, kind?: string): number[];
819
+ process_orders({ current_price, stop_loss, trade_zones, kind, }: {
820
+ current_price: number;
821
+ stop_loss: number;
822
+ trade_zones: number[];
823
+ kind?: "long" | "short";
824
+ }): any[];
825
+ get_risk_per_trade(number_of_orders: number): number;
826
+ build_trade_dict({ entry, stop, risk, arr, index, new_fees, kind, start, take_profit, }: {
827
+ entry: number;
828
+ stop: number;
829
+ risk: number;
830
+ arr: number[];
831
+ index: number;
832
+ new_fees?: number;
833
+ kind?: "long" | "short";
834
+ start?: number;
835
+ take_profit?: number;
836
+ }): {
837
+ entry: number;
838
+ risk: number;
839
+ quantity: number;
840
+ sell_price: number;
841
+ risk_sell: number;
842
+ stop: number;
843
+ pnl: number;
844
+ fee: number;
845
+ net: number;
846
+ incurred: number;
847
+ stop_percent: number;
848
+ };
849
+ to_df(currentPrice: number, places?: string): number;
366
850
  }
851
+ export declare function determine_average_entry_and_size(orders: Array<{
852
+ price: number;
853
+ quantity: number;
854
+ }>, places?: string, price_places?: string): {
855
+ entry: number;
856
+ price: number;
857
+ quantity: number;
858
+ };
859
+ export declare const createArray: (start: number, stop: number, step: number) => number[];
367
860
  export type AppConfig = {
368
861
  fee: number;
369
862
  risk_per_trade: number;
@@ -389,61 +882,170 @@ export type AppConfig = {
389
882
  gap?: number;
390
883
  rr?: number;
391
884
  max_size?: number;
885
+ last_value?: any;
886
+ entries?: any[];
392
887
  };
393
- declare class ExchangeAccount$1 {
394
- private instance;
395
- private exchange;
888
+ export type ExtendConfigType = {
889
+ take_profit?: number;
890
+ entry: number;
891
+ risk?: number;
892
+ stop?: number;
893
+ risk_reward?: number;
894
+ raw_instance?: boolean;
895
+ no_of_trades?: number;
896
+ increase?: boolean;
897
+ price_places?: string;
898
+ decimal_places?: string;
899
+ min_profit?: number;
900
+ kind?: "long" | "short";
901
+ gap?: number;
902
+ rr?: number;
903
+ };
904
+ export declare function buildConfig(app_config: AppConfig, { take_profit, entry, stop, raw_instance, risk, no_of_trades, min_profit, risk_reward, kind, increase, gap, rr, price_places, decimal_places, }: ExtendConfigType): any[] | Signal;
905
+ export declare function buildAvg({ _trades, kind, }: {
906
+ _trades: any[];
907
+ kind: "long" | "short";
908
+ }): any;
909
+ export declare function sortedBuildConfig(app_config: AppConfig, options: any): any[];
910
+ export declare function get_app_config_and_max_size(config: GlobalConfig, payload: {
911
+ entry: number;
912
+ stop: number;
913
+ kind: "long" | "short";
914
+ }): {
915
+ app_config: AppConfig;
916
+ max_size: any;
917
+ last_value: any;
918
+ entries: {
919
+ entry: any;
920
+ avg_entry: any;
921
+ avg_size: any;
922
+ neg_pnl: any;
923
+ quantity: any;
924
+ }[];
925
+ };
926
+ export declare function buildAppConfig(config: GlobalConfig, payload: {
927
+ entry: number;
928
+ stop: number;
929
+ risk_reward: number;
930
+ risk: number;
931
+ symbol: string;
932
+ profit?: number;
933
+ }): AppConfig;
934
+ export declare function getOptimumStopAndRisk(app_config: AppConfig, params: {
935
+ max_size: number;
936
+ target_stop: number;
937
+ highest_risk?: number;
938
+ }): {
939
+ optimal_stop: number;
940
+ optimal_risk: number;
941
+ avg_size: any;
942
+ avg_entry: any;
943
+ result: any[];
944
+ first_entry: any;
945
+ neg_pnl: any;
946
+ risk_reward: number;
947
+ size_diff: number;
948
+ entry_diff: number;
949
+ };
950
+ export declare function generate_config_params(app_config: AppConfig, payload: {
951
+ entry: number;
952
+ stop: number;
953
+ risk_reward: number;
954
+ risk: number;
955
+ symbol: string;
956
+ }): {
957
+ entry: number;
958
+ stop: number;
959
+ avg_size: any;
960
+ avg_entry: any;
961
+ risk_reward: number;
962
+ neg_pnl: any;
963
+ risk: number;
964
+ };
965
+ export declare function determine_break_even_price(payload: {
966
+ long_position: {
967
+ entry: number;
968
+ quantity: number;
969
+ };
970
+ short_position: {
971
+ entry: number;
972
+ quantity: number;
973
+ };
974
+ fee_percent?: number;
975
+ }): {
976
+ price: number;
977
+ direction: string;
978
+ };
979
+ export declare function determine_amount_to_buy(payload: {
980
+ orders: any[];
981
+ kind: "long" | "short";
982
+ decimal_places?: string;
983
+ price_places?: string;
984
+ place?: boolean;
985
+ position: any;
986
+ existingOrders: any[];
987
+ }): any[];
988
+ export declare function generateOptimumAppConfig(config: GlobalConfig, payload: {
989
+ entry: number;
990
+ stop: number;
991
+ risk_reward: number;
992
+ start_risk: number;
993
+ max_risk?: number;
994
+ }, position: {
995
+ entry: number;
996
+ quantity: number;
997
+ kind: "long" | "short";
998
+ }): AppConfig | null;
999
+ export declare function determineOptimumReward(app_config: AppConfig, increase?: boolean, low_range?: number, high_range?: number): number | {
1000
+ result: any[];
1001
+ value: number;
1002
+ total: number;
1003
+ risk_per_trade: number;
1004
+ max: number;
1005
+ min: number;
1006
+ neg_pnl: any;
1007
+ entry: any;
1008
+ };
1009
+ export declare function computeRiskReward(payload: {
1010
+ app_config: AppConfig;
1011
+ entry: number;
1012
+ stop: number;
1013
+ risk_per_trade: number;
1014
+ }): number | {
1015
+ result: any[];
1016
+ value: number;
1017
+ total: number;
1018
+ risk_per_trade: number;
1019
+ max: number;
1020
+ min: number;
1021
+ neg_pnl: any;
1022
+ entry: any;
1023
+ };
1024
+ export declare function getRiskReward(payload: {
1025
+ entry: number;
1026
+ stop: number;
1027
+ risk: number;
1028
+ global_config: GlobalConfig;
1029
+ }): any;
1030
+ declare class ExchangePosition {
1031
+ exchange: BaseExchange;
1032
+ exchange_account: ExchangeAccount$1;
396
1033
  private app_db;
397
- constructor(payload: ExchangeType, options: {
1034
+ private instance;
1035
+ constructor(payload: {
398
1036
  exchange: BaseExchange;
399
1037
  app_db: AppDatabase;
1038
+ instance: PositionsView;
1039
+ exchange_account: ExchangeAccount$1;
1040
+ without_view?: PositionsView;
400
1041
  });
401
- /**
402
- *In order to avoid rate limiting issues, we cache the live exchange
403
- details for each symbol for an account in the database with an option
404
- to refresh.
405
- */
406
- getLiveExchangeInstance(payload: {
407
- symbol: string;
408
- refresh?: boolean;
409
- }): Promise<import("pocketbase").RecordModel>;
410
- getActiveAccount(symbol: string, full?: boolean): Promise<Account | {
411
- liquidation: {
412
- long: number;
413
- short: number;
414
- };
415
- active_account: Account;
416
- current_price: any;
417
- exchange: any;
418
- }>;
419
- syncAccount(options: {
420
- symbol: string;
421
- kind?: "long" | "short";
422
- update?: boolean;
423
- as_view?: boolean;
424
- leverage?: number;
425
- }): Promise<(PositionsView & {
426
- expand?: {
427
- config: ScheduledTrade;
428
- };
429
- }) | (PositionsView & {
430
- expand?: {
431
- config: ScheduledTrade;
432
- };
433
- })[]>;
434
- getRunningInstanceFromDB(symbol: string): Promise<TradeBlockTracking>;
435
- syncOrders(options: {
436
- symbol: string;
437
- kind: "long" | "short";
438
- update?: boolean;
439
- }): Promise<import("pocketbase").RecordModel[]>;
1042
+ get symbol(): any;
1043
+ get kind(): any;
1044
+ get account(): any;
440
1045
  cancelOrders(payload: {
441
- symbol: string;
442
- kind: "long" | "short";
1046
+ limit?: boolean;
443
1047
  price?: number;
444
- all?: boolean;
445
- stop?: boolean;
446
- }): Promise<{
1048
+ }): Promise<void | {
447
1049
  success: boolean;
448
1050
  message: string;
449
1051
  exchange_result?: undefined;
@@ -459,16 +1061,42 @@ declare class ExchangeAccount$1 {
459
1061
  message?: undefined;
460
1062
  exchange_result?: undefined;
461
1063
  }>;
462
- cancelExchangeOrders(payload: {
463
- symbol: string;
464
- orders: number[];
1064
+ getConfig(payload?: {
1065
+ params?: {
1066
+ entry?: number;
1067
+ stop?: number;
1068
+ risk_reward?: number;
1069
+ risk?: number;
1070
+ profit_percent?: number;
1071
+ place_tp?: boolean;
1072
+ profit?: number;
1073
+ };
1074
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
1075
+ updateTargetPnl(): Promise<number>;
1076
+ updateConfigPnl(): Promise<void>;
1077
+ triggerTradeFromConfig(payload: {
1078
+ place?: boolean;
1079
+ raw?: boolean;
1080
+ tp?: boolean;
1081
+ stop?: boolean;
1082
+ use_current?: boolean;
1083
+ ignore_config?: boolean;
1084
+ }): Promise<any>;
1085
+ placeSharedOrder(action: "place_limit_orders" | "place_stop_orders" | "place_tp_orders", payload: {
1086
+ entry: number;
1087
+ stop: number;
1088
+ risk_reward: number;
1089
+ risk: number;
1090
+ place?: boolean;
1091
+ update_db?: boolean;
1092
+ raw?: boolean;
1093
+ use_current?: boolean;
465
1094
  }): Promise<any>;
466
1095
  buildAppConfig(payload: {
467
1096
  entry: number;
468
1097
  stop: number;
469
1098
  risk_reward: number;
470
1099
  risk: number;
471
- symbol: string;
472
1100
  profit?: number;
473
1101
  update_db?: boolean;
474
1102
  profit_percent?: number;
@@ -500,84 +1128,115 @@ declare class ExchangeAccount$1 {
500
1128
  kind: "long" | "short";
501
1129
  quantity: any;
502
1130
  is_limit: boolean;
1131
+ neg_pnl: any;
503
1132
  };
504
1133
  trades: any[];
505
1134
  }>;
506
- placeSharedOrder(action: "place_limit_orders" | "place_stop_orders" | "place_tp_orders", payload: {
507
- symbol: string;
508
- entry: number;
509
- stop: number;
510
- risk_reward: number;
511
- risk: number;
512
- place?: boolean;
513
- update_db?: boolean;
514
- }): Promise<any>;
515
- getPositionConfig(payload: {
516
- symbol: string;
1135
+ determineAmountToBuy(payload: {
1136
+ orders: any[];
517
1137
  kind: "long" | "short";
518
- params?: {
519
- entry: number;
520
- stop: number;
521
- risk_reward: number;
522
- risk: number;
523
- profit_percent?: number;
524
- };
525
- }): Promise<import("pocketbase").RecordModel>;
526
- getCurrentPrice(symbol: string): Promise<any>;
527
- getPositionStrategy(): Promise<{
528
- strategy_instance: Strategy;
529
- focus_account: ExchangeAccount;
1138
+ refresh?: boolean;
1139
+ decimal_places?: string;
1140
+ price_places?: string;
1141
+ cancel?: boolean;
1142
+ place?: boolean;
1143
+ }): Promise<any[]>;
1144
+ refresh(live_refresh?: boolean): Promise<{
1145
+ instance: PositionsView;
1146
+ existingOrders: void | Order[];
530
1147
  }>;
531
- getOriginalPlannedStop(payload: {
532
- symbol: string;
533
- kind: "long" | "short";
534
- }): Promise<any>;
535
- syncReduceClosePosition(symbol: string, payload?: {
536
- kind?: "long" | "short";
537
- long?: CodeNode;
538
- short?: CodeNode;
539
- trigger?: {
540
- long: boolean;
541
- short: boolean;
542
- };
1148
+ placeTrade(payload: {
1149
+ place?: boolean;
1150
+ tp?: boolean;
1151
+ stop?: boolean;
1152
+ raw?: boolean;
1153
+ cancel?: boolean;
1154
+ ignore_config?: boolean;
543
1155
  }): Promise<any>;
544
1156
  }
545
- declare class App {
1157
+ declare class ExchangeAccount$1 {
1158
+ private instance;
1159
+ exchange: BaseExchange;
1160
+ main_exchange?: BaseExchange;
546
1161
  private app_db;
547
- private getCredentials;
548
- constructor(app_db: AppDatabase, getCredentials: (account: string, exchange: string) => (account: string, exchange: string) => Promise<{
549
- api_key: string;
550
- api_secret: string;
551
- }>);
552
- getExchangeAccount(account: ExchangeType): Promise<ExchangeAccount$1>;
553
- syncAccount(payload: {
554
- account: ExchangeType;
1162
+ private long_position?;
1163
+ private short_position?;
1164
+ constructor(payload: ExchangeType, options: {
1165
+ exchange: BaseExchange;
1166
+ app_db: AppDatabase;
1167
+ main_exchange?: BaseExchange;
1168
+ });
1169
+ /**
1170
+ *In order to avoid rate limiting issues, we cache the live exchange
1171
+ details for each symbol for an account in the database with an option
1172
+ to refresh.
1173
+ */
1174
+ getDBInstance(): AppDatabase;
1175
+ getLiveExchangeInstance(payload: {
1176
+ symbol: string;
1177
+ refresh?: boolean;
1178
+ refresh_symbol_config?: boolean;
1179
+ }): Promise<import("pocketbase").RecordModel>;
1180
+ initializePositions(payload: {
555
1181
  symbol: string;
556
- kind?: "long" | "short";
557
- update?: boolean;
558
1182
  as_view?: boolean;
1183
+ kind: "long" | "short";
1184
+ }): Promise<ExchangePosition>;
1185
+ getActiveAccount(payload: {
1186
+ symbol: string;
1187
+ full?: boolean;
1188
+ refresh?: boolean;
1189
+ }): Promise<Account | {
1190
+ liquidation: {
1191
+ long: number;
1192
+ short: number;
1193
+ };
1194
+ active_account: Account;
1195
+ current_price: any;
1196
+ exchange: any;
1197
+ }>;
1198
+ refreshAccount(payload: {
1199
+ symbol: string;
1200
+ live_refresh?: boolean;
1201
+ leverage?: number;
559
1202
  }): Promise<(PositionsView & {
560
1203
  expand?: {
561
1204
  config: ScheduledTrade;
1205
+ account: ExchangeAccount;
562
1206
  };
563
- }) | (PositionsView & {
1207
+ })[]>;
1208
+ syncAccount(options: {
1209
+ symbol: string;
1210
+ kind?: "long" | "short";
1211
+ update?: boolean;
1212
+ as_view?: boolean;
1213
+ leverage?: number;
1214
+ live_refresh?: boolean;
1215
+ }): Promise<PositionsView | (PositionsView & {
564
1216
  expand?: {
565
1217
  config: ScheduledTrade;
1218
+ account: ExchangeAccount;
566
1219
  };
567
1220
  })[]>;
568
- syncOrders(payload: {
569
- account: ExchangeType;
1221
+ getRunningInstanceFromDB(symbol: string): Promise<TradeBlockTracking>;
1222
+ syncOrders(options: {
1223
+ symbol: string;
1224
+ kind?: "long" | "short";
1225
+ update?: boolean;
1226
+ }): Promise<void | Order[]>;
1227
+ toggleStopBuying(payload: {
570
1228
  symbol: string;
571
1229
  kind: "long" | "short";
572
- }): Promise<any>;
1230
+ should_stop?: boolean;
1231
+ }): Promise<import("pocketbase").RecordModel>;
573
1232
  cancelOrders(payload: {
574
- account: ExchangeType;
575
1233
  symbol: string;
576
1234
  kind: "long" | "short";
577
1235
  price?: number;
578
1236
  all?: boolean;
579
1237
  stop?: boolean;
580
- }): Promise<{
1238
+ limit?: boolean;
1239
+ }): Promise<void | {
581
1240
  success: boolean;
582
1241
  message: string;
583
1242
  exchange_result?: undefined;
@@ -593,83 +1252,596 @@ declare class App {
593
1252
  message?: undefined;
594
1253
  exchange_result?: undefined;
595
1254
  }>;
596
- triggerTradeFromConfig(payload: {
597
- account: ExchangeType;
1255
+ cancelExchangeOrders(payload: {
598
1256
  symbol: string;
599
- kind: "long" | "short";
1257
+ orders: number[];
600
1258
  }): Promise<any>;
601
- toggleStopBuying(payload: {
602
- account: ExchangeType;
1259
+ getBreakEvenPrice(payload: {
603
1260
  symbol: string;
604
- kind: "long" | "short";
605
- should_stop?: boolean;
606
- }): Promise<import("pocketbase").RecordModel>;
607
- generate_config_params(exchange_account: ExchangeAccount$1, payload: {
1261
+ }): Promise<{
1262
+ price: number;
1263
+ direction: string;
1264
+ }>;
1265
+ buildAppConfig(payload: {
608
1266
  entry: number;
609
1267
  stop: number;
610
1268
  risk_reward: number;
611
1269
  risk: number;
612
1270
  symbol: string;
1271
+ profit?: number;
1272
+ update_db?: boolean;
1273
+ profit_percent?: number;
1274
+ }): Promise<AppConfig>;
1275
+ tradeConfig(payload: {
1276
+ symbol: string;
1277
+ kind: "long" | "short";
1278
+ }): Promise<AppConfig>;
1279
+ justInTimeProfit(payload: {
1280
+ symbol: string;
1281
+ target_pnl: number;
1282
+ kind: "long" | "short";
1283
+ refresh?: boolean;
1284
+ place?: boolean;
1285
+ take_profit?: number;
1286
+ pause_tp?: boolean;
613
1287
  }): Promise<{
614
- place_stop: boolean;
1288
+ sell_ratio: number;
1289
+ current_pnl: number;
615
1290
  profit_percent: number;
1291
+ current_price: number;
1292
+ notional_value: number;
1293
+ }>;
1294
+ buildTrades(payload: {
1295
+ symbol: string;
1296
+ kind: "long" | "short";
1297
+ risk?: number;
1298
+ }): Promise<{
1299
+ trades: any[];
1300
+ max_size: any;
1301
+ last_price: any;
1302
+ total_size: number;
1303
+ avg_entry: number;
1304
+ }>;
1305
+ placeConfigOrders(app_config: AppConfig, solution: {
1306
+ risk_reward: number;
1307
+ entry: number;
1308
+ stop: number;
1309
+ risk_per_trade: number;
1310
+ avg_size: number;
1311
+ neg_pnl: number;
1312
+ min_size: number;
1313
+ symbol: string;
1314
+ }, place?: boolean, skip_stop?: boolean): Promise<{
1315
+ entry_orders: {
1316
+ orders: {
1317
+ entry: any;
1318
+ quantity: any;
1319
+ reverse_avg_entry: any;
1320
+ reverse_avg_quantity: any;
1321
+ avg_entry: any;
1322
+ avg_size: any;
1323
+ }[];
1324
+ kind: "long" | "short";
1325
+ };
1326
+ stop_orders: {
1327
+ stop: number;
1328
+ final_stop: number;
1329
+ kind: "long" | "short";
1330
+ quantity: any;
1331
+ is_limit: boolean;
1332
+ neg_pnl: any;
1333
+ };
1334
+ trades: any[];
1335
+ }>;
1336
+ determineAmountToBuy(payload: {
1337
+ orders: any[];
1338
+ kind: "long" | "short";
1339
+ refresh?: boolean;
1340
+ decimal_places?: string;
1341
+ price_places?: string;
1342
+ symbol: string;
1343
+ cancel?: boolean;
1344
+ place?: boolean;
1345
+ }): Promise<any[]>;
1346
+ placeSharedOrder(action: "place_limit_orders" | "place_stop_orders" | "place_tp_orders", payload: {
1347
+ symbol: string;
616
1348
  entry: number;
617
1349
  stop: number;
618
- avg_size: any;
619
- avg_entry: any;
620
1350
  risk_reward: number;
621
- neg_pnl: any;
622
1351
  risk: number;
623
- }>;
624
- generateConfig(payload: {
625
- account: ExchangeType;
1352
+ place?: boolean;
1353
+ update_db?: boolean;
1354
+ raw?: boolean;
1355
+ use_current?: boolean;
1356
+ }): Promise<any>;
1357
+ getOrCreatePositionConfig(payload: {
626
1358
  symbol: string;
627
1359
  kind: "long" | "short";
628
- update_orders?: boolean;
629
- place_orders?: boolean;
630
- }): Promise<any>;
631
- updateReduceRatio(payload: {
632
- account: ExchangeType;
1360
+ risk?: number;
1361
+ risk_reward?: number;
1362
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
1363
+ getPositionConfig(payload: {
1364
+ symbol: string;
1365
+ kind: "long" | "short";
1366
+ params?: {
1367
+ entry?: number;
1368
+ stop?: number;
1369
+ risk_reward?: number;
1370
+ risk?: number;
1371
+ profit_percent?: number;
1372
+ place_tp?: boolean;
1373
+ profit?: number;
1374
+ };
1375
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
1376
+ getCurrentPrice(symbol: string): Promise<any>;
1377
+ getAccountStrategy(payload: {
1378
+ symbol: string;
1379
+ }): Promise<AccountStrategy>;
1380
+ buildReduceConfig(payload: {
633
1381
  symbol: string;
1382
+ kind?: "long" | "short";
1383
+ as_dict?: boolean;
1384
+ target_pnl?: number;
1385
+ trigger?: {
1386
+ long: boolean;
1387
+ short: boolean;
1388
+ };
1389
+ use_full?: boolean;
634
1390
  }): Promise<{
635
- long_position: any;
636
- short_position: any;
637
- long_db_position: any;
638
- short_db_position: any;
639
- balance: any;
1391
+ trigger_short: boolean;
1392
+ trigger_long: boolean;
1393
+ symbol: string;
1394
+ short_minimum_pnl: number;
1395
+ long_minimum_pnl: number;
1396
+ short_profit: any;
1397
+ long_profit: any;
1398
+ owner: string;
1399
+ exchange: string;
1400
+ not_reduce: boolean;
1401
+ reduce_ratio_long: any;
1402
+ reduce_ratio_short: any;
1403
+ use_full_long: any;
1404
+ use_full_short: any;
1405
+ } | {
1406
+ long: {
1407
+ minimum_pnl: number;
1408
+ max_size: number;
1409
+ profit: any;
1410
+ increase: boolean;
1411
+ not_reduce: boolean;
1412
+ ratio: any;
1413
+ use_full: boolean;
1414
+ sell_ratio: any;
1415
+ };
1416
+ short: {
1417
+ minimum_pnl: number;
1418
+ max_size: number;
1419
+ profit: any;
1420
+ increase: boolean;
1421
+ not_reduce: boolean;
1422
+ ratio: any;
1423
+ use_full: boolean;
1424
+ sell_ratio: any;
1425
+ };
1426
+ trigger: {
1427
+ long: boolean;
1428
+ short: boolean;
1429
+ };
640
1430
  }>;
641
- extrapolateShortConfig(payload: {
642
- account: ExchangeType;
1431
+ getOriginalPlannedStop(payload: {
1432
+ symbol: string;
643
1433
  kind: "long" | "short";
1434
+ }): Promise<any>;
1435
+ syncReduceClosePosition(payload?: {
644
1436
  symbol: string;
645
- risk_reward?: number;
646
- }): Promise<PositionsView | {
647
- place_stop: boolean;
648
- profit_percent: number;
1437
+ kind?: "long" | "short";
1438
+ trigger?: boolean;
1439
+ }): Promise<any>;
1440
+ reduceMajorPositionEntry(payload: {
1441
+ symbol: string;
1442
+ long: any;
1443
+ short: any;
1444
+ trigger: {
1445
+ long: boolean;
1446
+ short: boolean;
1447
+ };
1448
+ }): Promise<any>;
1449
+ placeProfitAndStop(payload: {
1450
+ symbol: string;
1451
+ trigger?: boolean;
1452
+ refresh?: boolean;
1453
+ kind?: "long" | "short";
1454
+ target_pnl?: number;
1455
+ }): Promise<any>;
1456
+ reEnterPositionOnEmpty(symbol: string): Promise<void>;
1457
+ generate_config_params(payload: {
649
1458
  entry: number;
650
1459
  stop: number;
651
- avg_size: any;
652
- avg_entry: any;
653
1460
  risk_reward: number;
654
- neg_pnl: any;
655
1461
  risk: number;
656
- }>;
1462
+ symbol: string;
1463
+ with_trades?: boolean;
1464
+ }): Promise<any>;
1465
+ build_short_order(payload: {
1466
+ symbol: string;
1467
+ kind: "long" | "short";
1468
+ }): Promise<any>;
1469
+ extrapolateShortConfig(payload: {
1470
+ kind: "long" | "short";
1471
+ symbol: string;
1472
+ risk_reward?: number;
1473
+ risk?: number;
1474
+ }): Promise<any>;
1475
+ placeMarketOrder(payload: {
1476
+ symbol: string;
1477
+ kind: "long" | "short";
1478
+ quantity: number;
1479
+ }): Promise<void>;
1480
+ placeSingleOrder(payload: {
1481
+ symbol: string;
1482
+ kind: "long" | "short";
1483
+ }): Promise<string>;
1484
+ triggerTradeFromConfig(payload: {
1485
+ symbol: string;
1486
+ kind: "long" | "short";
1487
+ place?: boolean;
1488
+ raw?: boolean;
1489
+ tp?: boolean;
1490
+ stop?: boolean;
1491
+ use_current?: boolean;
1492
+ ignore_config?: boolean;
1493
+ }): Promise<any>;
657
1494
  verifyStopLoss(payload: {
658
- account: ExchangeType;
659
1495
  symbol: string;
660
1496
  kind: "long" | "short";
661
1497
  revert?: boolean;
662
- }): Promise<import("pocketbase").RecordModel[]>;
663
- updateTopMovers(payload?: {
664
- new_markets: {
665
- symbol: string;
666
- percent: number;
667
- }[];
668
- totalRisk: number;
1498
+ }): Promise<void | Order[]>;
1499
+ windDownSymbol(payload: {
1500
+ symbol: string;
1501
+ risk_reward?: number;
1502
+ risk?: number;
1503
+ }): Promise<void>;
1504
+ updateTargetPnl(payload: {
1505
+ symbol: string;
1506
+ kind: "long" | "short";
1507
+ }): Promise<number>;
1508
+ placeOppositeTradeAction(payload: {
1509
+ symbol: string;
1510
+ kind: "long" | "short";
1511
+ data: {
1512
+ avg: {
1513
+ quantity: number;
1514
+ price: number;
1515
+ };
1516
+ entry: number;
1517
+ stop: number;
1518
+ risk_per_trade: number;
1519
+ profit_percent: number;
1520
+ risk_reward: number;
1521
+ };
1522
+ }): Promise<void>;
1523
+ buildOppositeTrades(payload: {
1524
+ symbol: string;
1525
+ kind: "long" | "short";
1526
+ place?: boolean;
1527
+ place_symbol?: string;
669
1528
  }): Promise<{
1529
+ avg: {
1530
+ entry: number;
1531
+ price: number;
1532
+ quantity: number;
1533
+ };
1534
+ loss: number;
1535
+ profit_percent: number;
1536
+ fee: number;
1537
+ risk_per_trade: number;
1538
+ risk_reward: number;
1539
+ symbol?: string;
1540
+ focus: number;
1541
+ budget: number;
1542
+ support: number;
1543
+ resistance: number;
1544
+ percent_change: number;
1545
+ tradeSplit?: number;
1546
+ take_profit?: number;
1547
+ kind: "long" | "short";
1548
+ entry: number;
1549
+ stop: number;
1550
+ min_size: number;
1551
+ price_places?: string;
1552
+ strategy?: "quantity" | "entry";
1553
+ as_array?: boolean;
1554
+ decimal_places?: string;
1555
+ min_profit?: number;
1556
+ raw?: boolean;
1557
+ gap?: number;
1558
+ rr?: number;
1559
+ max_size?: number;
1560
+ }>;
1561
+ runSimulation(payload: {
1562
+ symbol: string;
1563
+ kind: "long" | "short";
1564
+ iterations?: number;
1565
+ raw?: boolean;
1566
+ }): Promise<Strategy | {
1567
+ last_entry: any;
1568
+ first_entry: any;
1569
+ threshold: any;
1570
+ risk: number;
1571
+ risk_reward: number;
1572
+ spread: number;
1573
+ gap_loss: number;
1574
+ net_profit: number;
1575
+ long: {
1576
+ avg_entry: number;
1577
+ avg_size: number;
1578
+ loss: number;
1579
+ stop: number;
1580
+ stop_quantity: number;
1581
+ re_entry_quantity: number;
1582
+ initial_pnl: number;
1583
+ tp: number;
1584
+ incurred_loss: number;
1585
+ pnl: number;
1586
+ remaining_quantity: number;
1587
+ };
1588
+ short: {
1589
+ avg_entry: number;
1590
+ avg_size: number;
1591
+ loss: number;
1592
+ stop: number;
1593
+ stop_quantity: number;
1594
+ re_entry_quantity: number;
1595
+ initial_pnl: number;
1596
+ tp: number;
1597
+ incurred_loss: number;
1598
+ pnl: number;
1599
+ remaining_quantity: number;
1600
+ };
1601
+ }[]>;
1602
+ getCurrentRun(payload: {
1603
+ symbol: string;
1604
+ kind?: "long" | "short";
1605
+ pnl?: number;
1606
+ }): Promise<true | import("pocketbase").RecordModel>;
1607
+ recomputeSymbolConfig(payload: {
1608
+ symbol: string;
1609
+ refresh?: boolean;
1610
+ }): Promise<SymbolConfig>;
1611
+ /**
1612
+ * This function builds a config for a symbol
1613
+ * @param payload
1614
+ * @returns
1615
+ */
1616
+ buildConfigForSymbol(payload: {
1617
+ symbol: string;
1618
+ risk: number;
1619
+ kind?: "long" | "short";
1620
+ risk_reward?: number;
1621
+ as_config?: boolean;
1622
+ with_trades?: boolean;
1623
+ }): Promise<any>;
1624
+ triggerBullishMarket(payload: {
1625
+ symbol: string;
1626
+ profit_percent?: number;
1627
+ risk_reward?: number;
1628
+ }): Promise<any>;
1629
+ updateAllActiveSymbols(payload: {
1630
+ interval?: number;
1631
+ }): Promise<void>;
1632
+ updateAllPositionsWithNoConfig(payload: {
1633
+ kind: "long" | "short";
1634
+ }): Promise<void>;
1635
+ getSymbolsForPositions(): Promise<any[]>;
1636
+ getNonEssentialSymbols(): Promise<any[]>;
1637
+ _terminatePositions(payload: {
1638
+ symbol: string;
1639
+ }): Promise<void>;
1640
+ getOrders(payload: {
1641
+ symbol: string;
1642
+ kind: "long" | "short";
1643
+ type: "limit" | "stop" | "tp";
1644
+ }): Promise<Order[]>;
1645
+ syncPositionConfigs(payload: {
1646
+ symbol: string;
1647
+ kind: "long" | "short";
1648
+ refresh?: boolean;
1649
+ }): Promise<void>;
1650
+ terminatePositions(payload: {
1651
+ symbol: string;
1652
+ }): Promise<void>;
1653
+ fetchAndUpdateTopMovers(): Promise<{
670
1654
  updated_bullish: BullishMarket[];
671
1655
  moved_to_winding: WindingDownMarket[];
672
1656
  }>;
1657
+ computeTargetPnl(payload: {
1658
+ symbol: string;
1659
+ kind: "long" | "short";
1660
+ }): Promise<number>;
1661
+ placeTrade(payload: {
1662
+ symbol: string;
1663
+ kind: "long" | "short";
1664
+ place?: boolean;
1665
+ limit?: boolean;
1666
+ tp?: boolean;
1667
+ stop?: boolean;
1668
+ raw?: boolean;
1669
+ cancel?: boolean;
1670
+ ignore_config?: boolean;
1671
+ target_pnl?: number;
1672
+ }): Promise<any>;
1673
+ updateConfigPnl(payload: {
1674
+ symbol: string;
1675
+ kind: "long" | "short";
1676
+ }): Promise<void>;
1677
+ profitWithinGapStrategy(payload: {
1678
+ symbol: string;
1679
+ kind: "long" | "short";
1680
+ risk: number;
1681
+ resistance: number;
1682
+ support: number;
1683
+ reward_factor?: number;
1684
+ }): Promise<{
1685
+ reverse_config: any;
1686
+ reverse_action: {
1687
+ avg: {
1688
+ entry: number;
1689
+ price: number;
1690
+ quantity: number;
1691
+ };
1692
+ loss: number;
1693
+ profit_percent: number;
1694
+ fee: number;
1695
+ risk_per_trade: number;
1696
+ risk_reward: number;
1697
+ symbol?: string;
1698
+ focus: number;
1699
+ budget: number;
1700
+ support: number;
1701
+ resistance: number;
1702
+ percent_change: number;
1703
+ tradeSplit?: number;
1704
+ take_profit?: number;
1705
+ kind: "long" | "short";
1706
+ entry: number;
1707
+ stop: number;
1708
+ min_size: number;
1709
+ price_places?: string;
1710
+ strategy?: "quantity" | "entry";
1711
+ as_array?: boolean;
1712
+ decimal_places?: string;
1713
+ min_profit?: number;
1714
+ raw?: boolean;
1715
+ gap?: number;
1716
+ rr?: number;
1717
+ max_size?: number;
1718
+ };
1719
+ reverse_orders_to_buy: any;
1720
+ positions: {
1721
+ long: PositionsView;
1722
+ short: PositionsView;
1723
+ };
1724
+ orders_to_place: any;
1725
+ config_details: {
1726
+ app_config: {
1727
+ fee: number;
1728
+ risk_per_trade: number;
1729
+ risk_reward: number;
1730
+ symbol?: string;
1731
+ focus: number;
1732
+ budget: number;
1733
+ support: number;
1734
+ resistance: number;
1735
+ percent_change: number;
1736
+ tradeSplit?: number;
1737
+ take_profit?: number;
1738
+ kind: "long" | "short";
1739
+ entry: number;
1740
+ stop: number;
1741
+ min_size: number;
1742
+ price_places?: string;
1743
+ strategy?: "quantity" | "entry";
1744
+ as_array?: boolean;
1745
+ decimal_places?: string;
1746
+ min_profit?: number;
1747
+ raw?: boolean;
1748
+ gap?: number;
1749
+ rr?: number;
1750
+ max_size?: number;
1751
+ };
1752
+ last_value: any;
1753
+ config: {
1754
+ entry: number;
1755
+ stop: number;
1756
+ risk: number;
1757
+ risk_reward: number | {
1758
+ result: any[];
1759
+ value: number;
1760
+ total: number;
1761
+ risk_per_trade: number;
1762
+ max: number;
1763
+ min: number;
1764
+ neg_pnl: any;
1765
+ entry: any;
1766
+ };
1767
+ profit_percent: number;
1768
+ };
1769
+ pnl: number;
1770
+ };
1771
+ }>;
1772
+ }
1773
+ declare function getExchangeAccount(payload: {
1774
+ account: ExchangeType;
1775
+ app_db: AppDatabase;
1776
+ getCredentials: (account: string, exchange: string) => {
1777
+ api_key: string;
1778
+ api_secret: string;
1779
+ email: string;
1780
+ };
1781
+ proxyOptions?: {
1782
+ proxy?: any;
1783
+ ignore_proxy?: boolean;
1784
+ };
1785
+ canWithdraw?: boolean;
1786
+ }): Promise<ExchangeAccount$1>;
1787
+ declare class App {
1788
+ app_db: AppDatabase;
1789
+ proxyOptions?: {
1790
+ proxy?: any;
1791
+ ignore_proxy?: boolean;
1792
+ canWithdraw?: boolean;
1793
+ };
1794
+ private getCredentials;
1795
+ constructor(app_db: AppDatabase, getCredentials: (account: string, exchange: string) => {
1796
+ api_key: string;
1797
+ api_secret: string;
1798
+ email: string;
1799
+ }, proxyOptions?: {
1800
+ proxy?: any;
1801
+ ignore_proxy?: boolean;
1802
+ canWithdraw?: boolean;
1803
+ });
1804
+ getExchangeAccount(account: ExchangeType): Promise<ExchangeAccount$1>;
1805
+ syncAccount(payload: {
1806
+ account: ExchangeType;
1807
+ symbol: string;
1808
+ kind?: "long" | "short";
1809
+ update?: boolean;
1810
+ as_view?: boolean;
1811
+ }): Promise<PositionsView | (PositionsView & {
1812
+ expand?: {
1813
+ config: ScheduledTrade;
1814
+ account: ExchangeAccount;
1815
+ };
1816
+ })[]>;
1817
+ syncOrders(payload: {
1818
+ account: ExchangeType;
1819
+ symbol: string;
1820
+ kind: "long" | "short";
1821
+ }): Promise<any>;
1822
+ cancelOrders(payload: {
1823
+ account: ExchangeType;
1824
+ symbol: string;
1825
+ kind: "long" | "short";
1826
+ price?: number;
1827
+ all?: boolean;
1828
+ stop?: boolean;
1829
+ }): Promise<void | {
1830
+ success: boolean;
1831
+ message: string;
1832
+ exchange_result?: undefined;
1833
+ error?: undefined;
1834
+ } | {
1835
+ success: boolean;
1836
+ exchange_result: any;
1837
+ message?: undefined;
1838
+ error?: undefined;
1839
+ } | {
1840
+ success: boolean;
1841
+ error: any;
1842
+ message?: undefined;
1843
+ exchange_result?: undefined;
1844
+ }>;
673
1845
  getWindingDownMarkets(): Promise<WindingDownMarket[]>;
674
1846
  updateSymbolConfigs(payload: {
675
1847
  configs: {
@@ -681,10 +1853,144 @@ declare class App {
681
1853
  price_places: string;
682
1854
  decimal_places: string;
683
1855
  }[];
684
- }): Promise<{
1856
+ }): Promise<SymbolConfig[] | {
685
1857
  updated: number;
686
1858
  created: number;
687
- } | SymbolConfig[]>;
1859
+ }>;
1860
+ updateAllAccountWithSymbols(with_positions?: boolean): Promise<void>;
1861
+ windDownSymbol(payload: {
1862
+ symbol: string;
1863
+ risk?: number;
1864
+ }): Promise<boolean>;
1865
+ getNonEssentialSymbols(): Promise<Set<any>>;
1866
+ refreshAllPositionsWithSymbol(payload: {
1867
+ symbol: string;
1868
+ }): Promise<void>;
1869
+ autoFollowPositions(): Promise<void>;
1870
+ getMoverExchangeInstances(): Promise<ExchangeAccount[]>;
1871
+ updateTpOnAllMarkets(): Promise<void>;
1872
+ triggerMoverTask(payload: {
1873
+ callback: (params: {
1874
+ symbol: string;
1875
+ account: ExchangeType;
1876
+ }) => Promise<any>;
1877
+ removeCallback?: (params: {
1878
+ symbol: string;
1879
+ account: ExchangeType;
1880
+ }) => Promise<any>;
1881
+ }): Promise<void>;
1882
+ placeTrade(payload: {
1883
+ account: ExchangeType;
1884
+ symbol: string;
1885
+ kind: "long" | "short";
1886
+ place?: boolean;
1887
+ tp?: boolean;
1888
+ cancel?: boolean;
1889
+ raw?: boolean;
1890
+ }): Promise<any>;
1891
+ runDbStrategyAccounts(callback: (params: {
1892
+ symbol: string;
1893
+ account: ExchangeType;
1894
+ risk: number;
1895
+ resistance: number;
1896
+ support: number;
1897
+ }) => Promise<any>): Promise<void>;
1898
+ profitWithinGapStrategy(payload: {
1899
+ account: ExchangeType;
1900
+ symbol: string;
1901
+ kind: "long" | "short";
1902
+ risk: number;
1903
+ resistance: number;
1904
+ support: number;
1905
+ reward_factor?: number;
1906
+ }): Promise<{
1907
+ reverse_config: any;
1908
+ reverse_action: {
1909
+ avg: {
1910
+ entry: number;
1911
+ price: number;
1912
+ quantity: number;
1913
+ };
1914
+ loss: number;
1915
+ profit_percent: number;
1916
+ fee: number;
1917
+ risk_per_trade: number;
1918
+ risk_reward: number;
1919
+ symbol?: string;
1920
+ focus: number;
1921
+ budget: number;
1922
+ support: number;
1923
+ resistance: number;
1924
+ percent_change: number;
1925
+ tradeSplit?: number;
1926
+ take_profit?: number;
1927
+ kind: "long" | "short";
1928
+ entry: number;
1929
+ stop: number;
1930
+ min_size: number;
1931
+ price_places?: string;
1932
+ strategy?: "quantity" | "entry";
1933
+ as_array?: boolean;
1934
+ decimal_places?: string;
1935
+ min_profit?: number;
1936
+ raw?: boolean;
1937
+ gap?: number;
1938
+ rr?: number;
1939
+ max_size?: number;
1940
+ };
1941
+ reverse_orders_to_buy: any;
1942
+ positions: {
1943
+ long: PositionsView;
1944
+ short: PositionsView;
1945
+ };
1946
+ orders_to_place: any;
1947
+ config_details: {
1948
+ app_config: {
1949
+ fee: number;
1950
+ risk_per_trade: number;
1951
+ risk_reward: number;
1952
+ symbol?: string;
1953
+ focus: number;
1954
+ budget: number;
1955
+ support: number;
1956
+ resistance: number;
1957
+ percent_change: number;
1958
+ tradeSplit?: number;
1959
+ take_profit?: number;
1960
+ kind: "long" | "short";
1961
+ entry: number;
1962
+ stop: number;
1963
+ min_size: number;
1964
+ price_places?: string;
1965
+ strategy?: "quantity" | "entry";
1966
+ as_array?: boolean;
1967
+ decimal_places?: string;
1968
+ min_profit?: number;
1969
+ raw?: boolean;
1970
+ gap?: number;
1971
+ rr?: number;
1972
+ max_size?: number;
1973
+ };
1974
+ last_value: any;
1975
+ config: {
1976
+ entry: number;
1977
+ stop: number;
1978
+ risk: number;
1979
+ risk_reward: number | {
1980
+ result: any[];
1981
+ value: number;
1982
+ total: number;
1983
+ risk_per_trade: number;
1984
+ max: number;
1985
+ min: number;
1986
+ neg_pnl: any;
1987
+ entry: any;
1988
+ };
1989
+ profit_percent: number;
1990
+ };
1991
+ pnl: number;
1992
+ };
1993
+ }>;
688
1994
  }
689
1995
  export declare function initApp(payload: {
690
1996
  db: {
@@ -692,14 +1998,44 @@ export declare function initApp(payload: {
692
1998
  email: string;
693
1999
  password: string;
694
2000
  };
695
- getCredentials: (account: string, exchange: string) => (account: string, exchange: string) => Promise<{
2001
+ password?: string;
2002
+ getCredentials: (account: string, exchange: string) => {
696
2003
  api_key: string;
697
2004
  api_secret: string;
698
- }>;
2005
+ email: string;
2006
+ };
2007
+ proxy?: any;
2008
+ ignore_proxy?: boolean;
2009
+ canWithdraw?: boolean;
2010
+ triggerToken?: string;
699
2011
  }): Promise<App>;
2012
+ declare function getCredentials(account: string, exchange: string): {
2013
+ api_key: string;
2014
+ api_secret: string;
2015
+ email: string;
2016
+ };
2017
+ export declare function initialize(payload: {
2018
+ password?: string;
2019
+ proxy?: any;
2020
+ ignore_proxy?: boolean;
2021
+ canWithdraw?: boolean;
2022
+ }): Promise<App>;
2023
+
2024
+ declare namespace database {
2025
+ export { AppDatabase, ExchangeType, initPocketBaseClient };
2026
+ }
2027
+ declare namespace exchange_account {
2028
+ export { ExchangeAccount$1 as ExchangeAccount, getExchangeAccount };
2029
+ }
2030
+ declare namespace app {
2031
+ export { App, getCredentials, initApp, initialize };
2032
+ }
700
2033
 
701
2034
  export {
702
2035
  ExchangeAccount$1 as ExchangeAccount,
2036
+ app,
2037
+ database,
2038
+ exchange_account,
703
2039
  };
704
2040
 
705
2041
  export {};