@gbozee/ultimate 0.0.2-19 → 0.0.2-191

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,296 @@
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 interface GetEntriesParams {
9
+ kind: "long" | "short";
10
+ distribution: "arithmetic" | "geometric" | "normal" | "exponential" | "inverse-exponential";
11
+ margin_range: [
12
+ number,
13
+ number
14
+ ];
15
+ risk_reward: number;
16
+ price_places?: string;
17
+ distribution_params?: {
18
+ curveFactor?: number;
19
+ stdDevFactor?: number;
20
+ lambda?: number;
21
+ };
22
+ }
23
+ export type RecordModel = PocketBaseRecordModel;
24
+ export interface BaseSystemFields {
25
+ id: string;
26
+ created: string;
27
+ updated: string;
28
+ }
29
+ export interface ExchangeAccount extends BaseSystemFields {
30
+ exchange: "binance" | "bybit";
31
+ owner: string;
32
+ email?: string;
33
+ user?: string;
34
+ usdt?: number;
35
+ usdc?: number;
36
+ proxy?: string;
37
+ bullish?: boolean;
38
+ bearish?: boolean;
39
+ movePercent?: number;
40
+ totalRisk?: number;
41
+ max_non_essential?: number;
42
+ profit_percent?: number;
43
+ risk_reward?: number;
44
+ exclude_coins?: {
45
+ bullish?: string[];
46
+ };
47
+ include_delisted?: boolean;
48
+ }
49
+ export interface Order extends BaseSystemFields {
50
+ symbol: string;
51
+ account: string;
52
+ kind: "long" | "short";
53
+ price: number;
54
+ quantity: number;
55
+ side: "sell" | "buy";
56
+ stop: number;
57
+ order_id: string;
58
+ }
59
+ export interface SymbolConfig extends BaseSystemFields {
60
+ symbol: string;
61
+ support?: number;
62
+ resistance?: number;
63
+ stop_percent?: number;
64
+ price_places?: string;
65
+ decimal_places?: string;
66
+ min_size?: number;
67
+ weight?: number;
68
+ leverage?: number;
69
+ candle_count?: number;
70
+ interval?: any;
71
+ fee_percent?: number;
72
+ }
73
+ export interface ScheduledTrade extends BaseSystemFields {
74
+ symbol: string;
75
+ account: string;
76
+ profit?: number;
77
+ risk?: number;
78
+ entry?: number;
79
+ stop?: number;
80
+ risk_reward?: number;
81
+ profit_percent?: number;
82
+ place_tp?: boolean;
83
+ kind?: "long" | "short";
84
+ follow?: boolean | 1 | 0;
85
+ reduce_ratio?: number;
86
+ sell_ratio?: number;
87
+ threshold_qty?: number;
88
+ pause_tp?: boolean;
89
+ stop_percent?: number;
90
+ kelly?: {
91
+ use_kelly?: boolean;
92
+ kelly_confidence_factor?: number;
93
+ kelly_minimum_risk?: number;
94
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
95
+ };
96
+ distribution?: GetEntriesParams["distribution"];
97
+ }
98
+ export interface AccountStrategy extends BaseSystemFields {
99
+ account: string;
100
+ symbol: string;
101
+ risk?: number;
102
+ reward_factor?: number;
103
+ kind?: "long" | "short";
104
+ support?: number;
105
+ resistance?: number;
106
+ running?: boolean;
107
+ max_reward_factor?: number;
108
+ follow?: boolean;
109
+ risk_reward?: number;
110
+ dynamic?: boolean;
111
+ }
112
+ interface Proxy$1 extends BaseSystemFields {
113
+ ip_address?: string;
114
+ type?: "http" | "socks5";
115
+ }
116
+ export interface TradeBlockTracking extends BaseSystemFields {
117
+ account?: string;
118
+ symbol?: string;
119
+ running?: boolean;
120
+ }
121
+ export interface PositionsView {
122
+ id: string;
123
+ symbol?: any;
124
+ entry?: any;
125
+ quantity?: any;
126
+ take_profit?: any;
127
+ account?: any;
128
+ kind?: any;
129
+ target_pnl?: number;
130
+ liquidation?: number;
131
+ avg_price?: number;
132
+ avg_qty?: number;
133
+ next_order?: number;
134
+ last_order?: number;
135
+ config?: any;
136
+ stop_loss?: {
137
+ price: number;
138
+ quantity: number;
139
+ };
140
+ stop_pnl?: any;
141
+ leverage?: any;
142
+ avg_liquidation?: any;
143
+ balance?: any;
144
+ reduce_ratio?: number;
145
+ sell_ratio?: number;
146
+ threshold_qty?: number;
147
+ follow?: boolean | 1 | 0;
148
+ current_price?: number;
149
+ usd_balance?: number;
150
+ tp?: {
151
+ price: number;
152
+ quantity: number;
153
+ };
154
+ next_risk?: number;
155
+ proxy?: string;
156
+ expand?: {
157
+ p_account?: ExchangeAccount;
158
+ b_config?: ScheduledTrade;
159
+ proxy?: Proxy$1;
160
+ account_strategy?: AccountStrategy;
161
+ compound_instance?: CompoundInstance;
162
+ support?: SupportTable;
163
+ symbol_config: SymbolConfig;
164
+ resistance?: SupportTable;
165
+ anchor?: Omit<PositionsView, "expand">;
166
+ };
167
+ pnl?: number;
168
+ support_price?: number;
169
+ }
170
+ export interface BullishMarket extends RecordModel {
171
+ id: string;
172
+ symbol: string;
173
+ risk: number;
174
+ }
175
+ export interface WindingDownMarket extends RecordModel {
176
+ id: string;
177
+ symbol: string;
178
+ risk_reward: number;
179
+ }
180
+ export interface Compounder extends BaseSystemFields {
181
+ risk?: number;
182
+ profit_percent?: number;
183
+ owner?: string;
184
+ completed?: boolean;
185
+ start_balance?: number;
186
+ starting_risk?: number;
187
+ fee_rate?: number;
188
+ }
189
+ export interface CompoundInstance extends BaseSystemFields {
190
+ ref?: string;
191
+ position?: string;
192
+ risk?: number;
193
+ hedged?: boolean;
194
+ loss?: number;
195
+ expand?: {
196
+ ref?: Compounder;
197
+ };
198
+ }
199
+ export interface SupportTable extends BaseSystemFields {
200
+ symbol?: string;
201
+ price?: number;
202
+ counter?: number;
203
+ last_updated?: string;
204
+ kind?: "long" | "short";
205
+ }
206
+ export interface BotInstance extends BaseSystemFields {
207
+ asset: string;
208
+ main_account?: string;
209
+ secondary_account?: string;
210
+ main_symbol: string;
211
+ secondary_symbol?: string;
212
+ direction?: "long" | "short";
213
+ budget?: number;
214
+ settings?: Record<string, any>;
215
+ user?: string;
216
+ }
217
+ export interface BotState extends BaseSystemFields {
218
+ bot: string;
219
+ running?: boolean;
220
+ status?: "main-trading" | "hedge-mode";
221
+ spot_quantity?: number;
222
+ exchange_details?: Record<string, any>;
223
+ completed?: boolean;
224
+ }
225
+ export interface BotOrderHistory extends BaseSystemFields {
226
+ field: string;
227
+ symbol: string;
228
+ pnl?: number;
229
+ kind?: "long" | "short";
230
+ type?: "future" | "spot";
231
+ }
232
+ export interface BotPositionData {
233
+ entry: number;
234
+ quantity: number;
235
+ tp: {
236
+ price: number;
237
+ quantity: number;
238
+ pnl: number;
239
+ };
240
+ current_price: number;
241
+ balance: number;
242
+ kind: "long" | "short";
243
+ next_order: number;
244
+ last_order: number;
245
+ avg: {
246
+ price: number;
247
+ quantity: number;
248
+ };
249
+ sl: {
250
+ price: number;
251
+ quantity: number;
252
+ pnl: number;
253
+ };
254
+ }
255
+ export interface BotView extends RecordModel {
256
+ id: string;
257
+ direction?: "long" | "short";
258
+ budget?: number;
259
+ main_symbol?: string;
260
+ main_long_position?: BotPositionData;
261
+ main_short_position?: BotPositionData;
262
+ secondary_symbol?: string;
263
+ secondary_long_position?: BotPositionData;
264
+ secondary_short_position?: BotPositionData;
265
+ main_account?: string;
266
+ secondary_account?: string;
267
+ settings?: Record<string, any>;
268
+ main_long_strategy?: string;
269
+ main_short_strategy?: string;
270
+ secondary_long_strategy?: string;
271
+ secondary_short_strategy?: string;
272
+ }
273
+ export type GlobalConfig = {
274
+ profit_percent: number;
275
+ symbol: string;
276
+ profit: number;
277
+ risk: number;
278
+ stop_percent: number;
279
+ kind: "long" | "short";
280
+ reduce_percent: number;
281
+ support: number;
282
+ resistance: number;
283
+ price_places: string;
284
+ decimal_places: string;
285
+ min_size: number;
286
+ accounts: {
287
+ owner: string;
288
+ exchange?: string;
289
+ }[];
290
+ risk_reward: number;
291
+ reverse_factor: number;
292
+ leverage?: number;
293
+ max_quantity?: number;
294
+ };
8
295
  interface Position$1 {
9
296
  id: number;
10
297
  kind: "long" | "short";
@@ -20,6 +307,7 @@ interface Position$1 {
20
307
  target_pnl?: number;
21
308
  reduce_ratio?: number;
22
309
  use_full?: boolean;
310
+ liquidation?: number;
23
311
  }
24
312
  export interface Account {
25
313
  id: number | string;
@@ -59,8 +347,69 @@ export interface Account {
59
347
  short: any;
60
348
  };
61
349
  }
62
- export interface BaseExchange {
350
+ interface Order$1 {
351
+ order_id?: string;
352
+ symbol?: string;
353
+ price: number;
354
+ quantity: number;
355
+ kind: "long" | "short";
356
+ side: "buy" | "sell";
357
+ stop: number;
358
+ triggerPrice?: number;
359
+ }
360
+ export interface CandlestickAnalysisResult {
361
+ candlesticks: {
362
+ [key: string]: any[];
363
+ };
364
+ resistance: {
365
+ [key: string]: number;
366
+ };
367
+ support: {
368
+ [key: string]: number;
369
+ };
370
+ current_price: number;
371
+ minimum_weekly: number;
372
+ }
373
+ declare abstract class BaseExchange {
63
374
  client: any;
375
+ name: string;
376
+ getCredentials: (payload: {
377
+ account: string;
378
+ }) => Promise<{
379
+ api_key: string;
380
+ api_secret: string;
381
+ email: string;
382
+ }>;
383
+ proxyAgent?: any;
384
+ constructor(client: any);
385
+ protected abstract getPositionInfo(symbol: string): Promise<any>;
386
+ abstract cancelAllOrders(symbol: string, payload: {
387
+ type?: "limit" | "stop" | "tp";
388
+ side?: "buy" | "sell";
389
+ kind?: "long" | "short";
390
+ }): Promise<any>;
391
+ protected abstract getCurrentPrice(symbol: string): Promise<any>;
392
+ protected abstract getExchangeInfo(options: {
393
+ price_places?: string;
394
+ decimal_places?: string;
395
+ account: {
396
+ owner: string;
397
+ exchange: string;
398
+ };
399
+ symbol: string;
400
+ }): Promise<any>;
401
+ protected abstract _createLimitPurchaseOrders(payload: {
402
+ symbol: string;
403
+ orders: any[];
404
+ price_places?: string;
405
+ decimal_places?: string;
406
+ }): Promise<any>;
407
+ rawCreateLimitPurchaseOrders(payload: {
408
+ symbol: string;
409
+ orders: Order$1[];
410
+ price_places?: string;
411
+ decimal_places?: string;
412
+ }): Promise<any>;
64
413
  placeStopOrders(payload: {
65
414
  symbol: string;
66
415
  quantity: number;
@@ -68,36 +417,70 @@ export interface BaseExchange {
68
417
  stop: number;
69
418
  price_places?: string;
70
419
  decimal_places?: string;
420
+ hedge?: boolean;
71
421
  place?: boolean;
72
422
  }): Promise<any>;
73
423
  bulkPlaceLimitOrders(payload: {
74
- orders: any[];
424
+ orders: Order$1[];
75
425
  kind: "long" | "short";
76
426
  decimal_places?: string;
77
427
  price_places?: string;
78
428
  symbol: string;
79
429
  place?: boolean;
80
- }): Promise<any>;
430
+ }): Promise<any[]>;
81
431
  get_current_price(symbol: string): Promise<any>;
82
- analyzeCharts(payload: {
432
+ abstract analyzeCharts(payload: {
83
433
  symbol: string;
84
434
  chartType: any;
85
- count: number;
435
+ limit: number;
86
436
  raw?: boolean;
87
437
  }): Promise<any>;
88
- getExchangeAccountInfo(account: {
89
- owner: string;
90
- exchange: string;
91
- }, symbol: string): Promise<any>;
438
+ getExchangeAccountInfo(options: {
439
+ price_places?: string;
440
+ decimal_places?: string;
441
+ account: {
442
+ owner: string;
443
+ exchange: string;
444
+ };
445
+ symbol: string;
446
+ }): Promise<any>;
447
+ protected abstract _cancelOrders(payload: {
448
+ symbol: string;
449
+ orders: Array<{
450
+ orderId?: any;
451
+ clientOrderId?: any;
452
+ }>;
453
+ }): Promise<any>;
92
454
  cancelOrders(payload: {
93
455
  symbol: string;
94
456
  orders: number[];
95
457
  }): Promise<any>;
458
+ protected abstract _placeTpOrder(payload: {
459
+ symbol: string;
460
+ tp: number;
461
+ kind: "long" | "short";
462
+ cancel?: boolean;
463
+ quantity?: number;
464
+ price_places?: string;
465
+ decimal_places?: string;
466
+ }): Promise<any>;
96
467
  placeTpOrder(payload: {
97
468
  symbol: string;
98
469
  take_profit: number;
99
470
  kind: "long" | "short";
100
471
  cancel?: boolean;
472
+ quantity?: number;
473
+ price_places?: string;
474
+ decimal_places?: string;
475
+ }): Promise<any>;
476
+ protected abstract placeLimitOrders(payload: {
477
+ symbol: string;
478
+ orders: Array<{
479
+ entry: number;
480
+ quantity: number;
481
+ }>;
482
+ kind: "long" | "short";
483
+ cancel?: boolean;
101
484
  price_places?: string;
102
485
  decimal_places?: string;
103
486
  }): Promise<any>;
@@ -109,6 +492,19 @@ export interface BaseExchange {
109
492
  price_places?: string;
110
493
  decimal_places?: string;
111
494
  }): Promise<any>;
495
+ protected abstract _placeStopOrder(payload: {
496
+ symbol: string;
497
+ stop: number;
498
+ quantity: number;
499
+ kind: "long" | "short";
500
+ price_places?: string;
501
+ decimal_places?: string;
502
+ final_stop: number;
503
+ cancel?: boolean;
504
+ is_limit?: boolean;
505
+ current_price: number;
506
+ hedge?: boolean;
507
+ }): Promise<any>;
112
508
  placeStopOrder(payload: {
113
509
  symbol: string;
114
510
  stop: number;
@@ -116,123 +512,147 @@ export interface BaseExchange {
116
512
  kind: "long" | "short";
117
513
  price_places?: string;
118
514
  decimal_places?: string;
515
+ hedge?: boolean;
119
516
  }): Promise<any>;
120
- setLeverage(payload: {
517
+ abstract setLeverage(payload: {
121
518
  symbol: string;
122
519
  leverage: number;
123
520
  }): Promise<any>;
124
- generateConfig(payload: {
521
+ abstract generateConfig(payload: {
125
522
  symbol: string;
523
+ interval?: any;
126
524
  limit?: number;
127
525
  }): Promise<any>;
128
- checkDelistedMovers(payload: {
526
+ abstract checkDelistedMovers(payload: {
129
527
  movePercent: number;
528
+ include_delisted?: boolean;
130
529
  }): Promise<any>;
131
- }
132
- export interface BaseSystemFields {
133
- id: string;
134
- created: string;
135
- updated: string;
136
- }
137
- export interface ExchangeAccount extends BaseSystemFields {
138
- exchange: "binance" | "bybit";
139
- owner: string;
140
- email?: string;
141
- user?: string;
142
- usdt?: number;
143
- usdc?: number;
144
- proxy?: string;
145
- }
146
- export interface SymbolConfig extends BaseSystemFields {
147
- symbol: string;
148
- support?: number;
149
- resistance?: number;
150
- stop_percent?: number;
151
- price_places?: string;
152
- decimal_places?: string;
153
- min_size?: number;
154
- weight?: number;
155
- leverage?: number;
156
- }
157
- export interface ScheduledTrade extends BaseSystemFields {
158
- symbol: string;
159
- account: string;
160
- profit?: number;
161
- risk?: number;
162
- entry?: number;
163
- stop?: number;
164
- risk_reward?: number;
165
- profit_percent?: number;
166
- place_tp?: boolean;
167
- kind?: "long" | "short";
168
- current_price?: number;
169
- }
170
- export interface Strategy extends BaseSystemFields {
171
- name: string;
172
- short_risk_factor?: number;
173
- long_risk_factor?: number;
174
- profit_percent?: number;
175
- cancel_short?: boolean;
176
- cancel_long?: boolean;
177
- recompute_short_config?: boolean;
178
- update_stop_loss?: boolean;
179
- liquidation_as_entry?: boolean;
180
- stop_as_entry?: boolean;
181
- tp_as_stop?: boolean;
182
- entry_as_stop?: boolean;
183
- place_stop?: boolean;
184
- save_config?: boolean;
185
- }
186
- interface Proxy$1 extends BaseSystemFields {
187
- ip_address?: string;
188
- type?: "http" | "socks5";
189
- }
190
- export interface TradeBlockTracking extends BaseSystemFields {
191
- account?: string;
192
- symbol?: string;
193
- running?: boolean;
194
- }
195
- export interface PositionsView {
196
- id: string;
197
- symbol?: any;
198
- entry?: any;
199
- quantity?: any;
200
- take_profit?: any;
201
- account?: any;
202
- kind?: any;
203
- target_pnl?: number;
204
- liquidation?: number;
205
- avg_price?: number;
206
- avg_qty?: number;
207
- next_order?: number;
208
- last_order?: number;
209
- config?: any;
210
- stop_loss?: {
211
- price: number;
530
+ closePosition(payload: {
531
+ symbol: string;
532
+ kind: "long" | "short";
533
+ price_places?: string;
534
+ decimal_places?: string;
535
+ }): Promise<any>;
536
+ protected abstract getAllOpenOrders(): Promise<any>;
537
+ getAllOpenSymbols(): Promise<unknown[]>;
538
+ createLimitPurchaseOrders(payload: {
539
+ orders: any[];
540
+ kind: "long" | "short";
541
+ decimal_places?: string;
542
+ price_places?: string;
543
+ symbol: string;
544
+ }): Promise<any>;
545
+ abstract getDelistedSpotSymbols(): Promise<any>;
546
+ abstract getOpenPositions(): Promise<any>;
547
+ abstract crossAccountTransfer(payload: {
548
+ from: {
549
+ owner: string;
550
+ wallet: string;
551
+ };
552
+ to: {
553
+ owner: string;
554
+ wallet: string;
555
+ };
556
+ asset: string;
557
+ amount: number;
558
+ }): Promise<any>;
559
+ placeMarketOrder(payload: {
560
+ symbol: string;
561
+ kind: "long" | "short";
212
562
  quantity: number;
213
- };
214
- stop_pnl?: any;
215
- leverage?: any;
216
- avg_liquidation?: any;
217
- balance?: any;
218
- }
219
- export interface BullishMarket extends RecordModel {
220
- id: string;
221
- symbol: string;
222
- risk: number;
223
- }
224
- export interface WindingDownMarket extends RecordModel {
225
- id: string;
226
- symbol: string;
227
- risk_reward: number;
563
+ price_places?: string;
564
+ decimal_places?: string;
565
+ close?: boolean;
566
+ }): Promise<any>;
567
+ customStopLoss(payload: {
568
+ price_places: string;
569
+ decimal_places: string;
570
+ symbol: string;
571
+ kind: "long" | "short";
572
+ stop: number;
573
+ quantity: number;
574
+ increase?: boolean;
575
+ place?: boolean;
576
+ increase_ratio?: number;
577
+ }): Promise<any>;
578
+ abstract getOpenOrders(payload: {
579
+ symbol: string;
580
+ }): Promise<any>;
581
+ placeBadStopEntry(payload: {
582
+ symbol: string;
583
+ orders: Order$1[];
584
+ price_places?: string;
585
+ decimal_places?: string;
586
+ }): Promise<any>;
587
+ analyzeCandlesticks(payload: {
588
+ symbol: string;
589
+ }): Promise<CandlestickAnalysisResult>;
590
+ setAccountDetails(payload: {
591
+ getCredentials: (payload: {
592
+ account: string;
593
+ }) => Promise<{
594
+ api_key: string;
595
+ api_secret: string;
596
+ email: string;
597
+ }>;
598
+ proxyAgent?: any;
599
+ }): void;
228
600
  }
601
+ declare function encryptObject(obj: any, password: string): string;
602
+ declare function decryptObject(encryptedString: string, password: string): any;
603
+ declare function initPocketBaseClient(proxy_credentials: {
604
+ host: string;
605
+ email: string;
606
+ password: string;
607
+ auto_cancellation?: boolean;
608
+ }): Promise<PocketBase>;
229
609
  export type ExchangeType = {
230
610
  owner: string;
231
611
  exchange: string;
232
612
  };
233
613
  export declare class AppDatabase {
234
- private pb;
235
- constructor(pb: PocketBase);
614
+ pb: PocketBase;
615
+ email?: string;
616
+ salt?: string;
617
+ constructor(pb: PocketBase, payload: {
618
+ email?: string;
619
+ salt?: string;
620
+ });
621
+ getUserByEmail(): Promise<import("pocketbase").RecordModel>;
622
+ verifyUserPassword(password: string): Promise<boolean>;
623
+ generateUserPassword(): Promise<boolean>;
624
+ getUserCredentials(): Promise<any>;
625
+ getCredentials(payload: {
626
+ password?: string;
627
+ }): Promise<any>;
628
+ saveCredentials(params: {
629
+ password?: string;
630
+ credentials: any;
631
+ }): Promise<import("pocketbase").RecordModel>;
632
+ changeUserPassword(payload: {
633
+ password: string;
634
+ }): Promise<boolean>;
635
+ verifyAdminPassword(password: string): Promise<boolean>;
636
+ setAdminPassword(payload: {
637
+ password: string;
638
+ salt: string;
639
+ }): Promise<boolean>;
640
+ addNewCredential(params: {
641
+ password?: string;
642
+ payload: {
643
+ name: string;
644
+ email: string;
645
+ exchange: string;
646
+ api_key: string;
647
+ api_secret: string;
648
+ };
649
+ }): Promise<void>;
650
+ getAccountWithActivePositions(): Promise<import("pocketbase").RecordModel[]>;
651
+ getAllSymbolsFromPositions(options?: {
652
+ no_position?: boolean;
653
+ kind?: "long" | "short";
654
+ custom_filter?: string;
655
+ }): Promise<any[]>;
236
656
  createOrUpdateLiveExchangeInstance(payload: {
237
657
  account: ExchangeType;
238
658
  symbol: string;
@@ -245,18 +665,31 @@ export declare class AppDatabase {
245
665
  }): Promise<import("pocketbase").RecordModel>;
246
666
  getProxyForAccount(account: ExchangeType): Promise<HttpsProxyAgent<`http://${string}`> | SocksProxyAgent>;
247
667
  getAccounts(): Promise<ExchangeAccount[]>;
248
- getAllSymbolConfigs(with_positions?: boolean): Promise<SymbolConfig[]>;
668
+ getAllSymbolConfigs(payload?: {
669
+ with_positions?: boolean;
670
+ custom_filter?: string;
671
+ }): Promise<SymbolConfig[]>;
249
672
  get_exchange_db_instance(account: ExchangeType): Promise<ExchangeAccount & {
250
673
  expand?: {
251
674
  proxy: Proxy$1;
252
675
  };
253
676
  }>;
254
- getPositions(account: ExchangeType, options: {
255
- symbol: string;
677
+ get positionExpand(): string;
678
+ fetchCentralPositions(payload: {
679
+ asset?: string;
680
+ symbol?: string;
681
+ customFilter?: string;
682
+ }): Promise<import("pocketbase").RecordModel[]>;
683
+ getPositions(options: {
684
+ account?: ExchangeType;
685
+ symbol?: string;
256
686
  as_view?: boolean;
687
+ custom_filter?: string;
257
688
  }): Promise<(PositionsView & {
258
689
  expand?: {
259
690
  config: ScheduledTrade;
691
+ account: ExchangeAccount;
692
+ proxy: Proxy$1;
260
693
  };
261
694
  })[]>;
262
695
  private _createOrUpdatePosition;
@@ -268,6 +701,8 @@ export declare class AppDatabase {
268
701
  }): Promise<(PositionsView & {
269
702
  expand?: {
270
703
  config: ScheduledTrade;
704
+ account: ExchangeAccount;
705
+ proxy: Proxy$1;
271
706
  };
272
707
  })[]>;
273
708
  update_db_position(position: any, payload: any): Promise<import("pocketbase").RecordModel>;
@@ -279,7 +714,7 @@ export declare class AppDatabase {
279
714
  getOrders(account: ExchangeType, options: {
280
715
  symbol: string;
281
716
  kind: "long" | "short";
282
- }): Promise<import("pocketbase").RecordModel[]>;
717
+ }): Promise<Order[]>;
283
718
  deleteAndRecreateOrders(account: ExchangeType, options: {
284
719
  symbol: string;
285
720
  kind: "long" | "short";
@@ -292,7 +727,34 @@ export declare class AppDatabase {
292
727
  stop: number;
293
728
  order_id: string;
294
729
  triggerPrice?: number;
295
- }>): Promise<import("pocketbase").RecordModel[]>;
730
+ }>): Promise<Order[]>;
731
+ deleteAndBulCreateAllOrders(payload: {
732
+ account: ExchangeType & {
733
+ id: string;
734
+ };
735
+ symbol: string;
736
+ all_orders: Array<{
737
+ symbol: string;
738
+ price: number;
739
+ quantity: number;
740
+ kind: "long" | "short";
741
+ side: "buy" | "sell";
742
+ stop: number;
743
+ order_id: string;
744
+ triggerPrice?: number;
745
+ clientOrderId?: string;
746
+ }>;
747
+ }): Promise<void>;
748
+ cancelLimitOrders(payload: {
749
+ symbol: string;
750
+ kind: "long" | "short";
751
+ account: ExchangeType;
752
+ raw?: boolean;
753
+ cancelExchangeOrders: (payload: {
754
+ symbol: string;
755
+ orders: number[];
756
+ }) => Promise<any>;
757
+ }): Promise<any[]>;
296
758
  cancelOrders(payload: {
297
759
  cancelExchangeOrders: (payload: {
298
760
  symbol: string;
@@ -320,23 +782,61 @@ export declare class AppDatabase {
320
782
  message?: undefined;
321
783
  exchange_result?: undefined;
322
784
  }>;
785
+ getMoverExchangeInstances(): Promise<ExchangeAccount[]>;
786
+ updateScheduledTrade(id: string, payload: any): Promise<import("pocketbase").RecordModel>;
787
+ getPositionsToAutoFollow(): Promise<(Position$1 & {
788
+ expand: {
789
+ account: ExchangeAccount;
790
+ };
791
+ })[]>;
323
792
  createOrUpdatePositionConfig(db_position: any, payload: {
324
793
  entry: number;
325
794
  stop: number;
326
795
  risk_reward: number;
327
796
  risk: number;
328
797
  profit_percent?: number;
329
- }): Promise<void>;
798
+ place_tp?: boolean;
799
+ profit?: number;
800
+ reduce_ratio?: number;
801
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
330
802
  getPositionConfig(payload: {
331
803
  symbol: string;
332
804
  kind: "long" | "short";
333
805
  account: ExchangeType;
334
806
  }): Promise<ScheduledTrade | null>;
335
- getPositionStrategy(account: ExchangeType): Promise<{
336
- strategy_instance: Strategy;
337
- focus_account: ExchangeAccount;
338
- }>;
339
- createOrUpdateWindingDownMarket(symbol: string): Promise<import("pocketbase").RecordModel>;
807
+ getRunningAccountStrategies(filter?: string): Promise<(AccountStrategy & {
808
+ expand?: {
809
+ account: ExchangeAccount;
810
+ };
811
+ })[]>;
812
+ getAccountStrategy(payload: {
813
+ symbol: string;
814
+ account: ExchangeType;
815
+ }): Promise<AccountStrategy>;
816
+ getBotViewInstance(payload: {
817
+ asset: string;
818
+ main_account: ExchangeType;
819
+ }): Promise<BotView | null>;
820
+ getBotInstance(payload: {
821
+ asset: string;
822
+ main_account: ExchangeType;
823
+ }): Promise<BotInstance | null>;
824
+ getBotState(payload: {
825
+ asset: string;
826
+ main_account: ExchangeType;
827
+ running?: boolean;
828
+ }): Promise<BotState[]>;
829
+ getBotOrderHistories(payload: {
830
+ asset: string;
831
+ main_account: ExchangeType;
832
+ symbol?: string;
833
+ kind?: "long" | "short";
834
+ type?: "future" | "spot";
835
+ }): Promise<BotOrderHistory[]>;
836
+ createOrUpdateWindingDownMarket(payload: {
837
+ symbol: string;
838
+ risk_reward?: number;
839
+ }): Promise<import("pocketbase").RecordModel>;
340
840
  getWindingDownMarkets(symbol?: string): Promise<WindingDownMarket[]>;
341
841
  getBullishMarket(symbol: string): Promise<BullishMarket>;
342
842
  getBullishMarkets(options?: {
@@ -345,6 +845,7 @@ export declare class AppDatabase {
345
845
  percent: number;
346
846
  }>;
347
847
  totalRisk: number;
848
+ max_count?: number;
348
849
  }): Promise<{
349
850
  updated_bullish: BullishMarket[];
350
851
  moved_to_winding: WindingDownMarket[];
@@ -365,254 +866,2238 @@ export declare class AppDatabase {
365
866
  } | SymbolConfig[]>;
366
867
  unwindSymbolFromDB(symbol: string): Promise<boolean>;
367
868
  hasExistingPosition(symbol: string): Promise<import("pocketbase").RecordModel[]>;
869
+ getPositionWithLowestNextOrder(options: {
870
+ symbol?: string;
871
+ kind: "long" | "short";
872
+ asset?: string;
873
+ exclude?: ExchangeType[];
874
+ }): Promise<PositionsView | null>;
875
+ hasExistingOrders(symbol: string): Promise<import("pocketbase").RecordModel[]>;
368
876
  removeSymbolFromUnwindingMarkets(symbol: string): Promise<boolean>;
369
877
  removePosition(position: any): Promise<void>;
370
878
  removePositionConfig(position: any): Promise<void>;
879
+ getConfigProfiles(payload: {
880
+ config_id: string;
881
+ }): Promise<{
882
+ id: any;
883
+ entry: any;
884
+ stop: any;
885
+ kind: "long" | "short";
886
+ risk_reward: any;
887
+ risk: any;
888
+ profit_percent: any;
889
+ }[]>;
890
+ editConfigProfile(payload: {
891
+ id: string;
892
+ params: {
893
+ entry?: number;
894
+ stop?: number;
895
+ risk_reward?: number;
896
+ risk?: number;
897
+ profit_percent?: number;
898
+ };
899
+ }): Promise<void>;
900
+ createConfigProfile(payload: {
901
+ config_id: string;
902
+ symbol: string;
903
+ params: {
904
+ entry: number;
905
+ stop: number;
906
+ kind: "long" | "short";
907
+ risk_reward: number;
908
+ risk: number;
909
+ profit_percent: number;
910
+ };
911
+ }): Promise<void>;
912
+ getCompoundInstance(payload: {
913
+ position: Position$1;
914
+ }): Promise<CompoundInstance & {
915
+ expand: {
916
+ ref: Compounder;
917
+ };
918
+ }>;
919
+ getSupportTable(payload: {
920
+ symbol: string;
921
+ kind: "long" | "short";
922
+ }): Promise<SupportTable>;
923
+ updateCompoundInstance(payload: {
924
+ id: string;
925
+ params: any;
926
+ }): Promise<import("pocketbase").RecordModel>;
371
927
  }
372
- export interface CodeNode {
373
- minimum_pnl: number;
374
- max_size: number;
375
- profit: number;
376
- ratio?: number;
377
- increase: boolean;
378
- not_reduce?: boolean;
379
- reduce_ratio?: number;
380
- use_full?: boolean;
381
- }
382
- export type AppConfig = {
383
- fee: number;
384
- risk_per_trade: number;
385
- risk_reward: number;
386
- symbol?: string;
387
- focus: number;
388
- budget: number;
389
- support: number;
390
- resistance: number;
391
- percent_change: number;
392
- tradeSplit?: number;
393
- take_profit?: number;
394
- kind: "long" | "short";
928
+ export type StrategyPosition = {
395
929
  entry: number;
930
+ quantity: number;
931
+ avg_price?: number;
932
+ avg_qty?: number;
933
+ };
934
+ export type GapCloserResult = {
935
+ avg_entry: number;
936
+ avg_size: number;
937
+ loss: number;
396
938
  stop: number;
397
- min_size: number;
398
- price_places?: string;
399
- strategy?: "quantity" | "entry";
400
- as_array?: boolean;
401
- decimal_places?: string;
402
- min_profit?: number;
403
- raw?: boolean;
404
- gap?: number;
405
- rr?: number;
406
- max_size?: number;
939
+ stop_quantity: number;
940
+ re_entry_quantity: number;
941
+ initial_pnl: number;
942
+ tp: number;
943
+ incurred_loss: number;
944
+ pnl: number;
945
+ remaining_quantity: number;
407
946
  };
408
- declare class ExchangeAccount$1 {
409
- private instance;
410
- exchange: BaseExchange;
411
- private app_db;
412
- constructor(payload: ExchangeType, options: {
413
- exchange: BaseExchange;
414
- app_db: AppDatabase;
947
+ export type Config = {
948
+ tp_percent: number;
949
+ short_tp_factor: number;
950
+ fee_percent?: number;
951
+ budget: number;
952
+ risk_reward: number;
953
+ reduce_ratio: number;
954
+ global_config: GlobalConfig;
955
+ };
956
+ export declare class Strategy {
957
+ position: {
958
+ long: StrategyPosition;
959
+ short: StrategyPosition;
960
+ };
961
+ dominant_position?: "long" | "short";
962
+ config: Config;
963
+ constructor(payload: {
964
+ long: StrategyPosition;
965
+ short: StrategyPosition;
966
+ config: Config;
967
+ dominant_position?: "long" | "short";
415
968
  });
416
- /**
417
- *In order to avoid rate limiting issues, we cache the live exchange
418
- details for each symbol for an account in the database with an option
419
- to refresh.
969
+ get price_places(): string;
970
+ get decimal_places(): string;
971
+ to_f(price: number): number;
972
+ to_df(quantity: number): number;
973
+ pnl(kind: "long" | "short", _position?: StrategyPosition): number;
974
+ tp(kind: "long" | "short"): number;
975
+ calculate_fee(position: {
976
+ price: number;
977
+ quantity: number;
978
+ }): number;
979
+ get long_tp(): number;
980
+ get short_tp(): number;
981
+ generateGapClosingAlgorithm(payload: {
982
+ kind: "long" | "short";
983
+ ignore_entries?: boolean;
984
+ reduce_ratio?: number;
985
+ sell_factor?: number;
986
+ }): {
987
+ last_entry: any;
988
+ first_entry: any;
989
+ threshold: any;
990
+ risk: number;
991
+ risk_reward: number;
992
+ spread: number;
993
+ gap_loss: number;
994
+ net_profit: number;
995
+ long: GapCloserResult;
996
+ short: GapCloserResult;
997
+ };
998
+ gapCloserHelper(payload: {
999
+ risk: number;
1000
+ entries?: any[];
1001
+ kind: "long" | "short";
1002
+ sell_factor?: number;
1003
+ reduce_ratio?: number;
1004
+ }): {
1005
+ risk: number;
1006
+ risk_reward: number;
1007
+ spread: number;
1008
+ gap_loss: number;
1009
+ net_profit: number;
1010
+ long: GapCloserResult;
1011
+ short: GapCloserResult;
1012
+ };
1013
+ runIterations(payload: {
1014
+ kind: "long" | "short";
1015
+ iterations: number;
1016
+ risk_reward?: number;
1017
+ ignore_entries?: boolean;
1018
+ reduce_ratio?: number;
1019
+ sell_factor?: number;
1020
+ }): {
1021
+ last_entry: any;
1022
+ first_entry: any;
1023
+ threshold: any;
1024
+ risk: number;
1025
+ risk_reward: number;
1026
+ spread: number;
1027
+ gap_loss: number;
1028
+ net_profit: number;
1029
+ long: GapCloserResult;
1030
+ short: GapCloserResult;
1031
+ }[];
1032
+ getPositionAfterTp(payload: {
1033
+ kind: "long" | "short";
1034
+ include_fees?: boolean;
1035
+ }): {
1036
+ [x: string]: number | {
1037
+ entry: number;
1038
+ quantity: number;
1039
+ diff?: undefined;
1040
+ } | {
1041
+ [x: string]: number;
1042
+ diff: number;
1043
+ entry?: undefined;
1044
+ quantity?: undefined;
1045
+ };
1046
+ pnl: {
1047
+ [x: string]: number;
1048
+ diff: number;
1049
+ };
1050
+ spread: number;
1051
+ };
1052
+ getPositionAfterIteration(payload: {
1053
+ kind: "long" | "short";
1054
+ iterations: number;
1055
+ with_fees?: boolean;
1056
+ }): {
1057
+ [x: string]: number | {
1058
+ entry: number;
1059
+ quantity: number;
1060
+ diff?: undefined;
1061
+ } | {
1062
+ [x: string]: number;
1063
+ diff: number;
1064
+ entry?: undefined;
1065
+ quantity?: undefined;
1066
+ };
1067
+ pnl: {
1068
+ [x: string]: number;
1069
+ diff: number;
1070
+ };
1071
+ spread: number;
1072
+ }[];
1073
+ /**To be used as one of the agent tools eventually since
1074
+ * it is something that can be triggered continously without
1075
+ * any risk
420
1076
  */
421
- getLiveExchangeInstance(payload: {
422
- symbol: string;
423
- refresh?: boolean;
1077
+ generateOppositeTrades(payload: {
1078
+ kind: "long" | "short";
1079
+ risk_factor?: number;
1080
+ avg_entry?: number;
1081
+ }): {
1082
+ avg: {
1083
+ entry: number;
1084
+ price: number;
1085
+ quantity: number;
1086
+ };
1087
+ loss: number;
1088
+ profit_percent: number;
1089
+ fee: number;
1090
+ risk_per_trade: number;
1091
+ risk_reward: number;
1092
+ symbol?: string;
1093
+ focus: number;
1094
+ budget: number;
1095
+ support: number;
1096
+ resistance: number;
1097
+ percent_change: number;
1098
+ tradeSplit?: number;
1099
+ take_profit?: number;
1100
+ kind: "long" | "short";
1101
+ entry: number;
1102
+ stop: number;
1103
+ min_size: number;
424
1104
  price_places?: string;
1105
+ strategy?: "quantity" | "entry";
1106
+ as_array?: boolean;
425
1107
  decimal_places?: string;
426
- }): Promise<import("pocketbase").RecordModel>;
427
- getActiveAccount(symbol: string, full?: boolean): Promise<Account | {
428
- liquidation: {
1108
+ min_profit?: number;
1109
+ raw?: boolean;
1110
+ gap?: number;
1111
+ rr?: number;
1112
+ max_size?: number;
1113
+ max_quantity?: number;
1114
+ kelly?: {
1115
+ use_kelly?: boolean;
1116
+ kelly_confidence_factor?: number;
1117
+ kelly_minimum_risk?: number;
1118
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
1119
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
1120
+ };
1121
+ };
1122
+ identifyGapConfig(payload: {
1123
+ factor?: number;
1124
+ sell_factor?: number;
1125
+ kind?: "long" | "short";
1126
+ risk?: number;
1127
+ }): {
1128
+ profit_percent: {
429
1129
  long: number;
430
1130
  short: number;
431
1131
  };
432
- active_account: Account;
433
- current_price: any;
434
- exchange: any;
435
- }>;
436
- syncAccount(options: {
437
- symbol: string;
438
- kind?: "long" | "short";
439
- update?: boolean;
440
- as_view?: boolean;
441
- leverage?: number;
442
- }): Promise<PositionsView | (PositionsView & {
443
- expand?: {
444
- config: ScheduledTrade;
1132
+ risk: {
1133
+ short: number;
1134
+ long: number;
445
1135
  };
446
- })[]>;
1136
+ take_profit: {
1137
+ long: number;
1138
+ short: number;
1139
+ };
1140
+ to_reduce: {
1141
+ short: number;
1142
+ long: number;
1143
+ };
1144
+ full_reduce: {
1145
+ short: number;
1146
+ long: number;
1147
+ };
1148
+ sell_quantity: {
1149
+ short: number;
1150
+ long: number;
1151
+ };
1152
+ gap: number;
1153
+ gap_loss: number;
1154
+ };
1155
+ analyzeProfit(payload: {
1156
+ reward_factor?: number;
1157
+ max_reward_factor: number;
1158
+ risk: number;
1159
+ kind: "long" | "short";
1160
+ }): {
1161
+ pnl: number;
1162
+ loss: number;
1163
+ full_loss: number;
1164
+ original_pnl: number;
1165
+ reward_factor: number;
1166
+ profit_percent: number;
1167
+ kind: "long" | "short";
1168
+ sell_price: number;
1169
+ quantity: number;
1170
+ price_places: string;
1171
+ decimal_places: string;
1172
+ };
1173
+ simulateGapReduction(payload: {
1174
+ iterations?: number;
1175
+ factor?: number;
1176
+ direction: "long" | "short";
1177
+ kind?: "long" | "short";
1178
+ risk?: number;
1179
+ sell_factor?: number;
1180
+ }): {
1181
+ results: {
1182
+ profit_percent: {
1183
+ long: number;
1184
+ short: number;
1185
+ };
1186
+ risk: {
1187
+ short: number;
1188
+ long: number;
1189
+ };
1190
+ take_profit: {
1191
+ long: number;
1192
+ short: number;
1193
+ };
1194
+ sell_quantity: {
1195
+ short: number;
1196
+ long: number;
1197
+ };
1198
+ gap_loss: number;
1199
+ position: {
1200
+ long: {
1201
+ entry: number;
1202
+ quantity: number;
1203
+ };
1204
+ short: {
1205
+ entry: number;
1206
+ quantity: number;
1207
+ };
1208
+ };
1209
+ }[];
1210
+ quantity: number;
1211
+ };
1212
+ }
1213
+ export declare function determine_average_entry_and_size(orders: Array<{
1214
+ price: number;
1215
+ quantity: number;
1216
+ }>, places?: string, price_places?: string): {
1217
+ entry: number;
1218
+ price: number;
1219
+ quantity: number;
1220
+ };
1221
+ export declare const createArray: (start: number, stop: number, step: number) => number[];
1222
+ export type SignalConfigType = {
1223
+ symbol?: string;
1224
+ focus: number;
1225
+ budget: number;
1226
+ percent_change?: number;
1227
+ price_places?: string;
1228
+ decimal_places?: string;
1229
+ zone_risk?: number;
1230
+ fee?: number;
1231
+ support?: number;
1232
+ risk_reward?: number;
1233
+ resistance?: number;
1234
+ risk_per_trade?: number;
1235
+ increase_size?: boolean;
1236
+ additional_increase?: number;
1237
+ minimum_pnl?: number;
1238
+ take_profit?: number;
1239
+ increase_position?: boolean;
1240
+ minimum_size?: number;
1241
+ first_order_size?: number;
1242
+ gap?: number;
1243
+ max_size?: number;
1244
+ use_kelly?: boolean;
1245
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
1246
+ kelly_confidence_factor?: number;
1247
+ kelly_minimum_risk?: number;
1248
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
1249
+ full_distribution?: {
1250
+ long: GetEntriesParams["distribution"];
1251
+ short: GetEntriesParams["distribution"];
1252
+ };
1253
+ };
1254
+ declare class Signal {
1255
+ focus: number;
1256
+ budget: number;
1257
+ percent_change: number;
1258
+ price_places: string;
1259
+ decimal_places: string;
1260
+ zone_risk: number;
1261
+ fee: number;
1262
+ support?: number;
1263
+ risk_reward: number;
1264
+ resistance?: number;
1265
+ risk_per_trade?: number;
1266
+ increase_size: boolean;
1267
+ additional_increase: number;
1268
+ minimum_pnl: number;
1269
+ take_profit?: number;
1270
+ increase_position: boolean;
1271
+ minimum_size: any;
1272
+ first_order_size: number;
1273
+ gap: number;
1274
+ max_size: number;
1275
+ use_kelly: boolean;
1276
+ kelly_prediction_model: "exponential" | "normal" | "uniform";
1277
+ kelly_confidence_factor: number;
1278
+ kelly_minimum_risk: number;
1279
+ kelly_func: "theoretical" | "position_based" | "theoretical_fixed";
1280
+ symbol?: string;
1281
+ distribution: {
1282
+ long: GetEntriesParams["distribution"];
1283
+ short: GetEntriesParams["distribution"];
1284
+ };
1285
+ constructor({ focus, symbol, 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, use_kelly, kelly_prediction_model, kelly_confidence_factor, kelly_minimum_risk, kelly_func, full_distribution, }: SignalConfigType);
1286
+ build_entry({ current_price, stop_loss, pnl, stop_percent, kind, risk, no_of_trades, take_profit, distribution, }: {
1287
+ take_profit?: number;
1288
+ no_of_trades?: number;
1289
+ current_price: number;
1290
+ stop_loss?: number;
1291
+ kind?: "long" | "short";
1292
+ risk: number;
1293
+ stop_percent?: number;
1294
+ pnl?: number;
1295
+ distribution?: GetEntriesParams["distribution"];
1296
+ }): any;
1297
+ get risk(): number;
1298
+ get min_trades(): number;
1299
+ get min_price(): number;
1300
+ build_opposite_order({ current_price, kind, }: {
1301
+ current_price: number;
1302
+ kind?: "long" | "short";
1303
+ }): any;
1304
+ special_build_orders({ current_price, kind, }: {
1305
+ current_price: number;
1306
+ kind?: "long" | "short";
1307
+ }): any;
1308
+ build_orders({ current_price, kind, limit, replace_focus, max_index, min_index, }: {
1309
+ current_price: number;
1310
+ kind?: "long" | "short";
1311
+ limit?: boolean;
1312
+ replace_focus?: boolean;
1313
+ max_index?: number;
1314
+ min_index?: number;
1315
+ }): any;
1316
+ build_orders_old({ current_price, kind, limit, replace_focus, max_index, min_index, }: {
1317
+ current_price: number;
1318
+ kind?: "long" | "short";
1319
+ limit?: boolean;
1320
+ replace_focus?: boolean;
1321
+ max_index?: number;
1322
+ min_index?: number;
1323
+ }): any;
1324
+ get_bulk_trade_zones({ current_price, kind, limit, }: {
1325
+ current_price: number;
1326
+ kind?: "long" | "short";
1327
+ limit?: boolean;
1328
+ }): any;
1329
+ get_future_zones_simple({ current_price, kind, raw, }: {
1330
+ raw?: boolean;
1331
+ current_price: number;
1332
+ kind?: "long" | "short";
1333
+ }): number[];
1334
+ get_future_zones({ current_price, kind, raw, }: {
1335
+ raw?: boolean;
1336
+ current_price: number;
1337
+ kind?: "long" | "short";
1338
+ }): number[];
1339
+ to_f(value: number, places?: string): number;
1340
+ get_margin_zones({ current_price, kind, }: {
1341
+ current_price: number;
1342
+ kind?: "long" | "short";
1343
+ }): number[][];
1344
+ get_margin_range(current_price: number, kind?: string): number[];
1345
+ process_orders({ current_price, stop_loss, trade_zones, kind, }: {
1346
+ current_price: number;
1347
+ stop_loss: number;
1348
+ trade_zones: number[];
1349
+ kind?: "long" | "short";
1350
+ }): any[];
1351
+ get_risk_per_trade(number_of_orders: number): number;
1352
+ build_trade_dict({ entry, stop, risk, arr, index, new_fees, kind, start, take_profit, }: {
1353
+ entry: number;
1354
+ stop: number;
1355
+ risk: number;
1356
+ arr: number[];
1357
+ index: number;
1358
+ new_fees?: number;
1359
+ kind?: "long" | "short";
1360
+ start?: number;
1361
+ take_profit?: number;
1362
+ }): {
1363
+ entry: number;
1364
+ risk: number;
1365
+ quantity: number;
1366
+ sell_price: number;
1367
+ risk_sell: number;
1368
+ stop: number;
1369
+ pnl: number;
1370
+ fee: number;
1371
+ net: number;
1372
+ incurred: number;
1373
+ stop_percent: number;
1374
+ };
1375
+ to_df(currentPrice: number, places?: string): number;
1376
+ }
1377
+ export type AppConfig = {
1378
+ fee: number;
1379
+ risk_per_trade: number;
1380
+ risk_reward: number;
1381
+ symbol?: string;
1382
+ focus: number;
1383
+ budget: number;
1384
+ support: number;
1385
+ resistance: number;
1386
+ percent_change: number;
1387
+ tradeSplit?: number;
1388
+ take_profit?: number;
1389
+ kind: "long" | "short";
1390
+ entry: number;
1391
+ stop: number;
1392
+ min_size: number;
1393
+ price_places?: string;
1394
+ strategy?: "quantity" | "entry";
1395
+ as_array?: boolean;
1396
+ decimal_places?: string;
1397
+ min_profit?: number;
1398
+ raw?: boolean;
1399
+ gap?: number;
1400
+ rr?: number;
1401
+ max_size?: number;
1402
+ last_value?: any;
1403
+ entries?: any[];
1404
+ max_quantity?: number;
1405
+ kelly?: {
1406
+ use_kelly?: boolean;
1407
+ kelly_confidence_factor?: number;
1408
+ kelly_minimum_risk?: number;
1409
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
1410
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
1411
+ };
1412
+ };
1413
+ export type ExtendConfigType = {
1414
+ take_profit?: number;
1415
+ entry: number;
1416
+ risk?: number;
1417
+ stop?: number;
1418
+ risk_reward?: number;
1419
+ raw_instance?: boolean;
1420
+ no_of_trades?: number;
1421
+ increase?: boolean;
1422
+ price_places?: string;
1423
+ decimal_places?: string;
1424
+ min_profit?: number;
1425
+ kind?: "long" | "short";
1426
+ gap?: number;
1427
+ rr?: number;
1428
+ min_avg_size?: number;
1429
+ use_kelly?: boolean;
1430
+ kelly_confidence_factor?: number;
1431
+ kelly_minimum_risk?: number;
1432
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
1433
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
1434
+ distribution?: GetEntriesParams["distribution"];
1435
+ };
1436
+ 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, use_kelly, kelly_confidence_factor, kelly_minimum_risk, kelly_prediction_model, kelly_func, min_avg_size, distribution, }: ExtendConfigType): any[] | Signal;
1437
+ export declare function buildAvg({ _trades, kind, }: {
1438
+ _trades: any[];
1439
+ kind: "long" | "short";
1440
+ }): any;
1441
+ export declare function sortedBuildConfig(app_config: AppConfig, options: any): any[];
1442
+ export declare function get_app_config_and_max_size(config: GlobalConfig, payload: {
1443
+ entry: number;
1444
+ stop: number;
1445
+ kind: "long" | "short";
1446
+ use_kelly?: boolean;
1447
+ kelly_confidence_factor?: number;
1448
+ kelly_minimum_risk?: number;
1449
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
1450
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
1451
+ distribution?: GetEntriesParams["distribution"];
1452
+ }): {
1453
+ app_config: AppConfig;
1454
+ max_size: any;
1455
+ last_value: any;
1456
+ entries: {
1457
+ entry: any;
1458
+ avg_entry: any;
1459
+ avg_size: any;
1460
+ neg_pnl: any;
1461
+ quantity: any;
1462
+ }[];
1463
+ };
1464
+ export declare function buildAppConfig(config: GlobalConfig, payload: {
1465
+ entry: number;
1466
+ stop: number;
1467
+ risk_reward: number;
1468
+ risk: number;
1469
+ symbol: string;
1470
+ profit?: number;
1471
+ use_kelly?: boolean;
1472
+ kelly_confidence_factor?: number;
1473
+ kelly_minimum_risk?: number;
1474
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
1475
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
1476
+ distribution?: GetEntriesParams["distribution"];
1477
+ }): AppConfig;
1478
+ export declare function getOptimumStopAndRisk(app_config: AppConfig, params: {
1479
+ max_size: number;
1480
+ target_stop: number;
1481
+ highest_risk?: number;
1482
+ distribution?: GetEntriesParams["distribution"];
1483
+ }): {
1484
+ optimal_stop: number;
1485
+ optimal_risk: number;
1486
+ avg_size: any;
1487
+ avg_entry: any;
1488
+ result: any[];
1489
+ first_entry: any;
1490
+ neg_pnl: any;
1491
+ risk_reward: number;
1492
+ size_diff: number;
1493
+ entry_diff: number;
1494
+ };
1495
+ export declare function generate_config_params(app_config: AppConfig, payload: {
1496
+ entry: number;
1497
+ stop: number;
1498
+ risk_reward: number;
1499
+ risk: number;
1500
+ symbol: string;
1501
+ }): {
1502
+ entry: number;
1503
+ stop: number;
1504
+ avg_size: any;
1505
+ avg_entry: any;
1506
+ risk_reward: number;
1507
+ neg_pnl: any;
1508
+ risk: number;
1509
+ };
1510
+ export declare function determine_break_even_price(payload: {
1511
+ long_position: {
1512
+ entry: number;
1513
+ quantity: number;
1514
+ };
1515
+ short_position: {
1516
+ entry: number;
1517
+ quantity: number;
1518
+ };
1519
+ fee_percent?: number;
1520
+ }): {
1521
+ price: number;
1522
+ direction: string;
1523
+ };
1524
+ export declare function determine_amount_to_buy(payload: {
1525
+ orders: any[];
1526
+ kind: "long" | "short";
1527
+ decimal_places?: string;
1528
+ price_places?: string;
1529
+ place?: boolean;
1530
+ position: any;
1531
+ existingOrders: any[];
1532
+ }): any[];
1533
+ export declare function generateOptimumAppConfig(config: GlobalConfig, payload: {
1534
+ entry: number;
1535
+ stop: number;
1536
+ risk_reward: number;
1537
+ start_risk: number;
1538
+ max_risk?: number;
1539
+ distribution?: GetEntriesParams["distribution"];
1540
+ }, position: {
1541
+ entry: number;
1542
+ quantity: number;
1543
+ kind: "long" | "short";
1544
+ }): AppConfig | null;
1545
+ export declare function determineOptimumReward(payload: {
1546
+ app_config: AppConfig;
1547
+ increase?: boolean;
1548
+ low_range?: number;
1549
+ high_range?: number;
1550
+ target_loss?: number;
1551
+ distribution?: GetEntriesParams["distribution"];
1552
+ }): number | {
1553
+ result: any[];
1554
+ value: number;
1555
+ total: number;
1556
+ risk_per_trade: number;
1557
+ max: number;
1558
+ min: number;
1559
+ neg_pnl: any;
1560
+ entry: any;
1561
+ };
1562
+ export declare function determineOptimumRisk(config: GlobalConfig, payload: {
1563
+ entry: number;
1564
+ stop: number;
1565
+ risk_reward: number;
1566
+ risk: number;
1567
+ symbol: string;
1568
+ distribution?: GetEntriesParams["distribution"];
1569
+ }, params: {
1570
+ highest_risk: number;
1571
+ tolerance?: number;
1572
+ max_iterations?: number;
1573
+ }): {
1574
+ optimal_risk: number;
1575
+ achieved_neg_pnl: number;
1576
+ target_neg_pnl: number;
1577
+ difference: number;
1578
+ iterations: number;
1579
+ converged: boolean;
1580
+ last_value: any;
1581
+ entries: any[];
1582
+ app_config: AppConfig;
1583
+ };
1584
+ export declare function computeRiskReward(payload: {
1585
+ app_config: AppConfig;
1586
+ entry: number;
1587
+ stop: number;
1588
+ risk_per_trade: number;
1589
+ target_loss?: number;
1590
+ distribution?: GetEntriesParams["distribution"];
1591
+ }): number | {
1592
+ result: any[];
1593
+ value: number;
1594
+ total: number;
1595
+ risk_per_trade: number;
1596
+ max: number;
1597
+ min: number;
1598
+ neg_pnl: any;
1599
+ entry: any;
1600
+ };
1601
+ export declare function getRiskReward(payload: {
1602
+ entry: number;
1603
+ stop: number;
1604
+ risk: number;
1605
+ global_config: GlobalConfig;
1606
+ force_exact_risk?: boolean;
1607
+ target_loss?: number;
1608
+ distribution?: GetEntriesParams["distribution"];
1609
+ }): any;
1610
+ export declare function computeProfitDetail(payload: {
1611
+ focus_position: {
1612
+ kind: "long" | "short";
1613
+ entry: number;
1614
+ quantity: number;
1615
+ avg_qty: number;
1616
+ avg_price: number;
1617
+ };
1618
+ strategy?: {
1619
+ reward_factor: number;
1620
+ max_reward_factor: number;
1621
+ risk: number;
1622
+ };
1623
+ pnl: number;
1624
+ reduce_position?: {
1625
+ kind: "long" | "short";
1626
+ entry: number;
1627
+ quantity: number;
1628
+ avg_qty: number;
1629
+ avg_price: number;
1630
+ };
1631
+ reverse_position?: {
1632
+ kind: "long" | "short";
1633
+ avg_qty: number;
1634
+ avg_price: number;
1635
+ stop_loss: {
1636
+ price: number;
1637
+ quantity: number;
1638
+ };
1639
+ };
1640
+ full_ratio?: number;
1641
+ price_places?: string;
1642
+ decimal_places?: string;
1643
+ }): {
1644
+ pnl: number;
1645
+ loss: number;
1646
+ full_loss: number;
1647
+ original_pnl: number;
1648
+ reward_factor: number;
1649
+ profit_percent: number;
1650
+ kind: "long" | "short";
1651
+ sell_price: number;
1652
+ quantity: number;
1653
+ price_places: string;
1654
+ decimal_places: string;
1655
+ };
1656
+ export declare function generateGapTp(payload: {
1657
+ long: {
1658
+ entry: number;
1659
+ quantity: number;
1660
+ };
1661
+ short: {
1662
+ entry: number;
1663
+ quantity: number;
1664
+ };
1665
+ risk?: number;
1666
+ kind?: "long" | "short";
1667
+ factor?: number;
1668
+ sell_factor?: number;
1669
+ price_places?: string;
1670
+ decimal_places?: string;
1671
+ }): {
1672
+ profit_percent: {
1673
+ long: number;
1674
+ short: number;
1675
+ };
1676
+ risk: {
1677
+ short: number;
1678
+ long: number;
1679
+ };
1680
+ take_profit: {
1681
+ long: number;
1682
+ short: number;
1683
+ };
1684
+ to_reduce: {
1685
+ short: number;
1686
+ long: number;
1687
+ };
1688
+ full_reduce: {
1689
+ short: number;
1690
+ long: number;
1691
+ };
1692
+ sell_quantity: {
1693
+ short: number;
1694
+ long: number;
1695
+ };
1696
+ gap: number;
1697
+ gap_loss: number;
1698
+ };
1699
+ export declare function calculateFactorFromTakeProfit(payload: {
1700
+ long: {
1701
+ entry: number;
1702
+ quantity: number;
1703
+ };
1704
+ short: {
1705
+ entry: number;
1706
+ quantity: number;
1707
+ };
1708
+ knownTp: number;
1709
+ tpType: "long" | "short";
1710
+ price_places?: string;
1711
+ }): number;
1712
+ export declare function calculateFactorFromSellQuantity(payload: {
1713
+ long: {
1714
+ entry: number;
1715
+ quantity: number;
1716
+ };
1717
+ short: {
1718
+ entry: number;
1719
+ quantity: number;
1720
+ };
1721
+ knownSellQuantity: number;
1722
+ sellType: "long" | "short";
1723
+ sell_factor?: number;
1724
+ price_places?: string;
1725
+ decimal_places?: string;
1726
+ }): number;
1727
+ export declare function determineRewardFactor(payload: {
1728
+ quantity: number;
1729
+ avg_qty: number;
1730
+ minimum_pnl: number;
1731
+ risk: number;
1732
+ }): number;
1733
+ export type BotPosition = {
1734
+ kind: "long" | "short";
1735
+ entry: number;
1736
+ quantity: number;
1737
+ tp: {
1738
+ price: number;
1739
+ };
1740
+ };
1741
+ export declare function getHedgeZone(payload: {
1742
+ symbol_config: GlobalConfig;
1743
+ risk: number;
1744
+ position: BotPosition;
1745
+ reward_factor?: number;
1746
+ risk_factor?: number;
1747
+ support?: number;
1748
+ }): {
1749
+ support: number;
1750
+ resistance: number;
1751
+ risk: number;
1752
+ profit_percent: number;
1753
+ };
1754
+ export declare function getOptimumHedgeFactor(payload: {
1755
+ target_support: number;
1756
+ tolerance?: number;
1757
+ max_iterations?: number;
1758
+ min_factor?: number;
1759
+ max_factor?: number;
1760
+ symbol_config: GlobalConfig;
1761
+ risk: number;
1762
+ position: BotPosition;
1763
+ }): {
1764
+ reward_factor: number;
1765
+ achieved_support: number;
1766
+ target_support: number;
1767
+ difference: number;
1768
+ iterations: number;
1769
+ converged?: undefined;
1770
+ } | {
1771
+ reward_factor: number;
1772
+ achieved_support: number;
1773
+ target_support: number;
1774
+ difference: number;
1775
+ iterations: number;
1776
+ converged: boolean;
1777
+ };
1778
+ export type CType = {
1779
+ next_order: number;
1780
+ take_profit: number;
1781
+ };
1782
+ export declare function determineCompoundLongTrade(payload: {
1783
+ focus_short_position: CType;
1784
+ focus_long_position: CType;
1785
+ shortConfig: {
1786
+ entry: number;
1787
+ stop: number;
1788
+ risk_reward: number;
1789
+ risk: number;
1790
+ symbol: string;
1791
+ profit_percent: number;
1792
+ };
1793
+ rr?: number;
1794
+ global_config: GlobalConfig;
1795
+ }): {
1796
+ start_risk: number;
1797
+ short_profit: number;
1798
+ support: number;
1799
+ resistance: number;
1800
+ long_v: any;
1801
+ profit_percent: number;
1802
+ result: any;
1803
+ short_max_size: any;
1804
+ };
1805
+ export declare function generateOppositeTradeConfig(payload: {
1806
+ kind: "long" | "short";
1807
+ entry: number;
1808
+ quantity: number;
1809
+ target_pnl: number;
1810
+ global_config: GlobalConfig;
1811
+ ratio?: number;
1812
+ }): {
1813
+ entry: number;
1814
+ stop: number;
1815
+ risk: number;
1816
+ risk_reward: number | {
1817
+ result: any[];
1818
+ value: number;
1819
+ total: number;
1820
+ risk_per_trade: number;
1821
+ max: number;
1822
+ min: number;
1823
+ neg_pnl: any;
1824
+ entry: any;
1825
+ };
1826
+ };
1827
+ export declare function constructAppConfig(payload: {
1828
+ account: PositionsView;
1829
+ global_config: GlobalConfig;
1830
+ kelly_config?: {
1831
+ use_kelly: boolean;
1832
+ kelly_confidence_factor: number;
1833
+ kelly_minimum_risk: number;
1834
+ kelly_prediction_model: string;
1835
+ };
1836
+ }): {
1837
+ fee: number;
1838
+ risk_per_trade: number;
1839
+ risk_reward: number;
1840
+ symbol?: string;
1841
+ focus: number;
1842
+ budget: number;
1843
+ support: number;
1844
+ resistance: number;
1845
+ percent_change: number;
1846
+ tradeSplit?: number;
1847
+ take_profit?: number;
1848
+ kind: "long" | "short";
1849
+ entry: number;
1850
+ stop: number;
1851
+ min_size: number;
1852
+ price_places?: string;
1853
+ strategy?: "quantity" | "entry";
1854
+ as_array?: boolean;
1855
+ decimal_places?: string;
1856
+ min_profit?: number;
1857
+ raw?: boolean;
1858
+ gap?: number;
1859
+ rr?: number;
1860
+ max_size?: number;
1861
+ last_value?: any;
1862
+ max_quantity?: number;
1863
+ kelly?: {
1864
+ use_kelly?: boolean;
1865
+ kelly_confidence_factor?: number;
1866
+ kelly_minimum_risk?: number;
1867
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
1868
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
1869
+ };
1870
+ };
1871
+ export declare function generateDangerousConfig(payload: {
1872
+ account: PositionsView;
1873
+ global_config: GlobalConfig;
1874
+ config: {
1875
+ quantity: number;
1876
+ stop: number;
1877
+ entry: number;
1878
+ };
1879
+ }): {
1880
+ entry: number;
1881
+ risk: number;
1882
+ stop: number;
1883
+ risk_reward: number | {
1884
+ result: any[];
1885
+ value: number;
1886
+ total: number;
1887
+ risk_per_trade: number;
1888
+ max: number;
1889
+ min: number;
1890
+ neg_pnl: any;
1891
+ entry: any;
1892
+ };
1893
+ };
1894
+ export type ExchangeOrder = {
1895
+ symbol: string;
1896
+ price: number;
1897
+ quantity: number;
1898
+ kind: "long" | "short";
1899
+ side: "buy" | "sell";
1900
+ stop: number;
1901
+ order_id: string;
1902
+ triggerPrice?: number;
1903
+ };
1904
+ export declare class ExchangePosition {
1905
+ exchange: BaseExchange;
1906
+ exchange_account: ExchangeAccount$1;
1907
+ private app_db;
1908
+ private instance;
1909
+ orders: {
1910
+ entries: ExchangeOrder[];
1911
+ stop_orders: ExchangeOrder[];
1912
+ tp_orders: ExchangeOrder[];
1913
+ };
1914
+ constructor(payload: {
1915
+ exchange: BaseExchange;
1916
+ app_db: AppDatabase;
1917
+ instance: PositionsView;
1918
+ exchange_account: ExchangeAccount$1;
1919
+ without_view?: PositionsView;
1920
+ orders?: {
1921
+ entries: any[];
1922
+ stop_orders: any[];
1923
+ tp_orders: any[];
1924
+ };
1925
+ });
1926
+ get symbol_config(): SymbolConfig;
1927
+ initialize(): Promise<void>;
1928
+ getInstance(): PositionsView;
1929
+ get symbol(): any;
1930
+ get kind(): any;
1931
+ get account(): ExchangeAccount;
1932
+ get compound(): CompoundInstance & {
1933
+ amount_to_risk?: number;
1934
+ profit_percent?: number;
1935
+ };
1936
+ getProxyForAccount(): Promise<HttpsProxyAgent<`http://${string}`> | SocksProxyAgent>;
1937
+ cancelOrders(payload: {
1938
+ limit?: boolean;
1939
+ price?: number;
1940
+ raw?: boolean;
1941
+ }): Promise<any[] | {
1942
+ success: boolean;
1943
+ message: string;
1944
+ exchange_result?: undefined;
1945
+ error?: undefined;
1946
+ } | {
1947
+ success: boolean;
1948
+ exchange_result: any;
1949
+ message?: undefined;
1950
+ error?: undefined;
1951
+ } | {
1952
+ success: boolean;
1953
+ error: any;
1954
+ message?: undefined;
1955
+ exchange_result?: undefined;
1956
+ }>;
1957
+ getConfig(payload?: {
1958
+ params?: {
1959
+ entry?: number;
1960
+ stop?: number;
1961
+ risk_reward?: number;
1962
+ risk?: number;
1963
+ profit_percent?: number;
1964
+ place_tp?: boolean;
1965
+ profit?: number;
1966
+ reduce_ratio?: number;
1967
+ };
1968
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
1969
+ updateTargetPnl(): Promise<any>;
1970
+ updateConfigPnl(): Promise<void>;
1971
+ triggerTradeFromConfig(payload: {
1972
+ place?: boolean;
1973
+ raw?: boolean;
1974
+ tp?: boolean;
1975
+ stop?: boolean;
1976
+ use_current?: boolean;
1977
+ ignore_config?: boolean;
1978
+ risky?: boolean;
1979
+ hedge?: boolean;
1980
+ }): Promise<any>;
1981
+ placeSharedOrder(action: "place_limit_orders" | "place_stop_orders" | "place_tp_orders" | "dangerous_entry_orders", payload: {
1982
+ entry: number;
1983
+ stop: number;
1984
+ risk_reward: number;
1985
+ risk: number;
1986
+ place?: boolean;
1987
+ update_db?: boolean;
1988
+ raw?: boolean;
1989
+ use_current?: boolean;
1990
+ stop_percent?: number;
1991
+ distribution?: GetEntriesParams["distribution"];
1992
+ hedge?: boolean;
1993
+ }): Promise<any>;
1994
+ buildAppConfig(payload: {
1995
+ entry: number;
1996
+ stop: number;
1997
+ risk_reward: number;
1998
+ risk: number;
1999
+ profit?: number;
2000
+ update_db?: boolean;
2001
+ profit_percent?: number;
2002
+ use_kelly?: boolean;
2003
+ kelly_confidence_factor?: number;
2004
+ kelly_minimum_risk?: number;
2005
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
2006
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
2007
+ }): Promise<AppConfig>;
2008
+ placeConfigOrders(app_config: AppConfig, solution: {
2009
+ risk_reward: number;
2010
+ entry: number;
2011
+ stop: number;
2012
+ risk_per_trade: number;
2013
+ avg_size: number;
2014
+ neg_pnl: number;
2015
+ min_size: number;
2016
+ symbol: string;
2017
+ stop_percent?: number;
2018
+ use_kelly?: boolean;
2019
+ kelly_confidence_factor?: number;
2020
+ kelly_minimum_risk?: number;
2021
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
2022
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
2023
+ distribution?: GetEntriesParams["distribution"];
2024
+ }, place?: boolean, skip_stop?: boolean): Promise<{
2025
+ entry_orders: {
2026
+ orders: {
2027
+ entry: any;
2028
+ quantity: any;
2029
+ reverse_avg_entry: any;
2030
+ reverse_avg_quantity: any;
2031
+ avg_entry: any;
2032
+ avg_size: any;
2033
+ }[];
2034
+ kind: "long" | "short";
2035
+ };
2036
+ stop_orders: {
2037
+ stop: number;
2038
+ final_stop: number;
2039
+ kind: "long" | "short";
2040
+ quantity: any;
2041
+ is_limit: boolean;
2042
+ neg_pnl: any;
2043
+ };
2044
+ trades: any[];
2045
+ }>;
2046
+ determineAmountToBuy(payload: {
2047
+ orders: any[];
2048
+ kind: "long" | "short";
2049
+ refresh?: boolean;
2050
+ decimal_places?: string;
2051
+ price_places?: string;
2052
+ cancel?: boolean;
2053
+ place?: boolean;
2054
+ }): Promise<any[]>;
2055
+ refresh(live_refresh?: boolean): Promise<{
2056
+ instance: PositionsView;
2057
+ existingOrders: void | Order[];
2058
+ }>;
2059
+ placeTrade(payload: {
2060
+ place?: boolean;
2061
+ tp?: boolean;
2062
+ stop?: boolean;
2063
+ raw?: boolean;
2064
+ limit?: boolean;
2065
+ cancel?: boolean;
2066
+ ignore_config?: boolean;
2067
+ risky?: boolean;
2068
+ target_pnl?: number;
2069
+ hedge?: boolean;
2070
+ }): Promise<any>;
2071
+ placeStopLimit(payload: {
2072
+ place?: boolean;
2073
+ stop: number;
2074
+ quantity?: number;
2075
+ }): Promise<any>;
2076
+ computeTargetPnl(payload: {
2077
+ secondary: ExchangePosition;
2078
+ }): Promise<number>;
2079
+ runSimulation(payload: {
2080
+ iterations?: number;
2081
+ long_position: ExchangePosition;
2082
+ short_position: ExchangePosition;
2083
+ raw?: boolean;
2084
+ }): Promise<Strategy | {
2085
+ last_entry: any;
2086
+ first_entry: any;
2087
+ threshold: any;
2088
+ risk: number;
2089
+ risk_reward: number;
2090
+ spread: number;
2091
+ gap_loss: number;
2092
+ net_profit: number;
2093
+ long: {
2094
+ avg_entry: number;
2095
+ avg_size: number;
2096
+ loss: number;
2097
+ stop: number;
2098
+ stop_quantity: number;
2099
+ re_entry_quantity: number;
2100
+ initial_pnl: number;
2101
+ tp: number;
2102
+ incurred_loss: number;
2103
+ pnl: number;
2104
+ remaining_quantity: number;
2105
+ };
2106
+ short: {
2107
+ avg_entry: number;
2108
+ avg_size: number;
2109
+ loss: number;
2110
+ stop: number;
2111
+ stop_quantity: number;
2112
+ re_entry_quantity: number;
2113
+ initial_pnl: number;
2114
+ tp: number;
2115
+ incurred_loss: number;
2116
+ pnl: number;
2117
+ remaining_quantity: number;
2118
+ };
2119
+ }[]>;
2120
+ rawConfigUpdate(payload: any): Promise<void>;
2121
+ /**
2122
+ * This method is used to place the opposite trade action
2123
+ */
2124
+ placeOppositeTradeAction(payload: {
2125
+ data: {
2126
+ avg: {
2127
+ quantity: number;
2128
+ price: number;
2129
+ };
2130
+ entry: number;
2131
+ stop: number;
2132
+ risk_per_trade: number;
2133
+ profit_percent: number;
2134
+ risk_reward: number;
2135
+ };
2136
+ }): Promise<void>;
2137
+ /**
2138
+ * Updates the risk configuration for an empty position using the next_risk value.
2139
+ * This implements progressive risk management where successful trades increase future risk tolerance.
2140
+ *
2141
+ * @param payload.symbol - The trading symbol (e.g., "BTCUSDT")
2142
+ * @param payload.kind - Position type: "long" or "short"
2143
+ * @returns Object indicating if update was successful with old/new risk values
2144
+ */
2145
+ updateRiskOnEmpty(): Promise<{
2146
+ updated: boolean;
2147
+ symbol: any;
2148
+ kind: any;
2149
+ old_risk: number;
2150
+ new_risk: number;
2151
+ reason?: undefined;
2152
+ } | {
2153
+ updated: boolean;
2154
+ symbol: any;
2155
+ kind: any;
2156
+ reason: string;
2157
+ old_risk?: undefined;
2158
+ new_risk?: undefined;
2159
+ }>;
2160
+ increasePositionAtStop(payload: {
2161
+ place?: boolean;
2162
+ price?: number;
2163
+ quantity?: number;
2164
+ increase?: boolean;
2165
+ ratio_to_loose?: number;
2166
+ reverse_position?: ExchangePosition;
2167
+ increase_ratio?: number;
2168
+ }): Promise<any>;
2169
+ lockReduction({ pnl, place, pause_tp, }: {
2170
+ pnl: number;
2171
+ place?: boolean;
2172
+ pause_tp?: boolean;
2173
+ }): Promise<{
2174
+ sell_ratio: number;
2175
+ current_pnl: number;
2176
+ profit_percent: number;
2177
+ current_price: number;
2178
+ notional_value: number;
2179
+ }>;
2180
+ placeSingleOrder(payload: {
2181
+ long_position: ExchangePosition;
2182
+ short_position: ExchangePosition;
2183
+ }): Promise<string>;
2184
+ placeMarketOrder(payload: {
2185
+ quantity?: number;
2186
+ close?: boolean;
2187
+ }): Promise<void>;
2188
+ generate_config_params(payload: {
2189
+ entry: number;
2190
+ stop: number;
2191
+ risk_reward: number;
2192
+ risk: number;
2193
+ with_trades?: boolean;
2194
+ }): Promise<any>;
2195
+ extrapolateConfig(payload: {
2196
+ risk_reward?: number;
2197
+ risk?: number;
2198
+ kind?: "long" | "short";
2199
+ }): Promise<any>;
2200
+ build_short_order(): Promise<any>;
2201
+ /**
2202
+ * This function builds a config for a symbol
2203
+ * @param payload
2204
+ * @returns
2205
+ */
2206
+ buildConfigForSymbol(payload: {
2207
+ risk: number;
2208
+ risk_reward?: number;
2209
+ as_config?: boolean;
2210
+ with_trades?: boolean;
2211
+ }): Promise<any>;
2212
+ buildTrades(payload: {
2213
+ risk?: number;
2214
+ }): Promise<{
2215
+ trades: any[];
2216
+ max_size: any;
2217
+ last_price: any;
2218
+ total_size: number;
2219
+ avg_entry: number;
2220
+ }>;
2221
+ tradeConfig(payload: {
2222
+ override?: any;
2223
+ }): Promise<AppConfig>;
2224
+ getOrCreatePositionConfig(payload: {
2225
+ risk?: number;
2226
+ risk_reward?: number;
2227
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
2228
+ getOppositeConfig(payload: {
2229
+ ratio?: number;
2230
+ }): {
2231
+ entry: number;
2232
+ stop: number;
2233
+ risk: number;
2234
+ risk_reward: number | {
2235
+ result: any[];
2236
+ value: number;
2237
+ total: number;
2238
+ risk_per_trade: number;
2239
+ max: number;
2240
+ min: number;
2241
+ neg_pnl: any;
2242
+ entry: any;
2243
+ };
2244
+ };
2245
+ getOptimumRiskReward(): Promise<number | {
2246
+ result: any[];
2247
+ value: number;
2248
+ total: number;
2249
+ risk_per_trade: number;
2250
+ max: number;
2251
+ min: number;
2252
+ neg_pnl: any;
2253
+ entry: any;
2254
+ }>;
2255
+ get appConfig(): {
2256
+ fee: number;
2257
+ risk_per_trade: number;
2258
+ risk_reward: number;
2259
+ symbol?: string;
2260
+ focus: number;
2261
+ budget: number;
2262
+ support: number;
2263
+ resistance: number;
2264
+ percent_change: number;
2265
+ tradeSplit?: number;
2266
+ take_profit?: number;
2267
+ kind: "long" | "short";
2268
+ entry: number;
2269
+ stop: number;
2270
+ min_size: number;
2271
+ price_places?: string;
2272
+ strategy?: "quantity" | "entry";
2273
+ as_array?: boolean;
2274
+ decimal_places?: string;
2275
+ min_profit?: number;
2276
+ raw?: boolean;
2277
+ gap?: number;
2278
+ rr?: number;
2279
+ max_size?: number;
2280
+ last_value?: any;
2281
+ max_quantity?: number;
2282
+ kelly?: {
2283
+ use_kelly?: boolean;
2284
+ kelly_confidence_factor?: number;
2285
+ kelly_minimum_risk?: number;
2286
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
2287
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
2288
+ };
2289
+ };
2290
+ updateProfitPercentWithRisk(payload: {
2291
+ focus_position: ExchangePosition;
2292
+ }): Promise<{
2293
+ profit_percent: number;
2294
+ take_profit: number;
2295
+ last_order: number;
2296
+ }>;
2297
+ getOrders(payload: {
2298
+ type?: "limit" | "stop" | "tp";
2299
+ }): {
2300
+ symbol: any;
2301
+ price: any;
2302
+ quantity: any;
2303
+ kind: any;
2304
+ side: any;
2305
+ stop: any;
2306
+ order_id: any;
2307
+ triggerPrice: any;
2308
+ client_order_id: any;
2309
+ }[];
2310
+ cancelExchangeOrder(payload: {
2311
+ type: "limit" | "stop" | "tp";
2312
+ refresh?: boolean;
2313
+ }): Promise<any>;
2314
+ placeDangerousTrade(payload: {
2315
+ entry: number;
2316
+ quantity: number;
2317
+ stop?: number;
2318
+ }): {
2319
+ entry: number;
2320
+ risk: number;
2321
+ stop: number;
2322
+ risk_reward: number | {
2323
+ result: any[];
2324
+ value: number;
2325
+ total: number;
2326
+ risk_per_trade: number;
2327
+ max: number;
2328
+ min: number;
2329
+ neg_pnl: any;
2330
+ entry: any;
2331
+ };
2332
+ };
2333
+ followStop(payload: {
2334
+ focus_position: ExchangePosition;
2335
+ fee_percent?: number;
2336
+ place?: boolean;
2337
+ }): Promise<any>;
2338
+ get support(): SupportTable;
2339
+ get linkedConfig(): ScheduledTrade;
2340
+ get isActiveTrade(): {
2341
+ config: ScheduledTrade;
2342
+ condition: boolean;
2343
+ };
2344
+ updateCompound(payload?: {
2345
+ place?: boolean;
2346
+ }): Promise<{
2347
+ support: number;
2348
+ counter: number;
2349
+ new_risk: number;
2350
+ condition: boolean;
2351
+ stop: number;
2352
+ }>;
2353
+ cleanOnActiveCompoundInstance(): Promise<void>;
2354
+ }
2355
+ declare class ExchangeAccount$1 {
2356
+ instance: {
2357
+ owner: string;
2358
+ exchange: string;
2359
+ };
2360
+ exchange: BaseExchange;
2361
+ main_exchange?: BaseExchange;
2362
+ private app_db;
2363
+ long_position?: ExchangePosition;
2364
+ short_position?: ExchangePosition;
2365
+ raw_positions?: PositionsView[];
2366
+ constructor(payload: ExchangeType, options: {
2367
+ exchange: BaseExchange;
2368
+ app_db: AppDatabase;
2369
+ main_exchange?: BaseExchange;
2370
+ });
2371
+ /**
2372
+ *In order to avoid rate limiting issues, we cache the live exchange
2373
+ details for each symbol for an account in the database with an option
2374
+ to refresh.
2375
+ */
2376
+ getDBInstance(): AppDatabase;
2377
+ getLiveExchangeInstance(payload: {
2378
+ symbol: string;
2379
+ refresh?: boolean;
2380
+ refresh_symbol_config?: boolean;
2381
+ }): Promise<import("pocketbase").RecordModel>;
2382
+ initializePositions(payload: {
2383
+ symbol: string;
2384
+ kind: "long" | "short";
2385
+ update?: boolean;
2386
+ }): Promise<ExchangePosition>;
2387
+ getActiveAccount(payload: {
2388
+ symbol: string;
2389
+ full?: boolean;
2390
+ refresh?: boolean;
2391
+ }): Promise<Account | {
2392
+ liquidation: {
2393
+ long: number;
2394
+ short: number;
2395
+ };
2396
+ active_account: Account;
2397
+ current_price: any;
2398
+ exchange: any;
2399
+ }>;
2400
+ refreshAccount(payload: {
2401
+ symbol: string;
2402
+ live_refresh?: boolean;
2403
+ leverage?: number;
2404
+ }): Promise<(PositionsView & {
2405
+ expand?: {
2406
+ config: ScheduledTrade;
2407
+ account: ExchangeAccount;
2408
+ proxy: Proxy$1;
2409
+ };
2410
+ })[]>;
2411
+ syncAccount(options: {
2412
+ symbol: string;
2413
+ kind?: "long" | "short";
2414
+ update?: boolean;
2415
+ as_view?: boolean;
2416
+ leverage?: number;
2417
+ live_refresh?: boolean;
2418
+ }): Promise<PositionsView | (PositionsView & {
2419
+ expand?: {
2420
+ config: ScheduledTrade;
2421
+ account: ExchangeAccount;
2422
+ proxy: Proxy$1;
2423
+ };
2424
+ })[]>;
447
2425
  getRunningInstanceFromDB(symbol: string): Promise<TradeBlockTracking>;
448
2426
  syncOrders(options: {
449
2427
  symbol: string;
450
- kind: "long" | "short";
2428
+ kind?: "long" | "short";
451
2429
  update?: boolean;
452
- }): Promise<import("pocketbase").RecordModel[]>;
2430
+ }): Promise<void | Order[]>;
453
2431
  toggleStopBuying(payload: {
454
2432
  symbol: string;
455
2433
  kind: "long" | "short";
456
- should_stop?: boolean;
457
- }): Promise<import("pocketbase").RecordModel>;
458
- cancelOrders(payload: {
2434
+ should_stop?: boolean;
2435
+ }): Promise<import("pocketbase").RecordModel>;
2436
+ getFocusPosition(payload: {
2437
+ symbol: string;
2438
+ kind: "long" | "short";
2439
+ update?: boolean;
2440
+ }): Promise<ExchangePosition>;
2441
+ cancelOrders(payload: {
2442
+ symbol: string;
2443
+ kind: "long" | "short";
2444
+ price?: number;
2445
+ all?: boolean;
2446
+ stop?: boolean;
2447
+ limit?: boolean;
2448
+ raw?: boolean;
2449
+ }): Promise<any[] | {
2450
+ success: boolean;
2451
+ message: string;
2452
+ exchange_result?: undefined;
2453
+ error?: undefined;
2454
+ } | {
2455
+ success: boolean;
2456
+ exchange_result: any;
2457
+ message?: undefined;
2458
+ error?: undefined;
2459
+ } | {
2460
+ success: boolean;
2461
+ error: any;
2462
+ message?: undefined;
2463
+ exchange_result?: undefined;
2464
+ }>;
2465
+ cancelExchangeOrders(payload: {
2466
+ symbol: string;
2467
+ orders: number[];
2468
+ }): Promise<any>;
2469
+ getBreakEvenPrice(payload: {
2470
+ symbol: string;
2471
+ }): Promise<{
2472
+ price: number;
2473
+ direction: string;
2474
+ }>;
2475
+ tradeConfig(payload: {
2476
+ symbol: string;
2477
+ kind: "long" | "short";
2478
+ override?: any;
2479
+ }): Promise<AppConfig>;
2480
+ justInTimeProfit(payload: {
2481
+ symbol: string;
2482
+ target_pnl: number;
2483
+ kind: "long" | "short";
2484
+ refresh?: boolean;
2485
+ place?: boolean;
2486
+ take_profit?: number;
2487
+ pause_tp?: boolean;
2488
+ }): Promise<{
2489
+ sell_ratio: number;
2490
+ current_pnl: number;
2491
+ profit_percent: number;
2492
+ current_price: number;
2493
+ notional_value: number;
2494
+ }>;
2495
+ buildTrades(payload: {
2496
+ symbol: string;
2497
+ kind: "long" | "short";
2498
+ risk?: number;
2499
+ }): Promise<{
2500
+ trades: any[];
2501
+ max_size: any;
2502
+ last_price: any;
2503
+ total_size: number;
2504
+ avg_entry: number;
2505
+ }>;
2506
+ placeSharedOrder(action: "place_limit_orders" | "place_stop_orders" | "place_tp_orders" | "dangerous_entry_orders", payload: {
2507
+ symbol: string;
2508
+ entry: number;
2509
+ stop: number;
2510
+ risk_reward: number;
2511
+ risk: number;
2512
+ place?: boolean;
2513
+ update_db?: boolean;
2514
+ raw?: boolean;
2515
+ use_current?: boolean;
2516
+ stop_percent?: number;
2517
+ }): Promise<any>;
2518
+ getOrCreatePositionConfig(payload: {
2519
+ symbol: string;
2520
+ kind: "long" | "short";
2521
+ risk?: number;
2522
+ risk_reward?: number;
2523
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
2524
+ getPositionConfig(payload: {
2525
+ symbol: string;
2526
+ kind: "long" | "short";
2527
+ params?: {
2528
+ entry?: number;
2529
+ stop?: number;
2530
+ risk_reward?: number;
2531
+ risk?: number;
2532
+ profit_percent?: number;
2533
+ place_tp?: boolean;
2534
+ profit?: number;
2535
+ };
2536
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
2537
+ getCurrentPrice(symbol: string): Promise<any>;
2538
+ getAccountStrategy(payload: {
2539
+ symbol: string;
2540
+ }): Promise<AccountStrategy>;
2541
+ buildReduceConfig(payload: {
2542
+ symbol: string;
2543
+ kind?: "long" | "short";
2544
+ as_dict?: boolean;
2545
+ target_pnl?: number;
2546
+ trigger?: {
2547
+ long: boolean;
2548
+ short: boolean;
2549
+ };
2550
+ use_full?: boolean;
2551
+ }): Promise<{
2552
+ trigger_short: boolean;
2553
+ trigger_long: boolean;
2554
+ symbol: string;
2555
+ short_minimum_pnl: number;
2556
+ long_minimum_pnl: number;
2557
+ short_profit: any;
2558
+ long_profit: any;
2559
+ owner: string;
2560
+ exchange: string;
2561
+ not_reduce: boolean;
2562
+ reduce_ratio_long: any;
2563
+ reduce_ratio_short: any;
2564
+ use_full_long: any;
2565
+ use_full_short: any;
2566
+ } | {
2567
+ long: {
2568
+ minimum_pnl: number;
2569
+ max_size: number;
2570
+ profit: any;
2571
+ increase: boolean;
2572
+ not_reduce: boolean;
2573
+ ratio: any;
2574
+ use_full: boolean;
2575
+ sell_ratio: any;
2576
+ };
2577
+ short: {
2578
+ minimum_pnl: number;
2579
+ max_size: number;
2580
+ profit: any;
2581
+ increase: boolean;
2582
+ not_reduce: boolean;
2583
+ ratio: any;
2584
+ use_full: boolean;
2585
+ sell_ratio: any;
2586
+ };
2587
+ trigger: {
2588
+ long: boolean;
2589
+ short: boolean;
2590
+ };
2591
+ }>;
2592
+ getOriginalPlannedStop(payload: {
2593
+ symbol: string;
2594
+ kind: "long" | "short";
2595
+ }): Promise<any>;
2596
+ syncReduceClosePosition(payload?: {
2597
+ symbol: string;
2598
+ kind?: "long" | "short";
2599
+ trigger?: boolean;
2600
+ }): Promise<any>;
2601
+ reduceMajorPositionEntry(payload: {
2602
+ symbol: string;
2603
+ long: any;
2604
+ short: any;
2605
+ trigger: {
2606
+ long: boolean;
2607
+ short: boolean;
2608
+ };
2609
+ }): Promise<any>;
2610
+ placeProfitAndStop(payload: {
2611
+ symbol: string;
2612
+ trigger?: boolean;
2613
+ refresh?: boolean;
2614
+ kind?: "long" | "short";
2615
+ target_pnl?: number;
2616
+ }): Promise<any>;
2617
+ reEnterPositionOnEmpty(symbol: string): Promise<void>;
2618
+ build_short_order(payload: {
2619
+ symbol: string;
2620
+ kind: "long" | "short";
2621
+ }): Promise<any>;
2622
+ extrapolateShortConfig(payload: {
2623
+ kind: "long" | "short";
2624
+ symbol: string;
2625
+ risk_reward?: number;
2626
+ risk?: number;
2627
+ }): Promise<any>;
2628
+ placeMarketOrder(payload: {
2629
+ symbol: string;
2630
+ kind: "long" | "short";
2631
+ quantity?: number;
2632
+ close?: boolean;
2633
+ }): Promise<void>;
2634
+ placeSingleOrder(payload: {
2635
+ symbol: string;
2636
+ kind: "long" | "short";
2637
+ }): Promise<string>;
2638
+ followStop(payload: {
2639
+ symbol: string;
2640
+ kind: "long" | "short";
2641
+ fee_percent?: number;
2642
+ focus_position: ExchangePosition;
2643
+ place?: boolean;
2644
+ }): Promise<any>;
2645
+ increasePositionAtStop(payload: {
2646
+ symbol: string;
2647
+ kind: "long" | "short";
2648
+ place?: boolean;
2649
+ price?: number;
2650
+ quantity?: number;
2651
+ increase?: boolean;
2652
+ ratio_to_loose?: number;
2653
+ }): Promise<any>;
2654
+ triggerTradeFromConfig(payload: {
2655
+ symbol: string;
2656
+ kind: "long" | "short";
2657
+ place?: boolean;
2658
+ raw?: boolean;
2659
+ tp?: boolean;
2660
+ stop?: boolean;
2661
+ use_current?: boolean;
2662
+ ignore_config?: boolean;
2663
+ risky?: boolean;
2664
+ }): Promise<any>;
2665
+ verifyStopLoss(payload: {
2666
+ symbol: string;
2667
+ kind: "long" | "short";
2668
+ revert?: boolean;
2669
+ }): Promise<void | Order[]>;
2670
+ windDownSymbol(payload: {
2671
+ symbol: string;
2672
+ risk_reward?: number;
2673
+ risk?: number;
2674
+ }): Promise<void>;
2675
+ updateTargetPnl(payload: {
2676
+ symbol: string;
2677
+ kind: "long" | "short";
2678
+ }): Promise<any>;
2679
+ updateRiskOnEmpty(payload: {
2680
+ symbol: string;
2681
+ kind: "long" | "short";
2682
+ }): Promise<{
2683
+ updated: boolean;
2684
+ symbol: any;
2685
+ kind: any;
2686
+ old_risk: number;
2687
+ new_risk: number;
2688
+ reason?: undefined;
2689
+ } | {
2690
+ updated: boolean;
2691
+ symbol: any;
2692
+ kind: any;
2693
+ reason: string;
2694
+ old_risk?: undefined;
2695
+ new_risk?: undefined;
2696
+ }>;
2697
+ updateGoodHedgeConfig(payload: {
2698
+ symbol: string;
2699
+ params?: {
2700
+ support: number;
2701
+ resistance: number;
2702
+ risk: number;
2703
+ profit_percent: number;
2704
+ };
2705
+ risk_factor?: number;
2706
+ update?: boolean;
2707
+ place?: boolean;
2708
+ update_tp?: boolean;
2709
+ }): Promise<{
2710
+ support: number;
2711
+ resistance: number;
2712
+ risk: number;
2713
+ profit_percent: number;
2714
+ }>;
2715
+ /**
2716
+ * This method is used to place the opposite trade action
2717
+ */
2718
+ placeOppositeTradeAction(payload: {
2719
+ symbol: string;
2720
+ kind: "long" | "short";
2721
+ data: {
2722
+ avg: {
2723
+ quantity: number;
2724
+ price: number;
2725
+ };
2726
+ entry: number;
2727
+ stop: number;
2728
+ risk_per_trade: number;
2729
+ profit_percent: number;
2730
+ risk_reward: number;
2731
+ };
2732
+ }): Promise<void>;
2733
+ buildOppositeTrades(payload: {
2734
+ symbol: string;
2735
+ kind: "long" | "short";
2736
+ place?: boolean;
2737
+ place_symbol?: string;
2738
+ }): Promise<{
2739
+ avg: {
2740
+ entry: number;
2741
+ price: number;
2742
+ quantity: number;
2743
+ };
2744
+ loss: number;
2745
+ profit_percent: number;
2746
+ fee: number;
2747
+ risk_per_trade: number;
2748
+ risk_reward: number;
2749
+ symbol?: string;
2750
+ focus: number;
2751
+ budget: number;
2752
+ support: number;
2753
+ resistance: number;
2754
+ percent_change: number;
2755
+ tradeSplit?: number;
2756
+ take_profit?: number;
2757
+ kind: "long" | "short";
2758
+ entry: number;
2759
+ stop: number;
2760
+ min_size: number;
2761
+ price_places?: string;
2762
+ strategy?: "quantity" | "entry";
2763
+ as_array?: boolean;
2764
+ decimal_places?: string;
2765
+ min_profit?: number;
2766
+ raw?: boolean;
2767
+ gap?: number;
2768
+ rr?: number;
2769
+ max_size?: number;
2770
+ max_quantity?: number;
2771
+ kelly?: {
2772
+ use_kelly?: boolean;
2773
+ kelly_confidence_factor?: number;
2774
+ kelly_minimum_risk?: number;
2775
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
2776
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
2777
+ };
2778
+ }>;
2779
+ runSimulation(payload: {
2780
+ symbol: string;
2781
+ kind: "long" | "short";
2782
+ iterations?: number;
2783
+ raw?: boolean;
2784
+ }): Promise<Strategy | {
2785
+ last_entry: any;
2786
+ first_entry: any;
2787
+ threshold: any;
2788
+ risk: number;
2789
+ risk_reward: number;
2790
+ spread: number;
2791
+ gap_loss: number;
2792
+ net_profit: number;
2793
+ long: {
2794
+ avg_entry: number;
2795
+ avg_size: number;
2796
+ loss: number;
2797
+ stop: number;
2798
+ stop_quantity: number;
2799
+ re_entry_quantity: number;
2800
+ initial_pnl: number;
2801
+ tp: number;
2802
+ incurred_loss: number;
2803
+ pnl: number;
2804
+ remaining_quantity: number;
2805
+ };
2806
+ short: {
2807
+ avg_entry: number;
2808
+ avg_size: number;
2809
+ loss: number;
2810
+ stop: number;
2811
+ stop_quantity: number;
2812
+ re_entry_quantity: number;
2813
+ initial_pnl: number;
2814
+ tp: number;
2815
+ incurred_loss: number;
2816
+ pnl: number;
2817
+ remaining_quantity: number;
2818
+ };
2819
+ }[]>;
2820
+ getCurrentRun(payload: {
2821
+ symbol: string;
2822
+ kind?: "long" | "short";
2823
+ pnl?: number;
2824
+ }): Promise<true | import("pocketbase").RecordModel>;
2825
+ recomputeSymbolConfig(payload: {
2826
+ symbol: string;
2827
+ refresh?: boolean;
2828
+ }): Promise<SymbolConfig>;
2829
+ /**
2830
+ * This function builds a config for a symbol
2831
+ * @param payload
2832
+ * @returns
2833
+ */
2834
+ buildConfigForSymbol(payload: {
2835
+ symbol: string;
2836
+ risk: number;
2837
+ kind?: "long" | "short";
2838
+ risk_reward?: number;
2839
+ as_config?: boolean;
2840
+ with_trades?: boolean;
2841
+ }): Promise<any>;
2842
+ triggerBullishMarket(payload: {
2843
+ symbol: string;
2844
+ profit_percent?: number;
2845
+ risk_reward?: number;
2846
+ }): Promise<any>;
2847
+ updateAllActiveSymbols(payload: {
2848
+ interval?: number;
2849
+ }): Promise<void>;
2850
+ updateAllPositionsWithNoConfig(payload: {
2851
+ kind: "long" | "short";
2852
+ }): Promise<void>;
2853
+ getSymbolsForPositions(): Promise<any[]>;
2854
+ getNonEssentialSymbols(): Promise<any[]>;
2855
+ _terminatePositions(payload: {
2856
+ symbol: string;
2857
+ }): Promise<void>;
2858
+ getOrders(payload: {
2859
+ symbol: string;
2860
+ kind: "long" | "short";
2861
+ type: "limit" | "stop" | "tp";
2862
+ }): Promise<Order[]>;
2863
+ syncPositionConfigs(payload: {
2864
+ symbol: string;
2865
+ kind: "long" | "short";
2866
+ refresh?: boolean;
2867
+ }): Promise<void>;
2868
+ terminatePositions(payload: {
2869
+ symbol: string;
2870
+ }): Promise<void>;
2871
+ fetchAndUpdateTopMovers(): Promise<{
2872
+ updated_bullish: BullishMarket[];
2873
+ moved_to_winding: WindingDownMarket[];
2874
+ }>;
2875
+ computeTargetPnl(payload: {
2876
+ symbol: string;
2877
+ kind: "long" | "short";
2878
+ }): Promise<number>;
2879
+ placeStopLimit(payload: {
2880
+ symbol: string;
2881
+ kind: "long" | "short";
2882
+ place?: boolean;
2883
+ stop: number;
2884
+ quantity?: number;
2885
+ }): Promise<any>;
2886
+ placeDangerousTrade(payload: {
459
2887
  symbol: string;
2888
+ config: {
2889
+ entry: number;
2890
+ quantity: number;
2891
+ stop: number;
2892
+ };
460
2893
  kind: "long" | "short";
461
- price?: number;
462
- all?: boolean;
463
- stop?: boolean;
464
2894
  }): Promise<{
465
- success: boolean;
466
- message: string;
467
- exchange_result?: undefined;
468
- error?: undefined;
469
- } | {
470
- success: boolean;
471
- exchange_result: any;
472
- message?: undefined;
473
- error?: undefined;
474
- } | {
475
- success: boolean;
476
- error: any;
477
- message?: undefined;
478
- exchange_result?: undefined;
479
- }>;
480
- cancelExchangeOrders(payload: {
481
- symbol: string;
482
- orders: number[];
483
- }): Promise<any>;
484
- buildAppConfig(payload: {
485
2895
  entry: number;
486
- stop: number;
487
- risk_reward: number;
488
2896
  risk: number;
489
- symbol: string;
490
- profit?: number;
491
- update_db?: boolean;
492
- profit_percent?: number;
493
- }): Promise<AppConfig>;
494
- placeConfigOrders(app_config: AppConfig, solution: {
495
- risk_reward: number;
496
- entry: number;
497
2897
  stop: number;
498
- risk_per_trade: number;
499
- avg_size: number;
500
- neg_pnl: number;
501
- min_size: number;
502
- symbol: string;
503
- }, place?: boolean, skip_stop?: boolean): Promise<{
504
- entry_orders: {
505
- orders: {
506
- entry: any;
507
- quantity: any;
508
- reverse_avg_entry: any;
509
- reverse_avg_quantity: any;
510
- avg_entry: any;
511
- avg_size: any;
512
- }[];
513
- kind: "long" | "short";
514
- };
515
- stop_orders: {
516
- stop: number;
517
- final_stop: number;
518
- kind: "long" | "short";
519
- quantity: any;
520
- is_limit: boolean;
2898
+ risk_reward: number | {
2899
+ result: any[];
2900
+ value: number;
2901
+ total: number;
2902
+ risk_per_trade: number;
2903
+ max: number;
2904
+ min: number;
2905
+ neg_pnl: any;
2906
+ entry: any;
521
2907
  };
522
- trades: any[];
523
2908
  }>;
524
- placeSharedOrder(action: "place_limit_orders" | "place_stop_orders" | "place_tp_orders", payload: {
2909
+ placeTrade(payload: {
525
2910
  symbol: string;
526
- entry: number;
527
- stop: number;
528
- risk_reward: number;
529
- risk: number;
2911
+ kind: "long" | "short";
530
2912
  place?: boolean;
531
- update_db?: boolean;
2913
+ limit?: boolean;
2914
+ tp?: boolean;
2915
+ stop?: boolean;
2916
+ raw?: boolean;
2917
+ cancel?: boolean;
2918
+ ignore_config?: boolean;
2919
+ target_pnl?: number;
2920
+ risky?: boolean;
532
2921
  }): Promise<any>;
533
- getPositionConfig(payload: {
2922
+ updateConfigPnl(payload: {
534
2923
  symbol: string;
535
2924
  kind: "long" | "short";
536
- params?: {
537
- entry: number;
538
- stop: number;
539
- risk_reward: number;
540
- risk: number;
541
- profit_percent?: number;
542
- };
543
- }): Promise<ScheduledTrade>;
544
- getCurrentPrice(symbol: string): Promise<any>;
545
- getPositionStrategy(): Promise<{
546
- strategy_instance: Strategy;
547
- focus_account: ExchangeAccount;
2925
+ }): Promise<void>;
2926
+ determineReduceTp(payload: {
2927
+ symbol: string;
2928
+ factor: number;
2929
+ }): Promise<{
2930
+ long_diff: number;
2931
+ short_diff: number;
2932
+ gap: number;
2933
+ gap_cost: number;
2934
+ long_tp: number;
2935
+ short_tp: number;
2936
+ long_percent: number;
2937
+ short_percent: number;
548
2938
  }>;
549
- getOriginalPlannedStop(payload: {
2939
+ oppositeGapExists(payload: {
550
2940
  symbol: string;
551
2941
  kind: "long" | "short";
552
- }): Promise<any>;
553
- syncReduceClosePosition(symbol: string, payload?: {
554
- kind?: "long" | "short";
555
- long?: CodeNode;
556
- short?: CodeNode;
557
- trigger?: {
558
- long: boolean;
559
- short: boolean;
2942
+ }): Promise<void>;
2943
+ profitWithinGapStrategy(payload: {
2944
+ symbol: string;
2945
+ callback?: (params: {
2946
+ symbol: string;
2947
+ account: ExchangeType;
2948
+ kind: "long" | "short";
2949
+ }) => Promise<any>;
2950
+ }): Promise<{
2951
+ config_details: {
2952
+ app_config: {
2953
+ fee: number;
2954
+ risk_per_trade: number;
2955
+ risk_reward: number;
2956
+ symbol?: string;
2957
+ focus: number;
2958
+ budget: number;
2959
+ support: number;
2960
+ resistance: number;
2961
+ percent_change: number;
2962
+ tradeSplit?: number;
2963
+ take_profit?: number;
2964
+ kind: "long" | "short";
2965
+ entry: number;
2966
+ stop: number;
2967
+ min_size: number;
2968
+ price_places?: string;
2969
+ strategy?: "quantity" | "entry";
2970
+ as_array?: boolean;
2971
+ decimal_places?: string;
2972
+ min_profit?: number;
2973
+ raw?: boolean;
2974
+ gap?: number;
2975
+ rr?: number;
2976
+ max_size?: number;
2977
+ max_quantity?: number;
2978
+ kelly?: {
2979
+ use_kelly?: boolean;
2980
+ kelly_confidence_factor?: number;
2981
+ kelly_minimum_risk?: number;
2982
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
2983
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
2984
+ };
2985
+ };
2986
+ last_value: any;
560
2987
  };
561
- }): Promise<any>;
562
- generate_config_params(payload: {
563
- entry: number;
564
- stop: number;
565
- risk_reward: number;
566
- risk: number;
2988
+ }>;
2989
+ generateGapTp(payload: {
567
2990
  symbol: string;
2991
+ factor?: number;
568
2992
  }): Promise<{
569
- place_stop: boolean;
570
- profit_percent: number;
571
- entry: number;
572
- stop: number;
573
- avg_size: any;
574
- avg_entry: any;
575
- risk_reward: number;
576
- neg_pnl: any;
577
- risk: number;
2993
+ profit_percent: {
2994
+ long: number;
2995
+ short: number;
2996
+ };
2997
+ risk: {
2998
+ short: number;
2999
+ long: number;
3000
+ };
3001
+ take_profit: {
3002
+ long: number;
3003
+ short: number;
3004
+ };
3005
+ to_reduce: {
3006
+ short: number;
3007
+ long: number;
3008
+ };
3009
+ full_reduce: {
3010
+ short: number;
3011
+ long: number;
3012
+ };
3013
+ sell_quantity: {
3014
+ short: number;
3015
+ long: number;
3016
+ };
3017
+ gap: number;
3018
+ gap_loss: number;
578
3019
  }>;
579
- extrapolateShortConfig(payload: {
580
- kind: "long" | "short";
3020
+ getSellPriceFromStrategy(payload: {
581
3021
  symbol: string;
582
- risk_reward?: number;
3022
+ reduce_position: PositionsView;
3023
+ kind?: "long" | "short";
3024
+ full_ratio?: number;
583
3025
  }): Promise<{
584
- place_stop: boolean;
3026
+ pnl: number;
3027
+ loss: number;
3028
+ full_loss: number;
3029
+ original_pnl: number;
3030
+ reward_factor: number;
585
3031
  profit_percent: number;
586
- entry: number;
587
- stop: number;
588
- avg_size: any;
589
- avg_entry: any;
590
- risk_reward: number;
591
- neg_pnl: any;
592
- risk: number;
3032
+ kind: "long" | "short";
3033
+ sell_price: number;
3034
+ quantity: number;
3035
+ price_places: string;
3036
+ decimal_places: string;
593
3037
  }>;
594
- triggerTradeFromConfig(payload: {
3038
+ placeCompoundShortTrade(payload: {}): Promise<void>;
3039
+ placeCompoundLongTrade(payload: {
595
3040
  symbol: string;
596
- kind: "long" | "short";
597
- }): Promise<any>;
598
- verifyStopLoss(payload: {
3041
+ params: {
3042
+ resistance: number;
3043
+ support: number;
3044
+ profit_percent: number;
3045
+ risk_reward: number;
3046
+ risk: number;
3047
+ };
3048
+ place?: boolean;
3049
+ }): Promise<void>;
3050
+ getConfigProfiles(payload: {
599
3051
  symbol: string;
600
3052
  kind: "long" | "short";
601
- revert?: boolean;
602
- }): Promise<import("pocketbase").RecordModel[]>;
603
- windDownSymbol(symbol: string, risk_reward?: number): Promise<void>;
604
- triggerBullishMarket(payload: {
605
- symbol: string;
606
- profit_percent?: number;
607
- }): Promise<any>;
3053
+ }): Promise<{
3054
+ id: any;
3055
+ entry: any;
3056
+ stop: any;
3057
+ kind: "long" | "short";
3058
+ risk_reward: any;
3059
+ risk: any;
3060
+ profit_percent: any;
3061
+ }[]>;
608
3062
  }
3063
+ declare function getExchangeAccount(payload: {
3064
+ account: ExchangeType;
3065
+ app_db: AppDatabase;
3066
+ getCredentials: (payload: {
3067
+ account: string;
3068
+ exchange: string;
3069
+ app_db: AppDatabase;
3070
+ }) => Promise<{
3071
+ api_key: string;
3072
+ api_secret: string;
3073
+ email: string;
3074
+ }>;
3075
+ proxyOptions?: {
3076
+ proxy?: any;
3077
+ ignore_proxy?: boolean;
3078
+ };
3079
+ canWithdraw?: boolean;
3080
+ }): Promise<ExchangeAccount$1>;
609
3081
  declare class App {
610
- private app_db;
3082
+ app_db: AppDatabase;
3083
+ proxyOptions?: {
3084
+ proxy?: any;
3085
+ ignore_proxy?: boolean;
3086
+ canWithdraw?: boolean;
3087
+ };
611
3088
  private getCredentials;
612
- constructor(app_db: AppDatabase, getCredentials: (account: string, exchange: string) => (account: string, exchange: string) => Promise<{
3089
+ constructor(app_db: AppDatabase, getCredentials: (payload: {
3090
+ account: string;
3091
+ exchange: string;
3092
+ }) => Promise<{
613
3093
  api_key: string;
614
3094
  api_secret: string;
615
- }>);
3095
+ email: string;
3096
+ }>, proxyOptions?: {
3097
+ proxy?: any;
3098
+ ignore_proxy?: boolean;
3099
+ canWithdraw?: boolean;
3100
+ });
616
3101
  getExchangeAccount(account: ExchangeType): Promise<ExchangeAccount$1>;
617
3102
  syncAccount(payload: {
618
3103
  account: ExchangeType;
@@ -623,6 +3108,8 @@ declare class App {
623
3108
  }): Promise<PositionsView | (PositionsView & {
624
3109
  expand?: {
625
3110
  config: ScheduledTrade;
3111
+ account: ExchangeAccount;
3112
+ proxy: Proxy$1;
626
3113
  };
627
3114
  })[]>;
628
3115
  syncOrders(payload: {
@@ -637,7 +3124,7 @@ declare class App {
637
3124
  price?: number;
638
3125
  all?: boolean;
639
3126
  stop?: boolean;
640
- }): Promise<{
3127
+ }): Promise<any[] | {
641
3128
  success: boolean;
642
3129
  message: string;
643
3130
  exchange_result?: undefined;
@@ -653,39 +3140,6 @@ declare class App {
653
3140
  message?: undefined;
654
3141
  exchange_result?: undefined;
655
3142
  }>;
656
- generateConfig(payload: {
657
- account: ExchangeType;
658
- symbol: string;
659
- kind: "long" | "short";
660
- update_orders?: boolean;
661
- place_orders?: boolean;
662
- }): Promise<any>;
663
- updateReduceRatio(payload: {
664
- account: ExchangeType;
665
- symbol: string;
666
- }): Promise<{
667
- long_position: any;
668
- short_position: any;
669
- long_db_position: any;
670
- short_db_position: any;
671
- balance: any;
672
- }>;
673
- verifyStopLoss(payload: {
674
- account: ExchangeType;
675
- symbol: string;
676
- kind: "long" | "short";
677
- revert?: boolean;
678
- }): Promise<import("pocketbase").RecordModel[]>;
679
- updateTopMovers(payload?: {
680
- new_markets: {
681
- symbol: string;
682
- percent: number;
683
- }[];
684
- totalRisk: number;
685
- }): Promise<{
686
- updated_bullish: BullishMarket[];
687
- moved_to_winding: WindingDownMarket[];
688
- }>;
689
3143
  getWindingDownMarkets(): Promise<WindingDownMarket[]>;
690
3144
  updateSymbolConfigs(payload: {
691
3145
  configs: {
@@ -702,15 +3156,128 @@ declare class App {
702
3156
  created: number;
703
3157
  }>;
704
3158
  updateAllAccountWithSymbols(with_positions?: boolean): Promise<void>;
705
- windDownSymbol(symbol: string): Promise<boolean>;
706
- fetchAndUpdateTopMovers(payload: {
707
- movePercent: number;
3159
+ windDownSymbol(payload: {
3160
+ symbol: string;
3161
+ risk?: number;
3162
+ }): Promise<boolean>;
3163
+ getNonEssentialSymbols(): Promise<Set<any>>;
3164
+ refreshAllPositionsWithSymbol(payload: {
3165
+ symbol: string;
3166
+ callback?: (payload: {
3167
+ symbol: string;
3168
+ account: ExchangeType;
3169
+ }) => Promise<any>;
3170
+ }): Promise<void>;
3171
+ autoFollowPositions(): Promise<void>;
3172
+ getMoverExchangeInstances(): Promise<ExchangeAccount[]>;
3173
+ updateTpOnAllMarkets(callback?: (payload: {
708
3174
  account: ExchangeType;
709
- totalRisk: number;
3175
+ }) => Promise<any>): Promise<void>;
3176
+ triggerMoverTask(payload: {
3177
+ callback: (params: {
3178
+ symbol: string;
3179
+ account: ExchangeType;
3180
+ }) => Promise<any>;
3181
+ removeCallback?: (params: {
3182
+ symbol: string;
3183
+ account: ExchangeType;
3184
+ }) => Promise<any>;
3185
+ }): Promise<void>;
3186
+ placeTrade(payload: {
3187
+ account: ExchangeType;
3188
+ symbol: string;
3189
+ kind: "long" | "short";
3190
+ place?: boolean;
3191
+ tp?: boolean;
3192
+ cancel?: boolean;
3193
+ raw?: boolean;
3194
+ }): Promise<any>;
3195
+ runDbStrategyAccounts(payload: {
3196
+ runningCallback: (params: {
3197
+ symbol: string;
3198
+ account: ExchangeType;
3199
+ }) => Promise<any>;
3200
+ notRunningCallback: (params: {
3201
+ symbol: string;
3202
+ account: ExchangeType;
3203
+ kind: "long" | "short";
3204
+ }) => Promise<any>;
3205
+ }): Promise<void>;
3206
+ profitWithinGapStrategy(payload: {
3207
+ account: ExchangeType;
3208
+ symbol: string;
710
3209
  }): Promise<{
711
- updated_bullish: BullishMarket[];
712
- moved_to_winding: WindingDownMarket[];
3210
+ config_details: {
3211
+ app_config: {
3212
+ fee: number;
3213
+ risk_per_trade: number;
3214
+ risk_reward: number;
3215
+ symbol?: string;
3216
+ focus: number;
3217
+ budget: number;
3218
+ support: number;
3219
+ resistance: number;
3220
+ percent_change: number;
3221
+ tradeSplit?: number;
3222
+ take_profit?: number;
3223
+ kind: "long" | "short";
3224
+ entry: number;
3225
+ stop: number;
3226
+ min_size: number;
3227
+ price_places?: string;
3228
+ strategy?: "quantity" | "entry";
3229
+ as_array?: boolean;
3230
+ decimal_places?: string;
3231
+ min_profit?: number;
3232
+ raw?: boolean;
3233
+ gap?: number;
3234
+ rr?: number;
3235
+ max_size?: number;
3236
+ max_quantity?: number;
3237
+ kelly?: {
3238
+ use_kelly?: boolean;
3239
+ kelly_confidence_factor?: number;
3240
+ kelly_minimum_risk?: number;
3241
+ kelly_prediction_model?: "exponential" | "normal" | "uniform";
3242
+ kelly_func?: "theoretical" | "position_based" | "theoretical_fixed";
3243
+ };
3244
+ };
3245
+ last_value: any;
3246
+ };
3247
+ }>;
3248
+ compoundLongTrade(payload: {
3249
+ main_account: ExchangeType & {
3250
+ symbol: string;
3251
+ };
3252
+ focus_account: ExchangeType & {
3253
+ symbol: string;
3254
+ };
3255
+ place?: boolean;
3256
+ rr?: number;
3257
+ }): Promise<{
3258
+ start_risk: number;
3259
+ short_profit: number;
3260
+ support: number;
3261
+ resistance: number;
3262
+ long_v: any;
3263
+ profit_percent: number;
3264
+ result: any;
3265
+ short_max_size: any;
713
3266
  }>;
3267
+ reduceExistingPosition(payload: {
3268
+ main_account: ExchangeType & {
3269
+ symbol: string;
3270
+ kind?: "long" | "short";
3271
+ };
3272
+ reduce_account: ExchangeType & {
3273
+ symbol: string;
3274
+ };
3275
+ kind: "long" | "short";
3276
+ place?: boolean;
3277
+ increase?: boolean;
3278
+ full_ratio?: number;
3279
+ cancel_limit?: boolean;
3280
+ }): Promise<any>;
714
3281
  }
715
3282
  export declare function initApp(payload: {
716
3283
  db: {
@@ -718,15 +3285,50 @@ export declare function initApp(payload: {
718
3285
  email: string;
719
3286
  password: string;
720
3287
  };
721
- getCredentials: (account: string, exchange: string) => (account: string, exchange: string) => Promise<{
3288
+ password?: string;
3289
+ salt?: string;
3290
+ email?: string;
3291
+ getCredentials: (payload: {
3292
+ account: string;
3293
+ exchange: string;
3294
+ app_db: AppDatabase;
3295
+ }) => Promise<{
722
3296
  api_key: string;
723
3297
  api_secret: string;
3298
+ email: string;
724
3299
  }>;
3300
+ proxy?: any;
3301
+ ignore_proxy?: boolean;
3302
+ canWithdraw?: boolean;
3303
+ triggerToken?: string;
3304
+ }): Promise<App>;
3305
+ declare function getCredentials(payload: {
3306
+ account: string;
3307
+ exchange: string;
3308
+ app_db: AppDatabase;
3309
+ }): Promise<any>;
3310
+ export declare function initialize(payload: {
3311
+ password?: string;
3312
+ proxy?: any;
3313
+ ignore_proxy?: boolean;
3314
+ canWithdraw?: boolean;
725
3315
  }): Promise<App>;
726
- export declare function initialize(): Promise<App>;
3316
+
3317
+ declare namespace database {
3318
+ export { AppDatabase, ExchangeType, decryptObject, encryptObject, initPocketBaseClient };
3319
+ }
3320
+ declare namespace exchange_account {
3321
+ export { ExchangeAccount$1 as ExchangeAccount, getExchangeAccount };
3322
+ }
3323
+ declare namespace app {
3324
+ export { App, getCredentials, initApp, initialize };
3325
+ }
727
3326
 
728
3327
  export {
729
3328
  ExchangeAccount$1 as ExchangeAccount,
3329
+ app,
3330
+ database,
3331
+ exchange_account,
730
3332
  };
731
3333
 
732
3334
  export {};