@gbozee/ultimate 0.0.2-13 → 0.0.2-131

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,232 @@
2
2
 
3
3
  import { HttpsProxyAgent } from 'https-proxy-agent';
4
4
  import PocketBase from 'pocketbase';
5
- import { RecordModel } from 'pocketbase';
5
+ import { RecordModel as PocketBaseRecordModel } from 'pocketbase';
6
6
  import { SocksProxyAgent } from 'socks-proxy-agent';
7
7
 
8
+ export type RecordModel = PocketBaseRecordModel;
9
+ export interface BaseSystemFields {
10
+ id: string;
11
+ created: string;
12
+ updated: string;
13
+ }
14
+ export interface ExchangeAccount extends BaseSystemFields {
15
+ exchange: "binance" | "bybit";
16
+ owner: string;
17
+ email?: string;
18
+ user?: string;
19
+ usdt?: number;
20
+ usdc?: number;
21
+ proxy?: string;
22
+ bullish?: boolean;
23
+ bearish?: boolean;
24
+ movePercent?: number;
25
+ totalRisk?: number;
26
+ max_non_essential?: number;
27
+ profit_percent?: number;
28
+ risk_reward?: number;
29
+ exclude_coins?: {
30
+ bullish?: string[];
31
+ };
32
+ include_delisted?: boolean;
33
+ }
34
+ export interface Order extends BaseSystemFields {
35
+ symbol: string;
36
+ account: string;
37
+ kind: "long" | "short";
38
+ price: number;
39
+ quantity: number;
40
+ side: "sell" | "buy";
41
+ stop: number;
42
+ order_id: string;
43
+ }
44
+ export interface SymbolConfig extends BaseSystemFields {
45
+ symbol: string;
46
+ support?: number;
47
+ resistance?: number;
48
+ stop_percent?: number;
49
+ price_places?: string;
50
+ decimal_places?: string;
51
+ min_size?: number;
52
+ weight?: number;
53
+ leverage?: number;
54
+ candle_count?: number;
55
+ interval?: any;
56
+ fee_percent?: number;
57
+ }
58
+ export interface ScheduledTrade extends BaseSystemFields {
59
+ symbol: string;
60
+ account: string;
61
+ profit?: number;
62
+ risk?: number;
63
+ entry?: number;
64
+ stop?: number;
65
+ risk_reward?: number;
66
+ profit_percent?: number;
67
+ place_tp?: boolean;
68
+ kind?: "long" | "short";
69
+ follow?: boolean | 1 | 0;
70
+ reduce_ratio?: number;
71
+ sell_ratio?: number;
72
+ threshold_qty?: number;
73
+ pause_tp?: boolean;
74
+ }
75
+ export interface AccountStrategy extends BaseSystemFields {
76
+ account: string;
77
+ symbol: string;
78
+ risk?: number;
79
+ reward_factor?: number;
80
+ kind?: "long" | "short";
81
+ support?: number;
82
+ resistance?: number;
83
+ running?: boolean;
84
+ max_reward_factor?: number;
85
+ follow?: boolean;
86
+ risk_reward?: number;
87
+ dynamic?: boolean;
88
+ }
89
+ interface Proxy$1 extends BaseSystemFields {
90
+ ip_address?: string;
91
+ type?: "http" | "socks5";
92
+ }
93
+ export interface TradeBlockTracking extends BaseSystemFields {
94
+ account?: string;
95
+ symbol?: string;
96
+ running?: boolean;
97
+ }
98
+ export interface PositionsView {
99
+ id: string;
100
+ symbol?: any;
101
+ entry?: any;
102
+ quantity?: any;
103
+ take_profit?: any;
104
+ account?: any;
105
+ kind?: any;
106
+ target_pnl?: number;
107
+ liquidation?: number;
108
+ avg_price?: number;
109
+ avg_qty?: number;
110
+ next_order?: number;
111
+ last_order?: number;
112
+ config?: any;
113
+ stop_loss?: {
114
+ price: number;
115
+ quantity: number;
116
+ };
117
+ stop_pnl?: any;
118
+ leverage?: any;
119
+ avg_liquidation?: any;
120
+ balance?: any;
121
+ reduce_ratio?: number;
122
+ sell_ratio?: number;
123
+ threshold_qty?: number;
124
+ follow?: boolean | 1 | 0;
125
+ current_price?: number;
126
+ usd_balance?: number;
127
+ tp?: {
128
+ price: number;
129
+ quantity: number;
130
+ };
131
+ next_risk?: number;
132
+ }
133
+ export interface BullishMarket extends RecordModel {
134
+ id: string;
135
+ symbol: string;
136
+ risk: number;
137
+ }
138
+ export interface WindingDownMarket extends RecordModel {
139
+ id: string;
140
+ symbol: string;
141
+ risk_reward: number;
142
+ }
143
+ export interface BotInstance extends BaseSystemFields {
144
+ asset: string;
145
+ main_account?: string;
146
+ secondary_account?: string;
147
+ main_symbol: string;
148
+ secondary_symbol?: string;
149
+ direction?: "long" | "short";
150
+ budget?: number;
151
+ settings?: Record<string, any>;
152
+ user?: string;
153
+ }
154
+ export interface BotState extends BaseSystemFields {
155
+ bot: string;
156
+ running?: boolean;
157
+ status?: "main-trading" | "hedge-mode";
158
+ spot_quantity?: number;
159
+ exchange_details?: Record<string, any>;
160
+ completed?: boolean;
161
+ }
162
+ export interface BotOrderHistory extends BaseSystemFields {
163
+ field: string;
164
+ symbol: string;
165
+ pnl?: number;
166
+ kind?: "long" | "short";
167
+ type?: "future" | "spot";
168
+ }
169
+ export interface BotPositionData {
170
+ entry: number;
171
+ quantity: number;
172
+ tp: {
173
+ price: number;
174
+ quantity: number;
175
+ pnl: number;
176
+ };
177
+ current_price: number;
178
+ balance: number;
179
+ kind: "long" | "short";
180
+ next_order: number;
181
+ last_order: number;
182
+ avg: {
183
+ price: number;
184
+ quantity: number;
185
+ };
186
+ sl: {
187
+ price: number;
188
+ quantity: number;
189
+ pnl: number;
190
+ };
191
+ }
192
+ export interface BotView extends RecordModel {
193
+ id: string;
194
+ direction?: "long" | "short";
195
+ budget?: number;
196
+ main_symbol?: string;
197
+ main_long_position?: BotPositionData;
198
+ main_short_position?: BotPositionData;
199
+ secondary_symbol?: string;
200
+ secondary_long_position?: BotPositionData;
201
+ secondary_short_position?: BotPositionData;
202
+ main_account?: string;
203
+ secondary_account?: string;
204
+ settings?: Record<string, any>;
205
+ main_long_strategy?: string;
206
+ main_short_strategy?: string;
207
+ secondary_long_strategy?: string;
208
+ secondary_short_strategy?: string;
209
+ }
210
+ export type GlobalConfig = {
211
+ profit_percent: number;
212
+ symbol: string;
213
+ profit: number;
214
+ risk: number;
215
+ stop_percent: number;
216
+ kind: "long" | "short";
217
+ reduce_percent: number;
218
+ support: number;
219
+ resistance: number;
220
+ price_places: string;
221
+ decimal_places: string;
222
+ min_size: number;
223
+ accounts: {
224
+ owner: string;
225
+ exchange?: string;
226
+ }[];
227
+ risk_reward: number;
228
+ reverse_factor: number;
229
+ leverage?: number;
230
+ };
8
231
  interface Position$1 {
9
232
  id: number;
10
233
  kind: "long" | "short";
@@ -59,8 +282,68 @@ export interface Account {
59
282
  short: any;
60
283
  };
61
284
  }
62
- export interface BaseExchange {
285
+ interface Order$1 {
286
+ order_id?: string;
287
+ symbol?: string;
288
+ price: number;
289
+ quantity: number;
290
+ kind: "long" | "short";
291
+ side: "buy" | "sell";
292
+ stop: number;
293
+ triggerPrice?: number;
294
+ }
295
+ export interface CandlestickAnalysisResult {
296
+ candlesticks: {
297
+ [key: string]: any[];
298
+ };
299
+ resistance: {
300
+ [key: string]: number;
301
+ };
302
+ support: {
303
+ [key: string]: number;
304
+ };
305
+ current_price: number;
306
+ minimum_weekly: number;
307
+ }
308
+ declare abstract class BaseExchange {
63
309
  client: any;
310
+ getCredentials: (payload: {
311
+ account: string;
312
+ }) => Promise<{
313
+ api_key: string;
314
+ api_secret: string;
315
+ email: string;
316
+ }>;
317
+ proxyAgent?: any;
318
+ constructor(client: any);
319
+ protected abstract getPositionInfo(symbol: string): Promise<any>;
320
+ abstract cancelAllOrders(symbol: string, payload: {
321
+ type?: "limit" | "stop" | "tp";
322
+ side?: "buy" | "sell";
323
+ kind?: "long" | "short";
324
+ }): Promise<any>;
325
+ protected abstract getCurrentPrice(symbol: string): Promise<any>;
326
+ protected abstract getExchangeInfo(options: {
327
+ price_places?: string;
328
+ decimal_places?: string;
329
+ account: {
330
+ owner: string;
331
+ exchange: string;
332
+ };
333
+ symbol: string;
334
+ }): Promise<any>;
335
+ protected abstract _createLimitPurchaseOrders(payload: {
336
+ symbol: string;
337
+ orders: any[];
338
+ price_places?: string;
339
+ decimal_places?: string;
340
+ }): Promise<any>;
341
+ rawCreateLimitPurchaseOrders(payload: {
342
+ symbol: string;
343
+ orders: Order$1[];
344
+ price_places?: string;
345
+ decimal_places?: string;
346
+ }): Promise<any>;
64
347
  placeStopOrders(payload: {
65
348
  symbol: string;
66
349
  quantity: number;
@@ -71,33 +354,65 @@ export interface BaseExchange {
71
354
  place?: boolean;
72
355
  }): Promise<any>;
73
356
  bulkPlaceLimitOrders(payload: {
74
- orders: any[];
357
+ orders: Order$1[];
75
358
  kind: "long" | "short";
76
359
  decimal_places?: string;
77
360
  price_places?: string;
78
361
  symbol: string;
79
362
  place?: boolean;
80
- }): Promise<any>;
363
+ }): Promise<any[]>;
81
364
  get_current_price(symbol: string): Promise<any>;
82
- analyzeCharts(payload: {
365
+ abstract analyzeCharts(payload: {
83
366
  symbol: string;
84
367
  chartType: any;
85
- count: number;
368
+ limit: number;
86
369
  raw?: boolean;
87
370
  }): Promise<any>;
88
- getExchangeAccountInfo(account: {
89
- owner: string;
90
- exchange: string;
91
- }, symbol: string): Promise<any>;
371
+ getExchangeAccountInfo(options: {
372
+ price_places?: string;
373
+ decimal_places?: string;
374
+ account: {
375
+ owner: string;
376
+ exchange: string;
377
+ };
378
+ symbol: string;
379
+ }): Promise<any>;
380
+ protected abstract _cancelOrders(payload: {
381
+ symbol: string;
382
+ orders: Array<{
383
+ orderId: number;
384
+ }>;
385
+ }): Promise<any>;
92
386
  cancelOrders(payload: {
93
387
  symbol: string;
94
388
  orders: number[];
95
389
  }): Promise<any>;
390
+ protected abstract _placeTpOrder(payload: {
391
+ symbol: string;
392
+ tp: number;
393
+ kind: "long" | "short";
394
+ cancel?: boolean;
395
+ quantity?: number;
396
+ price_places?: string;
397
+ decimal_places?: string;
398
+ }): Promise<any>;
96
399
  placeTpOrder(payload: {
97
400
  symbol: string;
98
401
  take_profit: number;
99
402
  kind: "long" | "short";
100
403
  cancel?: boolean;
404
+ quantity?: number;
405
+ price_places?: string;
406
+ decimal_places?: string;
407
+ }): Promise<any>;
408
+ protected abstract placeLimitOrders(payload: {
409
+ symbol: string;
410
+ orders: Array<{
411
+ entry: number;
412
+ quantity: number;
413
+ }>;
414
+ kind: "long" | "short";
415
+ cancel?: boolean;
101
416
  price_places?: string;
102
417
  decimal_places?: string;
103
418
  }): Promise<any>;
@@ -109,6 +424,18 @@ export interface BaseExchange {
109
424
  price_places?: string;
110
425
  decimal_places?: string;
111
426
  }): Promise<any>;
427
+ protected abstract _placeStopOrder(payload: {
428
+ symbol: string;
429
+ stop: number;
430
+ quantity: number;
431
+ kind: "long" | "short";
432
+ price_places?: string;
433
+ decimal_places?: string;
434
+ final_stop: number;
435
+ cancel?: boolean;
436
+ is_limit?: boolean;
437
+ current_price: number;
438
+ }): Promise<any>;
112
439
  placeStopOrder(payload: {
113
440
  symbol: string;
114
441
  stop: number;
@@ -117,119 +444,137 @@ export interface BaseExchange {
117
444
  price_places?: string;
118
445
  decimal_places?: string;
119
446
  }): Promise<any>;
120
- setLeverage(payload: {
447
+ abstract setLeverage(payload: {
121
448
  symbol: string;
122
449
  leverage: number;
123
450
  }): Promise<any>;
124
- generateConfig(payload: {
451
+ abstract generateConfig(payload: {
125
452
  symbol: string;
453
+ interval?: any;
126
454
  limit?: number;
127
455
  }): Promise<any>;
456
+ abstract checkDelistedMovers(payload: {
457
+ movePercent: number;
458
+ include_delisted?: boolean;
459
+ }): Promise<any>;
460
+ closePosition(payload: {
461
+ symbol: string;
462
+ kind: "long" | "short";
463
+ price_places?: string;
464
+ decimal_places?: string;
465
+ }): Promise<any>;
466
+ protected abstract getAllOpenOrders(): Promise<any>;
467
+ getAllOpenSymbols(): Promise<unknown[]>;
468
+ createLimitPurchaseOrders(payload: {
469
+ orders: any[];
470
+ kind: "long" | "short";
471
+ decimal_places?: string;
472
+ price_places?: string;
473
+ symbol: string;
474
+ }): Promise<any>;
475
+ abstract getDelistedSpotSymbols(): Promise<any>;
476
+ abstract getOpenPositions(): Promise<any>;
477
+ abstract crossAccountTransfer(payload: {
478
+ from: {
479
+ owner: string;
480
+ wallet: string;
481
+ };
482
+ to: {
483
+ owner: string;
484
+ wallet: string;
485
+ };
486
+ asset: string;
487
+ amount: number;
488
+ }): Promise<any>;
489
+ placeMarketOrder(payload: {
490
+ symbol: string;
491
+ kind: "long" | "short";
492
+ quantity: number;
493
+ price_places?: string;
494
+ decimal_places?: string;
495
+ }): Promise<any>;
496
+ customStopLoss(payload: {
497
+ price_places: string;
498
+ decimal_places: string;
499
+ symbol: string;
500
+ kind: "long" | "short";
501
+ stop: number;
502
+ quantity: number;
503
+ increase?: boolean;
504
+ place?: boolean;
505
+ }): Promise<any>;
506
+ abstract getOpenOrders(payload: {
507
+ symbol: string;
508
+ }): Promise<any>;
509
+ placeBadStopEntry(payload: {
510
+ symbol: string;
511
+ orders: Order$1[];
512
+ price_places?: string;
513
+ decimal_places?: string;
514
+ }): Promise<any>;
515
+ analyzeCandlesticks(payload: {
516
+ symbol: string;
517
+ }): Promise<CandlestickAnalysisResult>;
518
+ setAccountDetails(payload: {
519
+ getCredentials: (payload: {
520
+ account: string;
521
+ }) => Promise<{
522
+ api_key: string;
523
+ api_secret: string;
524
+ email: string;
525
+ }>;
526
+ proxyAgent?: any;
527
+ }): void;
128
528
  }
129
- export interface BaseSystemFields {
130
- id: string;
131
- created: string;
132
- updated: string;
133
- }
134
- export interface ExchangeAccount extends BaseSystemFields {
135
- exchange: "binance" | "bybit";
529
+ declare function encryptObject(obj: any, password: string): string;
530
+ declare function decryptObject(encryptedString: string, password: string): any;
531
+ declare function initPocketBaseClient(proxy_credentials: {
532
+ host: string;
533
+ email: string;
534
+ password: string;
535
+ auto_cancellation?: boolean;
536
+ }): Promise<PocketBase>;
537
+ export type ExchangeType = {
136
538
  owner: string;
539
+ exchange: string;
540
+ };
541
+ export declare class AppDatabase {
542
+ pb: PocketBase;
137
543
  email?: string;
138
- user?: string;
139
- usdt?: number;
140
- usdc?: number;
141
- proxy?: string;
142
- }
143
- export interface SymbolConfig extends BaseSystemFields {
144
- symbol: string;
145
- support?: number;
146
- resistance?: number;
147
- stop_percent?: number;
148
- price_places?: string;
149
- decimal_places?: string;
150
- min_size?: number;
151
- weight?: number;
152
- leverage?: number;
153
- }
154
- export interface ScheduledTrade extends BaseSystemFields {
155
- symbol: string;
156
- account: string;
157
- profit?: number;
158
- risk?: number;
159
- entry?: number;
160
- stop?: number;
161
- risk_reward?: number;
162
- profit_percent?: number;
163
- place_tp?: boolean;
164
- kind?: "long" | "short";
165
- current_price?: number;
166
- }
167
- export interface Strategy extends BaseSystemFields {
168
- name: string;
169
- short_risk_factor?: number;
170
- long_risk_factor?: number;
171
- profit_percent?: number;
172
- cancel_short?: boolean;
173
- cancel_long?: boolean;
174
- recompute_short_config?: boolean;
175
- update_stop_loss?: boolean;
176
- liquidation_as_entry?: boolean;
177
- stop_as_entry?: boolean;
178
- tp_as_stop?: boolean;
179
- entry_as_stop?: boolean;
180
- place_stop?: boolean;
181
- save_config?: boolean;
182
- }
183
- interface Proxy$1 extends BaseSystemFields {
184
- ip_address?: string;
185
- type?: "http" | "socks5";
186
- }
187
- export interface TradeBlockTracking extends BaseSystemFields {
188
- account?: string;
189
- symbol?: string;
190
- running?: boolean;
191
- }
192
- export interface PositionsView {
193
- id: string;
194
- symbol?: any;
195
- entry?: any;
196
- quantity?: any;
197
- take_profit?: any;
198
- account?: any;
199
- kind?: any;
200
- target_pnl?: number;
201
- liquidation?: number;
202
- avg_price?: number;
203
- avg_qty?: number;
204
- next_order?: number;
205
- last_order?: number;
206
- config?: any;
207
- stop_loss?: {
208
- price: number;
209
- quantity: number;
210
- };
211
- stop_pnl?: any;
212
- leverage?: any;
213
- avg_liquidation?: any;
214
- balance?: any;
215
- }
216
- export interface BullishMarket extends RecordModel {
217
- id: string;
218
- symbol: string;
219
- risk: number;
220
- }
221
- export interface WindingDownMarket extends RecordModel {
222
- id: string;
223
- symbol: string;
224
- risk_reward: number;
225
- }
226
- export type ExchangeType = {
227
- owner: string;
228
- exchange: string;
229
- };
230
- export declare class AppDatabase {
231
- private pb;
232
- constructor(pb: PocketBase);
544
+ salt?: string;
545
+ constructor(pb: PocketBase, payload: {
546
+ email?: string;
547
+ salt?: string;
548
+ });
549
+ getUserByEmail(): Promise<import("pocketbase").RecordModel>;
550
+ generateUserPassword(): Promise<void>;
551
+ getUserCredentials(): Promise<any>;
552
+ getCredentials(payload: {
553
+ password?: string;
554
+ }): Promise<any>;
555
+ saveCredentials(params: {
556
+ password?: string;
557
+ credentials: any;
558
+ }): Promise<import("pocketbase").RecordModel>;
559
+ changeUserPassword(payload: {
560
+ password: string;
561
+ }): Promise<boolean>;
562
+ addNewCredential(params: {
563
+ password?: string;
564
+ payload: {
565
+ name: string;
566
+ email: string;
567
+ exchange: string;
568
+ api_key: string;
569
+ api_secret: string;
570
+ };
571
+ }): Promise<void>;
572
+ getAccountWithActivePositions(): Promise<import("pocketbase").RecordModel[]>;
573
+ getAllSymbolsFromPositions(options?: {
574
+ no_position?: boolean;
575
+ kind?: "long" | "short";
576
+ custom_filter?: string;
577
+ }): Promise<any[]>;
233
578
  createOrUpdateLiveExchangeInstance(payload: {
234
579
  account: ExchangeType;
235
580
  symbol: string;
@@ -242,18 +587,24 @@ export declare class AppDatabase {
242
587
  }): Promise<import("pocketbase").RecordModel>;
243
588
  getProxyForAccount(account: ExchangeType): Promise<HttpsProxyAgent<`http://${string}`> | SocksProxyAgent>;
244
589
  getAccounts(): Promise<ExchangeAccount[]>;
245
- getAllSymbolConfigs(with_positions?: boolean): Promise<SymbolConfig[]>;
590
+ getAllSymbolConfigs(payload?: {
591
+ with_positions?: boolean;
592
+ custom_filter?: string;
593
+ }): Promise<SymbolConfig[]>;
246
594
  get_exchange_db_instance(account: ExchangeType): Promise<ExchangeAccount & {
247
595
  expand?: {
248
596
  proxy: Proxy$1;
249
597
  };
250
598
  }>;
251
- getPositions(account: ExchangeType, options: {
252
- symbol: string;
599
+ getPositions(options: {
600
+ account?: ExchangeType;
601
+ symbol?: string;
253
602
  as_view?: boolean;
603
+ custom_filter?: string;
254
604
  }): Promise<(PositionsView & {
255
605
  expand?: {
256
606
  config: ScheduledTrade;
607
+ account: ExchangeAccount;
257
608
  };
258
609
  })[]>;
259
610
  private _createOrUpdatePosition;
@@ -265,6 +616,7 @@ export declare class AppDatabase {
265
616
  }): Promise<(PositionsView & {
266
617
  expand?: {
267
618
  config: ScheduledTrade;
619
+ account: ExchangeAccount;
268
620
  };
269
621
  })[]>;
270
622
  update_db_position(position: any, payload: any): Promise<import("pocketbase").RecordModel>;
@@ -276,7 +628,7 @@ export declare class AppDatabase {
276
628
  getOrders(account: ExchangeType, options: {
277
629
  symbol: string;
278
630
  kind: "long" | "short";
279
- }): Promise<import("pocketbase").RecordModel[]>;
631
+ }): Promise<Order[]>;
280
632
  deleteAndRecreateOrders(account: ExchangeType, options: {
281
633
  symbol: string;
282
634
  kind: "long" | "short";
@@ -289,7 +641,33 @@ export declare class AppDatabase {
289
641
  stop: number;
290
642
  order_id: string;
291
643
  triggerPrice?: number;
292
- }>): Promise<import("pocketbase").RecordModel[]>;
644
+ }>): Promise<Order[]>;
645
+ deleteAndBulCreateAllOrders(payload: {
646
+ account: ExchangeType & {
647
+ id: string;
648
+ };
649
+ symbol: string;
650
+ all_orders: Array<{
651
+ symbol: string;
652
+ price: number;
653
+ quantity: number;
654
+ kind: "long" | "short";
655
+ side: "buy" | "sell";
656
+ stop: number;
657
+ order_id: string;
658
+ triggerPrice?: number;
659
+ }>;
660
+ }): Promise<void>;
661
+ cancelLimitOrders(payload: {
662
+ symbol: string;
663
+ kind: "long" | "short";
664
+ account: ExchangeType;
665
+ raw?: boolean;
666
+ cancelExchangeOrders: (payload: {
667
+ symbol: string;
668
+ orders: number[];
669
+ }) => Promise<any>;
670
+ }): Promise<any[]>;
293
671
  cancelOrders(payload: {
294
672
  cancelExchangeOrders: (payload: {
295
673
  symbol: string;
@@ -317,23 +695,60 @@ export declare class AppDatabase {
317
695
  message?: undefined;
318
696
  exchange_result?: undefined;
319
697
  }>;
698
+ getMoverExchangeInstances(): Promise<ExchangeAccount[]>;
699
+ updateScheduledTrade(id: string, payload: any): Promise<import("pocketbase").RecordModel>;
700
+ getPositionsToAutoFollow(): Promise<(Position$1 & {
701
+ expand: {
702
+ account: ExchangeAccount;
703
+ };
704
+ })[]>;
320
705
  createOrUpdatePositionConfig(db_position: any, payload: {
321
706
  entry: number;
322
707
  stop: number;
323
708
  risk_reward: number;
324
709
  risk: number;
325
710
  profit_percent?: number;
326
- }): Promise<void>;
711
+ place_tp?: boolean;
712
+ profit?: number;
713
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
327
714
  getPositionConfig(payload: {
328
715
  symbol: string;
329
716
  kind: "long" | "short";
330
717
  account: ExchangeType;
331
718
  }): Promise<ScheduledTrade | null>;
332
- getPositionStrategy(account: ExchangeType): Promise<{
333
- strategy_instance: Strategy;
334
- focus_account: ExchangeAccount;
335
- }>;
336
- createOrUpdateWindingDownMarket(symbol: string): Promise<import("pocketbase").RecordModel>;
719
+ getRunningAccountStrategies(): Promise<(AccountStrategy & {
720
+ expand?: {
721
+ account: ExchangeAccount;
722
+ };
723
+ })[]>;
724
+ getAccountStrategy(payload: {
725
+ symbol: string;
726
+ account: ExchangeType;
727
+ }): Promise<AccountStrategy>;
728
+ getBotViewInstance(payload: {
729
+ asset: string;
730
+ main_account: ExchangeType;
731
+ }): Promise<BotView | null>;
732
+ getBotInstance(payload: {
733
+ asset: string;
734
+ main_account: ExchangeType;
735
+ }): Promise<BotInstance | null>;
736
+ getBotState(payload: {
737
+ asset: string;
738
+ main_account: ExchangeType;
739
+ running?: boolean;
740
+ }): Promise<BotState[]>;
741
+ getBotOrderHistories(payload: {
742
+ asset: string;
743
+ main_account: ExchangeType;
744
+ symbol?: string;
745
+ kind?: "long" | "short";
746
+ type?: "future" | "spot";
747
+ }): Promise<BotOrderHistory[]>;
748
+ createOrUpdateWindingDownMarket(payload: {
749
+ symbol: string;
750
+ risk_reward?: number;
751
+ }): Promise<import("pocketbase").RecordModel>;
337
752
  getWindingDownMarkets(symbol?: string): Promise<WindingDownMarket[]>;
338
753
  getBullishMarket(symbol: string): Promise<BullishMarket>;
339
754
  getBullishMarkets(options?: {
@@ -342,6 +757,7 @@ export declare class AppDatabase {
342
757
  percent: number;
343
758
  }>;
344
759
  totalRisk: number;
760
+ max_count?: number;
345
761
  }): Promise<{
346
762
  updated_bullish: BullishMarket[];
347
763
  moved_to_winding: WindingDownMarket[];
@@ -362,20 +778,432 @@ export declare class AppDatabase {
362
778
  } | SymbolConfig[]>;
363
779
  unwindSymbolFromDB(symbol: string): Promise<boolean>;
364
780
  hasExistingPosition(symbol: string): Promise<import("pocketbase").RecordModel[]>;
781
+ getPositionWithLowestNextOrder(options: {
782
+ symbol?: string;
783
+ kind: "long" | "short";
784
+ asset?: string;
785
+ exclude?: ExchangeType[];
786
+ }): Promise<PositionsView | null>;
787
+ hasExistingOrders(symbol: string): Promise<import("pocketbase").RecordModel[]>;
365
788
  removeSymbolFromUnwindingMarkets(symbol: string): Promise<boolean>;
366
789
  removePosition(position: any): Promise<void>;
367
790
  removePositionConfig(position: any): Promise<void>;
368
791
  }
369
- export interface CodeNode {
792
+ export type StrategyPosition = {
793
+ entry: number;
794
+ quantity: number;
795
+ avg_price?: number;
796
+ avg_qty?: number;
797
+ };
798
+ export type GapCloserResult = {
799
+ avg_entry: number;
800
+ avg_size: number;
801
+ loss: number;
802
+ stop: number;
803
+ stop_quantity: number;
804
+ re_entry_quantity: number;
805
+ initial_pnl: number;
806
+ tp: number;
807
+ incurred_loss: number;
808
+ pnl: number;
809
+ remaining_quantity: number;
810
+ };
811
+ export type Config = {
812
+ tp_percent: number;
813
+ short_tp_factor: number;
814
+ fee_percent?: number;
815
+ budget: number;
816
+ risk_reward: number;
817
+ reduce_ratio: number;
818
+ global_config: GlobalConfig;
819
+ };
820
+ export declare class Strategy {
821
+ position: {
822
+ long: StrategyPosition;
823
+ short: StrategyPosition;
824
+ };
825
+ dominant_position?: "long" | "short";
826
+ config: Config;
827
+ constructor(payload: {
828
+ long: StrategyPosition;
829
+ short: StrategyPosition;
830
+ config: Config;
831
+ dominant_position?: "long" | "short";
832
+ });
833
+ get price_places(): string;
834
+ get decimal_places(): string;
835
+ to_f(price: number): number;
836
+ to_df(quantity: number): number;
837
+ pnl(kind: "long" | "short", _position?: StrategyPosition): number;
838
+ tp(kind: "long" | "short"): number;
839
+ calculate_fee(position: {
840
+ price: number;
841
+ quantity: number;
842
+ }): number;
843
+ get long_tp(): number;
844
+ get short_tp(): number;
845
+ generateGapClosingAlgorithm(payload: {
846
+ kind: "long" | "short";
847
+ ignore_entries?: boolean;
848
+ reduce_ratio?: number;
849
+ sell_factor?: number;
850
+ }): {
851
+ last_entry: any;
852
+ first_entry: any;
853
+ threshold: any;
854
+ risk: number;
855
+ risk_reward: number;
856
+ spread: number;
857
+ gap_loss: number;
858
+ net_profit: number;
859
+ long: GapCloserResult;
860
+ short: GapCloserResult;
861
+ };
862
+ gapCloserHelper(payload: {
863
+ risk: number;
864
+ entries?: any[];
865
+ kind: "long" | "short";
866
+ sell_factor?: number;
867
+ reduce_ratio?: number;
868
+ }): {
869
+ risk: number;
870
+ risk_reward: number;
871
+ spread: number;
872
+ gap_loss: number;
873
+ net_profit: number;
874
+ long: GapCloserResult;
875
+ short: GapCloserResult;
876
+ };
877
+ runIterations(payload: {
878
+ kind: "long" | "short";
879
+ iterations: number;
880
+ risk_reward?: number;
881
+ ignore_entries?: boolean;
882
+ reduce_ratio?: number;
883
+ sell_factor?: number;
884
+ }): {
885
+ last_entry: any;
886
+ first_entry: any;
887
+ threshold: any;
888
+ risk: number;
889
+ risk_reward: number;
890
+ spread: number;
891
+ gap_loss: number;
892
+ net_profit: number;
893
+ long: GapCloserResult;
894
+ short: GapCloserResult;
895
+ }[];
896
+ getPositionAfterTp(payload: {
897
+ kind: "long" | "short";
898
+ include_fees?: boolean;
899
+ }): {
900
+ [x: string]: number | {
901
+ entry: number;
902
+ quantity: number;
903
+ diff?: undefined;
904
+ } | {
905
+ [x: string]: number;
906
+ diff: number;
907
+ entry?: undefined;
908
+ quantity?: undefined;
909
+ };
910
+ pnl: {
911
+ [x: string]: number;
912
+ diff: number;
913
+ };
914
+ spread: number;
915
+ };
916
+ getPositionAfterIteration(payload: {
917
+ kind: "long" | "short";
918
+ iterations: number;
919
+ with_fees?: boolean;
920
+ }): {
921
+ [x: string]: number | {
922
+ entry: number;
923
+ quantity: number;
924
+ diff?: undefined;
925
+ } | {
926
+ [x: string]: number;
927
+ diff: number;
928
+ entry?: undefined;
929
+ quantity?: undefined;
930
+ };
931
+ pnl: {
932
+ [x: string]: number;
933
+ diff: number;
934
+ };
935
+ spread: number;
936
+ }[];
937
+ /**To be used as one of the agent tools eventually since
938
+ * it is something that can be triggered continously without
939
+ * any risk
940
+ */
941
+ generateOppositeTrades(payload: {
942
+ kind: "long" | "short";
943
+ risk_factor?: number;
944
+ avg_entry?: number;
945
+ }): {
946
+ avg: {
947
+ entry: number;
948
+ price: number;
949
+ quantity: number;
950
+ };
951
+ loss: number;
952
+ profit_percent: number;
953
+ fee: number;
954
+ risk_per_trade: number;
955
+ risk_reward: number;
956
+ symbol?: string;
957
+ focus: number;
958
+ budget: number;
959
+ support: number;
960
+ resistance: number;
961
+ percent_change: number;
962
+ tradeSplit?: number;
963
+ take_profit?: number;
964
+ kind: "long" | "short";
965
+ entry: number;
966
+ stop: number;
967
+ min_size: number;
968
+ price_places?: string;
969
+ strategy?: "quantity" | "entry";
970
+ as_array?: boolean;
971
+ decimal_places?: string;
972
+ min_profit?: number;
973
+ raw?: boolean;
974
+ gap?: number;
975
+ rr?: number;
976
+ max_size?: number;
977
+ max_quantity?: number;
978
+ };
979
+ identifyGapConfig(payload: {
980
+ factor?: number;
981
+ sell_factor?: number;
982
+ kind?: "long" | "short";
983
+ risk?: number;
984
+ }): {
985
+ profit_percent: {
986
+ long: number;
987
+ short: number;
988
+ };
989
+ risk: {
990
+ short: number;
991
+ long: number;
992
+ };
993
+ take_profit: {
994
+ long: number;
995
+ short: number;
996
+ };
997
+ to_reduce: {
998
+ short: number;
999
+ long: number;
1000
+ };
1001
+ full_reduce: {
1002
+ short: number;
1003
+ long: number;
1004
+ };
1005
+ sell_quantity: {
1006
+ short: number;
1007
+ long: number;
1008
+ };
1009
+ gap: number;
1010
+ gap_loss: number;
1011
+ };
1012
+ analyzeProfit(payload: {
1013
+ reward_factor?: number;
1014
+ max_reward_factor: number;
1015
+ risk: number;
1016
+ kind: "long" | "short";
1017
+ }): {
1018
+ pnl: number;
1019
+ loss: number;
1020
+ original_pnl: number;
1021
+ reward_factor: number;
1022
+ profit_percent: number;
1023
+ kind: "long" | "short";
1024
+ sell_price: number;
1025
+ quantity: number;
1026
+ price_places: string;
1027
+ decimal_places: string;
1028
+ };
1029
+ simulateGapReduction(payload: {
1030
+ iterations?: number;
1031
+ factor?: number;
1032
+ direction: "long" | "short";
1033
+ kind?: "long" | "short";
1034
+ risk?: number;
1035
+ sell_factor?: number;
1036
+ }): {
1037
+ results: {
1038
+ profit_percent: {
1039
+ long: number;
1040
+ short: number;
1041
+ };
1042
+ risk: {
1043
+ short: number;
1044
+ long: number;
1045
+ };
1046
+ take_profit: {
1047
+ long: number;
1048
+ short: number;
1049
+ };
1050
+ sell_quantity: {
1051
+ short: number;
1052
+ long: number;
1053
+ };
1054
+ gap_loss: number;
1055
+ position: {
1056
+ long: {
1057
+ entry: number;
1058
+ quantity: number;
1059
+ };
1060
+ short: {
1061
+ entry: number;
1062
+ quantity: number;
1063
+ };
1064
+ };
1065
+ }[];
1066
+ quantity: number;
1067
+ };
1068
+ }
1069
+ export type SignalConfigType = {
1070
+ focus: number;
1071
+ budget: number;
1072
+ percent_change?: number;
1073
+ price_places?: string;
1074
+ decimal_places?: string;
1075
+ zone_risk?: number;
1076
+ fee?: number;
1077
+ support?: number;
1078
+ risk_reward?: number;
1079
+ resistance?: number;
1080
+ risk_per_trade?: number;
1081
+ increase_size?: boolean;
1082
+ additional_increase?: number;
1083
+ minimum_pnl?: number;
1084
+ take_profit?: number;
1085
+ increase_position?: boolean;
1086
+ minimum_size?: number;
1087
+ first_order_size?: number;
1088
+ gap?: number;
1089
+ max_size?: number;
1090
+ };
1091
+ declare class Signal {
1092
+ focus: number;
1093
+ budget: number;
1094
+ percent_change: number;
1095
+ price_places: string;
1096
+ decimal_places: string;
1097
+ zone_risk: number;
1098
+ fee: number;
1099
+ support?: number;
1100
+ risk_reward: number;
1101
+ resistance?: number;
1102
+ risk_per_trade?: number;
1103
+ increase_size: boolean;
1104
+ additional_increase: number;
370
1105
  minimum_pnl: number;
1106
+ take_profit?: number;
1107
+ increase_position: boolean;
1108
+ minimum_size: any;
1109
+ first_order_size: number;
1110
+ gap: number;
371
1111
  max_size: number;
372
- profit: number;
373
- ratio?: number;
374
- increase: boolean;
375
- not_reduce?: boolean;
376
- reduce_ratio?: number;
377
- use_full?: boolean;
1112
+ constructor({ focus, budget, percent_change, price_places, decimal_places, zone_risk, fee, support, risk_reward, resistance, risk_per_trade, increase_size, additional_increase, minimum_pnl, take_profit, increase_position, minimum_size, first_order_size, gap, max_size, }: SignalConfigType);
1113
+ build_entry({ current_price, stop_loss, pnl, stop_percent, kind, risk, no_of_trades, take_profit, }: {
1114
+ take_profit?: number;
1115
+ no_of_trades?: number;
1116
+ current_price: number;
1117
+ stop_loss?: number;
1118
+ kind?: "long" | "short";
1119
+ risk: number;
1120
+ stop_percent?: number;
1121
+ pnl?: number;
1122
+ }): any;
1123
+ get risk(): number;
1124
+ get min_trades(): number;
1125
+ get min_price(): number;
1126
+ build_opposite_order({ current_price, kind, }: {
1127
+ current_price: number;
1128
+ kind?: "long" | "short";
1129
+ }): any;
1130
+ special_build_orders({ current_price, kind, }: {
1131
+ current_price: number;
1132
+ kind?: "long" | "short";
1133
+ }): any;
1134
+ build_orders({ current_price, kind, limit, replace_focus, max_index, min_index, }: {
1135
+ current_price: number;
1136
+ kind?: "long" | "short";
1137
+ limit?: boolean;
1138
+ replace_focus?: boolean;
1139
+ max_index?: number;
1140
+ min_index?: number;
1141
+ }): any;
1142
+ build_orders_old({ current_price, kind, limit, replace_focus, max_index, min_index, }: {
1143
+ current_price: number;
1144
+ kind?: "long" | "short";
1145
+ limit?: boolean;
1146
+ replace_focus?: boolean;
1147
+ max_index?: number;
1148
+ min_index?: number;
1149
+ }): any;
1150
+ get_bulk_trade_zones({ current_price, kind, limit, }: {
1151
+ current_price: number;
1152
+ kind?: "long" | "short";
1153
+ limit?: boolean;
1154
+ }): any;
1155
+ get_future_zones({ current_price, kind, raw, }: {
1156
+ raw?: boolean;
1157
+ current_price: number;
1158
+ kind?: "long" | "short";
1159
+ }): number[];
1160
+ to_f(value: number, places?: string): number;
1161
+ get_margin_zones({ current_price, kind, }: {
1162
+ current_price: number;
1163
+ kind?: "long" | "short";
1164
+ }): number[][];
1165
+ get_margin_range(current_price: number, kind?: string): number[];
1166
+ process_orders({ current_price, stop_loss, trade_zones, kind, }: {
1167
+ current_price: number;
1168
+ stop_loss: number;
1169
+ trade_zones: number[];
1170
+ kind?: "long" | "short";
1171
+ }): any[];
1172
+ get_risk_per_trade(number_of_orders: number): number;
1173
+ build_trade_dict({ entry, stop, risk, arr, index, new_fees, kind, start, take_profit, }: {
1174
+ entry: number;
1175
+ stop: number;
1176
+ risk: number;
1177
+ arr: number[];
1178
+ index: number;
1179
+ new_fees?: number;
1180
+ kind?: "long" | "short";
1181
+ start?: number;
1182
+ take_profit?: number;
1183
+ }): {
1184
+ entry: number;
1185
+ risk: number;
1186
+ quantity: number;
1187
+ sell_price: number;
1188
+ risk_sell: number;
1189
+ stop: number;
1190
+ pnl: number;
1191
+ fee: number;
1192
+ net: number;
1193
+ incurred: number;
1194
+ stop_percent: number;
1195
+ };
1196
+ to_df(currentPrice: number, places?: string): number;
378
1197
  }
1198
+ export declare function determine_average_entry_and_size(orders: Array<{
1199
+ price: number;
1200
+ quantity: number;
1201
+ }>, places?: string, price_places?: string): {
1202
+ entry: number;
1203
+ price: number;
1204
+ quantity: number;
1205
+ };
1206
+ export declare const createArray: (start: number, stop: number, step: number) => number[];
379
1207
  export type AppConfig = {
380
1208
  fee: number;
381
1209
  risk_per_trade: number;
@@ -401,27 +1229,502 @@ export type AppConfig = {
401
1229
  gap?: number;
402
1230
  rr?: number;
403
1231
  max_size?: number;
1232
+ last_value?: any;
1233
+ entries?: any[];
1234
+ max_quantity?: number;
404
1235
  };
405
- declare class ExchangeAccount$1 {
406
- private instance;
407
- private exchange;
408
- private app_db;
409
- constructor(payload: ExchangeType, options: {
410
- exchange: BaseExchange;
411
- app_db: AppDatabase;
412
- });
413
- /**
414
- *In order to avoid rate limiting issues, we cache the live exchange
415
- details for each symbol for an account in the database with an option
416
- to refresh.
417
- */
418
- getLiveExchangeInstance(payload: {
1236
+ export type ExtendConfigType = {
1237
+ take_profit?: number;
1238
+ entry: number;
1239
+ risk?: number;
1240
+ stop?: number;
1241
+ risk_reward?: number;
1242
+ raw_instance?: boolean;
1243
+ no_of_trades?: number;
1244
+ increase?: boolean;
1245
+ price_places?: string;
1246
+ decimal_places?: string;
1247
+ min_profit?: number;
1248
+ kind?: "long" | "short";
1249
+ gap?: number;
1250
+ rr?: number;
1251
+ };
1252
+ export declare function buildConfig(app_config: AppConfig, { take_profit, entry, stop, raw_instance, risk, no_of_trades, min_profit, risk_reward, kind, increase, gap, rr, price_places, decimal_places, }: ExtendConfigType): any[] | Signal;
1253
+ export declare function buildAvg({ _trades, kind, }: {
1254
+ _trades: any[];
1255
+ kind: "long" | "short";
1256
+ }): any;
1257
+ export declare function sortedBuildConfig(app_config: AppConfig, options: any): any[];
1258
+ export declare function get_app_config_and_max_size(config: GlobalConfig, payload: {
1259
+ entry: number;
1260
+ stop: number;
1261
+ kind: "long" | "short";
1262
+ }): {
1263
+ app_config: AppConfig;
1264
+ max_size: any;
1265
+ last_value: any;
1266
+ entries: {
1267
+ entry: any;
1268
+ avg_entry: any;
1269
+ avg_size: any;
1270
+ neg_pnl: any;
1271
+ quantity: any;
1272
+ }[];
1273
+ };
1274
+ export declare function buildAppConfig(config: GlobalConfig, payload: {
1275
+ entry: number;
1276
+ stop: number;
1277
+ risk_reward: number;
1278
+ risk: number;
1279
+ symbol: string;
1280
+ profit?: number;
1281
+ }): AppConfig;
1282
+ export declare function getOptimumStopAndRisk(app_config: AppConfig, params: {
1283
+ max_size: number;
1284
+ target_stop: number;
1285
+ highest_risk?: number;
1286
+ }): {
1287
+ optimal_stop: number;
1288
+ optimal_risk: number;
1289
+ avg_size: any;
1290
+ avg_entry: any;
1291
+ result: any[];
1292
+ first_entry: any;
1293
+ neg_pnl: any;
1294
+ risk_reward: number;
1295
+ size_diff: number;
1296
+ entry_diff: number;
1297
+ };
1298
+ export declare function generate_config_params(app_config: AppConfig, payload: {
1299
+ entry: number;
1300
+ stop: number;
1301
+ risk_reward: number;
1302
+ risk: number;
1303
+ symbol: string;
1304
+ }): {
1305
+ entry: number;
1306
+ stop: number;
1307
+ avg_size: any;
1308
+ avg_entry: any;
1309
+ risk_reward: number;
1310
+ neg_pnl: any;
1311
+ risk: number;
1312
+ };
1313
+ export declare function determine_break_even_price(payload: {
1314
+ long_position: {
1315
+ entry: number;
1316
+ quantity: number;
1317
+ };
1318
+ short_position: {
1319
+ entry: number;
1320
+ quantity: number;
1321
+ };
1322
+ fee_percent?: number;
1323
+ }): {
1324
+ price: number;
1325
+ direction: string;
1326
+ };
1327
+ export declare function determine_amount_to_buy(payload: {
1328
+ orders: any[];
1329
+ kind: "long" | "short";
1330
+ decimal_places?: string;
1331
+ price_places?: string;
1332
+ place?: boolean;
1333
+ position: any;
1334
+ existingOrders: any[];
1335
+ }): any[];
1336
+ export declare function generateOptimumAppConfig(config: GlobalConfig, payload: {
1337
+ entry: number;
1338
+ stop: number;
1339
+ risk_reward: number;
1340
+ start_risk: number;
1341
+ max_risk?: number;
1342
+ }, position: {
1343
+ entry: number;
1344
+ quantity: number;
1345
+ kind: "long" | "short";
1346
+ }): AppConfig | null;
1347
+ export declare function determineOptimumReward(app_config: AppConfig, increase?: boolean, low_range?: number, high_range?: number): number | {
1348
+ result: any[];
1349
+ value: number;
1350
+ total: number;
1351
+ risk_per_trade: number;
1352
+ max: number;
1353
+ min: number;
1354
+ neg_pnl: any;
1355
+ entry: any;
1356
+ };
1357
+ export declare function determineOptimumRisk(config: GlobalConfig, payload: {
1358
+ entry: number;
1359
+ stop: number;
1360
+ risk_reward: number;
1361
+ risk: number;
1362
+ symbol: string;
1363
+ }, params: {
1364
+ highest_risk: number;
1365
+ tolerance?: number;
1366
+ max_iterations?: number;
1367
+ }): {
1368
+ optimal_risk: number;
1369
+ achieved_neg_pnl: number;
1370
+ target_neg_pnl: number;
1371
+ difference: number;
1372
+ iterations: number;
1373
+ converged: boolean;
1374
+ last_value: any;
1375
+ entries: any[];
1376
+ app_config: AppConfig;
1377
+ };
1378
+ export declare function computeRiskReward(payload: {
1379
+ app_config: AppConfig;
1380
+ entry: number;
1381
+ stop: number;
1382
+ risk_per_trade: number;
1383
+ }): number | {
1384
+ result: any[];
1385
+ value: number;
1386
+ total: number;
1387
+ risk_per_trade: number;
1388
+ max: number;
1389
+ min: number;
1390
+ neg_pnl: any;
1391
+ entry: any;
1392
+ };
1393
+ export declare function getRiskReward(payload: {
1394
+ entry: number;
1395
+ stop: number;
1396
+ risk: number;
1397
+ global_config: GlobalConfig;
1398
+ force_exact_risk?: boolean;
1399
+ }): any;
1400
+ export declare function computeProfitDetail(payload: {
1401
+ focus_position: {
1402
+ kind: "long" | "short";
1403
+ entry: number;
1404
+ quantity: number;
1405
+ avg_qty: number;
1406
+ avg_price: number;
1407
+ };
1408
+ strategy: {
1409
+ reward_factor: number;
1410
+ max_reward_factor: number;
1411
+ risk: number;
1412
+ };
1413
+ pnl: number;
1414
+ reduce_position?: {
1415
+ kind: "long" | "short";
1416
+ entry: number;
1417
+ quantity: number;
1418
+ avg_qty: number;
1419
+ avg_price: number;
1420
+ };
1421
+ reverse_position?: {
1422
+ kind: "long" | "short";
1423
+ avg_qty: number;
1424
+ avg_price: number;
1425
+ stop_loss: {
1426
+ price: number;
1427
+ quantity: number;
1428
+ };
1429
+ };
1430
+ price_places?: string;
1431
+ decimal_places?: string;
1432
+ }): {
1433
+ pnl: number;
1434
+ loss: number;
1435
+ original_pnl: number;
1436
+ reward_factor: number;
1437
+ profit_percent: number;
1438
+ kind: "long" | "short";
1439
+ sell_price: number;
1440
+ quantity: number;
1441
+ price_places: string;
1442
+ decimal_places: string;
1443
+ };
1444
+ export declare function generateGapTp(payload: {
1445
+ long: {
1446
+ entry: number;
1447
+ quantity: number;
1448
+ };
1449
+ short: {
1450
+ entry: number;
1451
+ quantity: number;
1452
+ };
1453
+ risk?: number;
1454
+ kind?: "long" | "short";
1455
+ factor?: number;
1456
+ sell_factor?: number;
1457
+ price_places?: string;
1458
+ decimal_places?: string;
1459
+ }): {
1460
+ profit_percent: {
1461
+ long: number;
1462
+ short: number;
1463
+ };
1464
+ risk: {
1465
+ short: number;
1466
+ long: number;
1467
+ };
1468
+ take_profit: {
1469
+ long: number;
1470
+ short: number;
1471
+ };
1472
+ to_reduce: {
1473
+ short: number;
1474
+ long: number;
1475
+ };
1476
+ full_reduce: {
1477
+ short: number;
1478
+ long: number;
1479
+ };
1480
+ sell_quantity: {
1481
+ short: number;
1482
+ long: number;
1483
+ };
1484
+ gap: number;
1485
+ gap_loss: number;
1486
+ };
1487
+ export declare function determineRewardFactor(payload: {
1488
+ quantity: number;
1489
+ avg_qty: number;
1490
+ minimum_pnl: number;
1491
+ risk: number;
1492
+ }): number;
1493
+ export type BotPosition = {
1494
+ kind: "long" | "short";
1495
+ entry: number;
1496
+ quantity: number;
1497
+ tp: {
1498
+ price: number;
1499
+ };
1500
+ };
1501
+ export declare function getHedgeZone(payload: {
1502
+ symbol_config: GlobalConfig;
1503
+ risk: number;
1504
+ position: BotPosition;
1505
+ reward_factor?: number;
1506
+ risk_factor?: number;
1507
+ support?: number;
1508
+ }): {
1509
+ support: number;
1510
+ resistance: number;
1511
+ risk: number;
1512
+ profit_percent: number;
1513
+ };
1514
+ export declare function getOptimumHedgeFactor(payload: {
1515
+ target_support: number;
1516
+ tolerance?: number;
1517
+ max_iterations?: number;
1518
+ min_factor?: number;
1519
+ max_factor?: number;
1520
+ symbol_config: GlobalConfig;
1521
+ risk: number;
1522
+ position: BotPosition;
1523
+ }): {
1524
+ reward_factor: number;
1525
+ achieved_support: number;
1526
+ target_support: number;
1527
+ difference: number;
1528
+ iterations: number;
1529
+ converged?: undefined;
1530
+ } | {
1531
+ reward_factor: number;
1532
+ achieved_support: number;
1533
+ target_support: number;
1534
+ difference: number;
1535
+ iterations: number;
1536
+ converged: boolean;
1537
+ };
1538
+ export type CType = {
1539
+ next_order: number;
1540
+ take_profit: number;
1541
+ };
1542
+ export declare function determineCompoundLongTrade(payload: {
1543
+ focus_short_position: CType;
1544
+ focus_long_position: CType;
1545
+ shortConfig: {
1546
+ entry: number;
1547
+ stop: number;
1548
+ risk_reward: number;
1549
+ risk: number;
419
1550
  symbol: string;
1551
+ profit_percent: number;
1552
+ };
1553
+ rr?: number;
1554
+ global_config: GlobalConfig;
1555
+ }): {
1556
+ start_risk: number;
1557
+ short_profit: number;
1558
+ support: number;
1559
+ resistance: number;
1560
+ long_v: any;
1561
+ profit_percent: number;
1562
+ result: any;
1563
+ short_max_size: any;
1564
+ };
1565
+ declare class ExchangePosition {
1566
+ exchange: BaseExchange;
1567
+ exchange_account: ExchangeAccount$1;
1568
+ private app_db;
1569
+ private instance;
1570
+ constructor(payload: {
1571
+ exchange: BaseExchange;
1572
+ app_db: AppDatabase;
1573
+ instance: PositionsView;
1574
+ exchange_account: ExchangeAccount$1;
1575
+ without_view?: PositionsView;
1576
+ });
1577
+ get symbol(): any;
1578
+ get kind(): any;
1579
+ get account(): any;
1580
+ cancelOrders(payload: {
1581
+ limit?: boolean;
1582
+ price?: number;
1583
+ }): Promise<any[] | {
1584
+ success: boolean;
1585
+ message: string;
1586
+ exchange_result?: undefined;
1587
+ error?: undefined;
1588
+ } | {
1589
+ success: boolean;
1590
+ exchange_result: any;
1591
+ message?: undefined;
1592
+ error?: undefined;
1593
+ } | {
1594
+ success: boolean;
1595
+ error: any;
1596
+ message?: undefined;
1597
+ exchange_result?: undefined;
1598
+ }>;
1599
+ getConfig(payload?: {
1600
+ params?: {
1601
+ entry?: number;
1602
+ stop?: number;
1603
+ risk_reward?: number;
1604
+ risk?: number;
1605
+ profit_percent?: number;
1606
+ place_tp?: boolean;
1607
+ profit?: number;
1608
+ };
1609
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
1610
+ updateTargetPnl(): Promise<number>;
1611
+ updateConfigPnl(): Promise<void>;
1612
+ triggerTradeFromConfig(payload: {
1613
+ place?: boolean;
1614
+ raw?: boolean;
1615
+ tp?: boolean;
1616
+ stop?: boolean;
1617
+ use_current?: boolean;
1618
+ ignore_config?: boolean;
1619
+ }): Promise<any>;
1620
+ placeSharedOrder(action: "place_limit_orders" | "place_stop_orders" | "place_tp_orders", payload: {
1621
+ entry: number;
1622
+ stop: number;
1623
+ risk_reward: number;
1624
+ risk: number;
1625
+ place?: boolean;
1626
+ update_db?: boolean;
1627
+ raw?: boolean;
1628
+ use_current?: boolean;
1629
+ }): Promise<any>;
1630
+ buildAppConfig(payload: {
1631
+ entry: number;
1632
+ stop: number;
1633
+ risk_reward: number;
1634
+ risk: number;
1635
+ profit?: number;
1636
+ update_db?: boolean;
1637
+ profit_percent?: number;
1638
+ }): Promise<AppConfig>;
1639
+ placeConfigOrders(app_config: AppConfig, solution: {
1640
+ risk_reward: number;
1641
+ entry: number;
1642
+ stop: number;
1643
+ risk_per_trade: number;
1644
+ avg_size: number;
1645
+ neg_pnl: number;
1646
+ min_size: number;
1647
+ symbol: string;
1648
+ }, place?: boolean, skip_stop?: boolean): Promise<{
1649
+ entry_orders: {
1650
+ orders: {
1651
+ entry: any;
1652
+ quantity: any;
1653
+ reverse_avg_entry: any;
1654
+ reverse_avg_quantity: any;
1655
+ avg_entry: any;
1656
+ avg_size: any;
1657
+ }[];
1658
+ kind: "long" | "short";
1659
+ };
1660
+ stop_orders: {
1661
+ stop: number;
1662
+ final_stop: number;
1663
+ kind: "long" | "short";
1664
+ quantity: any;
1665
+ is_limit: boolean;
1666
+ neg_pnl: any;
1667
+ };
1668
+ trades: any[];
1669
+ }>;
1670
+ determineAmountToBuy(payload: {
1671
+ orders: any[];
1672
+ kind: "long" | "short";
420
1673
  refresh?: boolean;
421
- price_places?: string;
422
1674
  decimal_places?: string;
1675
+ price_places?: string;
1676
+ cancel?: boolean;
1677
+ place?: boolean;
1678
+ }): Promise<any[]>;
1679
+ refresh(live_refresh?: boolean): Promise<{
1680
+ instance: PositionsView;
1681
+ existingOrders: void | Order[];
1682
+ }>;
1683
+ placeTrade(payload: {
1684
+ place?: boolean;
1685
+ tp?: boolean;
1686
+ stop?: boolean;
1687
+ raw?: boolean;
1688
+ cancel?: boolean;
1689
+ ignore_config?: boolean;
1690
+ }): Promise<any>;
1691
+ }
1692
+ declare class ExchangeAccount$1 {
1693
+ instance: {
1694
+ owner: string;
1695
+ exchange: string;
1696
+ };
1697
+ exchange: BaseExchange;
1698
+ main_exchange?: BaseExchange;
1699
+ private app_db;
1700
+ private long_position?;
1701
+ private short_position?;
1702
+ constructor(payload: ExchangeType, options: {
1703
+ exchange: BaseExchange;
1704
+ app_db: AppDatabase;
1705
+ main_exchange?: BaseExchange;
1706
+ });
1707
+ /**
1708
+ *In order to avoid rate limiting issues, we cache the live exchange
1709
+ details for each symbol for an account in the database with an option
1710
+ to refresh.
1711
+ */
1712
+ getDBInstance(): AppDatabase;
1713
+ getLiveExchangeInstance(payload: {
1714
+ symbol: string;
1715
+ refresh?: boolean;
1716
+ refresh_symbol_config?: boolean;
423
1717
  }): Promise<import("pocketbase").RecordModel>;
424
- getActiveAccount(symbol: string, full?: boolean): Promise<Account | {
1718
+ initializePositions(payload: {
1719
+ symbol: string;
1720
+ as_view?: boolean;
1721
+ kind: "long" | "short";
1722
+ }): Promise<ExchangePosition>;
1723
+ getActiveAccount(payload: {
1724
+ symbol: string;
1725
+ full?: boolean;
1726
+ refresh?: boolean;
1727
+ }): Promise<Account | {
425
1728
  liquidation: {
426
1729
  long: number;
427
1730
  short: number;
@@ -430,23 +1733,35 @@ declare class ExchangeAccount$1 {
430
1733
  current_price: any;
431
1734
  exchange: any;
432
1735
  }>;
1736
+ refreshAccount(payload: {
1737
+ symbol: string;
1738
+ live_refresh?: boolean;
1739
+ leverage?: number;
1740
+ }): Promise<(PositionsView & {
1741
+ expand?: {
1742
+ config: ScheduledTrade;
1743
+ account: ExchangeAccount;
1744
+ };
1745
+ })[]>;
433
1746
  syncAccount(options: {
434
1747
  symbol: string;
435
1748
  kind?: "long" | "short";
436
1749
  update?: boolean;
437
1750
  as_view?: boolean;
438
1751
  leverage?: number;
1752
+ live_refresh?: boolean;
439
1753
  }): Promise<PositionsView | (PositionsView & {
440
1754
  expand?: {
441
1755
  config: ScheduledTrade;
1756
+ account: ExchangeAccount;
442
1757
  };
443
1758
  })[]>;
444
1759
  getRunningInstanceFromDB(symbol: string): Promise<TradeBlockTracking>;
445
1760
  syncOrders(options: {
446
1761
  symbol: string;
447
- kind: "long" | "short";
1762
+ kind?: "long" | "short";
448
1763
  update?: boolean;
449
- }): Promise<import("pocketbase").RecordModel[]>;
1764
+ }): Promise<void | Order[]>;
450
1765
  toggleStopBuying(payload: {
451
1766
  symbol: string;
452
1767
  kind: "long" | "short";
@@ -458,7 +1773,9 @@ declare class ExchangeAccount$1 {
458
1773
  price?: number;
459
1774
  all?: boolean;
460
1775
  stop?: boolean;
461
- }): Promise<{
1776
+ limit?: boolean;
1777
+ raw?: boolean;
1778
+ }): Promise<any[] | {
462
1779
  success: boolean;
463
1780
  message: string;
464
1781
  exchange_result?: undefined;
@@ -478,135 +1795,658 @@ declare class ExchangeAccount$1 {
478
1795
  symbol: string;
479
1796
  orders: number[];
480
1797
  }): Promise<any>;
1798
+ getBreakEvenPrice(payload: {
1799
+ symbol: string;
1800
+ }): Promise<{
1801
+ price: number;
1802
+ direction: string;
1803
+ }>;
481
1804
  buildAppConfig(payload: {
482
1805
  entry: number;
483
1806
  stop: number;
484
1807
  risk_reward: number;
485
1808
  risk: number;
486
1809
  symbol: string;
487
- profit?: number;
488
- update_db?: boolean;
489
- profit_percent?: number;
490
- }): Promise<AppConfig>;
491
- placeConfigOrders(app_config: AppConfig, solution: {
1810
+ profit?: number;
1811
+ update_db?: boolean;
1812
+ profit_percent?: number;
1813
+ }): Promise<AppConfig>;
1814
+ tradeConfig(payload: {
1815
+ symbol: string;
1816
+ kind: "long" | "short";
1817
+ }): Promise<AppConfig>;
1818
+ justInTimeProfit(payload: {
1819
+ symbol: string;
1820
+ target_pnl: number;
1821
+ kind: "long" | "short";
1822
+ refresh?: boolean;
1823
+ place?: boolean;
1824
+ take_profit?: number;
1825
+ pause_tp?: boolean;
1826
+ }): Promise<{
1827
+ sell_ratio: number;
1828
+ current_pnl: number;
1829
+ profit_percent: number;
1830
+ current_price: number;
1831
+ notional_value: number;
1832
+ }>;
1833
+ buildTrades(payload: {
1834
+ symbol: string;
1835
+ kind: "long" | "short";
1836
+ risk?: number;
1837
+ }): Promise<{
1838
+ trades: any[];
1839
+ max_size: any;
1840
+ last_price: any;
1841
+ total_size: number;
1842
+ avg_entry: number;
1843
+ }>;
1844
+ placeConfigOrders(app_config: AppConfig, solution: {
1845
+ risk_reward: number;
1846
+ entry: number;
1847
+ stop: number;
1848
+ risk_per_trade: number;
1849
+ avg_size: number;
1850
+ neg_pnl: number;
1851
+ min_size: number;
1852
+ symbol: string;
1853
+ }, place?: boolean, skip_stop?: boolean): Promise<{
1854
+ entry_orders: {
1855
+ orders: {
1856
+ entry: any;
1857
+ quantity: any;
1858
+ reverse_avg_entry: any;
1859
+ reverse_avg_quantity: any;
1860
+ avg_entry: any;
1861
+ avg_size: any;
1862
+ }[];
1863
+ kind: "long" | "short";
1864
+ };
1865
+ stop_orders: {
1866
+ stop: number;
1867
+ final_stop: number;
1868
+ kind: "long" | "short";
1869
+ quantity: any;
1870
+ is_limit: boolean;
1871
+ neg_pnl: any;
1872
+ };
1873
+ trades: any[];
1874
+ }>;
1875
+ determineAmountToBuy(payload: {
1876
+ orders: any[];
1877
+ kind: "long" | "short";
1878
+ refresh?: boolean;
1879
+ decimal_places?: string;
1880
+ price_places?: string;
1881
+ symbol: string;
1882
+ cancel?: boolean;
1883
+ place?: boolean;
1884
+ }): Promise<any[]>;
1885
+ placeSharedOrder(action: "place_limit_orders" | "place_stop_orders" | "place_tp_orders", payload: {
1886
+ symbol: string;
1887
+ entry: number;
1888
+ stop: number;
1889
+ risk_reward: number;
1890
+ risk: number;
1891
+ place?: boolean;
1892
+ update_db?: boolean;
1893
+ raw?: boolean;
1894
+ use_current?: boolean;
1895
+ }): Promise<any>;
1896
+ getOrCreatePositionConfig(payload: {
1897
+ symbol: string;
1898
+ kind: "long" | "short";
1899
+ risk?: number;
1900
+ risk_reward?: number;
1901
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
1902
+ getPositionConfig(payload: {
1903
+ symbol: string;
1904
+ kind: "long" | "short";
1905
+ params?: {
1906
+ entry?: number;
1907
+ stop?: number;
1908
+ risk_reward?: number;
1909
+ risk?: number;
1910
+ profit_percent?: number;
1911
+ place_tp?: boolean;
1912
+ profit?: number;
1913
+ };
1914
+ }): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
1915
+ getCurrentPrice(symbol: string): Promise<any>;
1916
+ getAccountStrategy(payload: {
1917
+ symbol: string;
1918
+ }): Promise<AccountStrategy>;
1919
+ buildReduceConfig(payload: {
1920
+ symbol: string;
1921
+ kind?: "long" | "short";
1922
+ as_dict?: boolean;
1923
+ target_pnl?: number;
1924
+ trigger?: {
1925
+ long: boolean;
1926
+ short: boolean;
1927
+ };
1928
+ use_full?: boolean;
1929
+ }): Promise<{
1930
+ trigger_short: boolean;
1931
+ trigger_long: boolean;
1932
+ symbol: string;
1933
+ short_minimum_pnl: number;
1934
+ long_minimum_pnl: number;
1935
+ short_profit: any;
1936
+ long_profit: any;
1937
+ owner: string;
1938
+ exchange: string;
1939
+ not_reduce: boolean;
1940
+ reduce_ratio_long: any;
1941
+ reduce_ratio_short: any;
1942
+ use_full_long: any;
1943
+ use_full_short: any;
1944
+ } | {
1945
+ long: {
1946
+ minimum_pnl: number;
1947
+ max_size: number;
1948
+ profit: any;
1949
+ increase: boolean;
1950
+ not_reduce: boolean;
1951
+ ratio: any;
1952
+ use_full: boolean;
1953
+ sell_ratio: any;
1954
+ };
1955
+ short: {
1956
+ minimum_pnl: number;
1957
+ max_size: number;
1958
+ profit: any;
1959
+ increase: boolean;
1960
+ not_reduce: boolean;
1961
+ ratio: any;
1962
+ use_full: boolean;
1963
+ sell_ratio: any;
1964
+ };
1965
+ trigger: {
1966
+ long: boolean;
1967
+ short: boolean;
1968
+ };
1969
+ }>;
1970
+ getOriginalPlannedStop(payload: {
1971
+ symbol: string;
1972
+ kind: "long" | "short";
1973
+ }): Promise<any>;
1974
+ syncReduceClosePosition(payload?: {
1975
+ symbol: string;
1976
+ kind?: "long" | "short";
1977
+ trigger?: boolean;
1978
+ }): Promise<any>;
1979
+ reduceMajorPositionEntry(payload: {
1980
+ symbol: string;
1981
+ long: any;
1982
+ short: any;
1983
+ trigger: {
1984
+ long: boolean;
1985
+ short: boolean;
1986
+ };
1987
+ }): Promise<any>;
1988
+ placeProfitAndStop(payload: {
1989
+ symbol: string;
1990
+ trigger?: boolean;
1991
+ refresh?: boolean;
1992
+ kind?: "long" | "short";
1993
+ target_pnl?: number;
1994
+ }): Promise<any>;
1995
+ reEnterPositionOnEmpty(symbol: string): Promise<void>;
1996
+ generate_config_params(payload: {
1997
+ entry: number;
1998
+ stop: number;
1999
+ risk_reward: number;
2000
+ risk: number;
2001
+ symbol: string;
2002
+ with_trades?: boolean;
2003
+ }): Promise<any>;
2004
+ build_short_order(payload: {
2005
+ symbol: string;
2006
+ kind: "long" | "short";
2007
+ }): Promise<any>;
2008
+ extrapolateShortConfig(payload: {
2009
+ kind: "long" | "short";
2010
+ symbol: string;
2011
+ risk_reward?: number;
2012
+ risk?: number;
2013
+ }): Promise<any>;
2014
+ placeMarketOrder(payload: {
2015
+ symbol: string;
2016
+ kind: "long" | "short";
2017
+ quantity: number;
2018
+ }): Promise<void>;
2019
+ placeSingleOrder(payload: {
2020
+ symbol: string;
2021
+ kind: "long" | "short";
2022
+ }): Promise<string>;
2023
+ increasePositionAtStop(payload: {
2024
+ symbol: string;
2025
+ kind: "long" | "short";
2026
+ place?: boolean;
2027
+ }): Promise<any>;
2028
+ triggerTradeFromConfig(payload: {
2029
+ symbol: string;
2030
+ kind: "long" | "short";
2031
+ place?: boolean;
2032
+ raw?: boolean;
2033
+ tp?: boolean;
2034
+ stop?: boolean;
2035
+ use_current?: boolean;
2036
+ ignore_config?: boolean;
2037
+ }): Promise<any>;
2038
+ verifyStopLoss(payload: {
2039
+ symbol: string;
2040
+ kind: "long" | "short";
2041
+ revert?: boolean;
2042
+ }): Promise<void | Order[]>;
2043
+ windDownSymbol(payload: {
2044
+ symbol: string;
2045
+ risk_reward?: number;
2046
+ risk?: number;
2047
+ }): Promise<void>;
2048
+ updateTargetPnl(payload: {
2049
+ symbol: string;
2050
+ kind: "long" | "short";
2051
+ }): Promise<number>;
2052
+ /**
2053
+ * Updates the risk configuration for an empty position using the next_risk value.
2054
+ * This implements progressive risk management where successful trades increase future risk tolerance.
2055
+ *
2056
+ * @param payload.symbol - The trading symbol (e.g., "BTCUSDT")
2057
+ * @param payload.kind - Position type: "long" or "short"
2058
+ * @returns Object indicating if update was successful with old/new risk values
2059
+ */
2060
+ updateRiskOnEmpty(payload: {
2061
+ symbol: string;
2062
+ kind: "long" | "short";
2063
+ }): Promise<{
2064
+ updated: boolean;
2065
+ symbol: string;
2066
+ kind: "long" | "short";
2067
+ old_risk: number;
2068
+ new_risk: number;
2069
+ reason?: undefined;
2070
+ } | {
2071
+ updated: boolean;
2072
+ symbol: string;
2073
+ kind: "long" | "short";
2074
+ reason: string;
2075
+ old_risk?: undefined;
2076
+ new_risk?: undefined;
2077
+ }>;
2078
+ updateGoodHedgeConfig(payload: {
2079
+ symbol: string;
2080
+ params?: {
2081
+ support: number;
2082
+ resistance: number;
2083
+ risk: number;
2084
+ profit_percent: number;
2085
+ };
2086
+ risk_factor?: number;
2087
+ update?: boolean;
2088
+ place?: boolean;
2089
+ update_tp?: boolean;
2090
+ }): Promise<{
2091
+ support: number;
2092
+ resistance: number;
2093
+ risk: number;
2094
+ profit_percent: number;
2095
+ }>;
2096
+ /**
2097
+ * This method is used to place the opposite trade action
2098
+ */
2099
+ placeOppositeTradeAction(payload: {
2100
+ symbol: string;
2101
+ kind: "long" | "short";
2102
+ data: {
2103
+ avg: {
2104
+ quantity: number;
2105
+ price: number;
2106
+ };
2107
+ entry: number;
2108
+ stop: number;
2109
+ risk_per_trade: number;
2110
+ profit_percent: number;
2111
+ risk_reward: number;
2112
+ };
2113
+ }): Promise<void>;
2114
+ buildOppositeTrades(payload: {
2115
+ symbol: string;
2116
+ kind: "long" | "short";
2117
+ place?: boolean;
2118
+ place_symbol?: string;
2119
+ }): Promise<{
2120
+ avg: {
2121
+ entry: number;
2122
+ price: number;
2123
+ quantity: number;
2124
+ };
2125
+ loss: number;
2126
+ profit_percent: number;
2127
+ fee: number;
2128
+ risk_per_trade: number;
492
2129
  risk_reward: number;
2130
+ symbol?: string;
2131
+ focus: number;
2132
+ budget: number;
2133
+ support: number;
2134
+ resistance: number;
2135
+ percent_change: number;
2136
+ tradeSplit?: number;
2137
+ take_profit?: number;
2138
+ kind: "long" | "short";
493
2139
  entry: number;
494
2140
  stop: number;
495
- risk_per_trade: number;
496
- avg_size: number;
497
- neg_pnl: number;
498
2141
  min_size: number;
2142
+ price_places?: string;
2143
+ strategy?: "quantity" | "entry";
2144
+ as_array?: boolean;
2145
+ decimal_places?: string;
2146
+ min_profit?: number;
2147
+ raw?: boolean;
2148
+ gap?: number;
2149
+ rr?: number;
2150
+ max_size?: number;
2151
+ max_quantity?: number;
2152
+ }>;
2153
+ runSimulation(payload: {
499
2154
  symbol: string;
500
- }, place?: boolean, skip_stop?: boolean): Promise<{
501
- entry_orders: {
502
- orders: {
503
- entry: any;
504
- quantity: any;
505
- reverse_avg_entry: any;
506
- reverse_avg_quantity: any;
507
- avg_entry: any;
508
- avg_size: any;
509
- }[];
510
- kind: "long" | "short";
2155
+ kind: "long" | "short";
2156
+ iterations?: number;
2157
+ raw?: boolean;
2158
+ }): Promise<Strategy | {
2159
+ last_entry: any;
2160
+ first_entry: any;
2161
+ threshold: any;
2162
+ risk: number;
2163
+ risk_reward: number;
2164
+ spread: number;
2165
+ gap_loss: number;
2166
+ net_profit: number;
2167
+ long: {
2168
+ avg_entry: number;
2169
+ avg_size: number;
2170
+ loss: number;
2171
+ stop: number;
2172
+ stop_quantity: number;
2173
+ re_entry_quantity: number;
2174
+ initial_pnl: number;
2175
+ tp: number;
2176
+ incurred_loss: number;
2177
+ pnl: number;
2178
+ remaining_quantity: number;
511
2179
  };
512
- stop_orders: {
2180
+ short: {
2181
+ avg_entry: number;
2182
+ avg_size: number;
2183
+ loss: number;
513
2184
  stop: number;
514
- final_stop: number;
515
- kind: "long" | "short";
516
- quantity: any;
517
- is_limit: boolean;
2185
+ stop_quantity: number;
2186
+ re_entry_quantity: number;
2187
+ initial_pnl: number;
2188
+ tp: number;
2189
+ incurred_loss: number;
2190
+ pnl: number;
2191
+ remaining_quantity: number;
518
2192
  };
519
- trades: any[];
520
- }>;
521
- placeSharedOrder(action: "place_limit_orders" | "place_stop_orders" | "place_tp_orders", payload: {
2193
+ }[]>;
2194
+ getCurrentRun(payload: {
2195
+ symbol: string;
2196
+ kind?: "long" | "short";
2197
+ pnl?: number;
2198
+ }): Promise<true | import("pocketbase").RecordModel>;
2199
+ recomputeSymbolConfig(payload: {
2200
+ symbol: string;
2201
+ refresh?: boolean;
2202
+ }): Promise<SymbolConfig>;
2203
+ /**
2204
+ * This function builds a config for a symbol
2205
+ * @param payload
2206
+ * @returns
2207
+ */
2208
+ buildConfigForSymbol(payload: {
522
2209
  symbol: string;
523
- entry: number;
524
- stop: number;
525
- risk_reward: number;
526
2210
  risk: number;
527
- place?: boolean;
528
- update_db?: boolean;
2211
+ kind?: "long" | "short";
2212
+ risk_reward?: number;
2213
+ as_config?: boolean;
2214
+ with_trades?: boolean;
529
2215
  }): Promise<any>;
530
- getPositionConfig(payload: {
2216
+ triggerBullishMarket(payload: {
531
2217
  symbol: string;
2218
+ profit_percent?: number;
2219
+ risk_reward?: number;
2220
+ }): Promise<any>;
2221
+ updateAllActiveSymbols(payload: {
2222
+ interval?: number;
2223
+ }): Promise<void>;
2224
+ updateAllPositionsWithNoConfig(payload: {
532
2225
  kind: "long" | "short";
533
- params?: {
534
- entry: number;
535
- stop: number;
536
- risk_reward: number;
537
- risk: number;
538
- profit_percent?: number;
539
- };
540
- }): Promise<ScheduledTrade>;
541
- getCurrentPrice(symbol: string): Promise<any>;
542
- getPositionStrategy(): Promise<{
543
- strategy_instance: Strategy;
544
- focus_account: ExchangeAccount;
2226
+ }): Promise<void>;
2227
+ getSymbolsForPositions(): Promise<any[]>;
2228
+ getNonEssentialSymbols(): Promise<any[]>;
2229
+ _terminatePositions(payload: {
2230
+ symbol: string;
2231
+ }): Promise<void>;
2232
+ getOrders(payload: {
2233
+ symbol: string;
2234
+ kind: "long" | "short";
2235
+ type: "limit" | "stop" | "tp";
2236
+ }): Promise<Order[]>;
2237
+ syncPositionConfigs(payload: {
2238
+ symbol: string;
2239
+ kind: "long" | "short";
2240
+ refresh?: boolean;
2241
+ }): Promise<void>;
2242
+ terminatePositions(payload: {
2243
+ symbol: string;
2244
+ }): Promise<void>;
2245
+ fetchAndUpdateTopMovers(): Promise<{
2246
+ updated_bullish: BullishMarket[];
2247
+ moved_to_winding: WindingDownMarket[];
545
2248
  }>;
546
- getOriginalPlannedStop(payload: {
2249
+ computeTargetPnl(payload: {
2250
+ symbol: string;
2251
+ kind: "long" | "short";
2252
+ }): Promise<number>;
2253
+ placeStopLimit(payload: {
547
2254
  symbol: string;
548
2255
  kind: "long" | "short";
2256
+ place?: boolean;
2257
+ stop: number;
2258
+ quantity?: number;
549
2259
  }): Promise<any>;
550
- syncReduceClosePosition(symbol: string, payload?: {
551
- kind?: "long" | "short";
552
- long?: CodeNode;
553
- short?: CodeNode;
554
- trigger?: {
555
- long: boolean;
556
- short: boolean;
557
- };
2260
+ placeTrade(payload: {
2261
+ symbol: string;
2262
+ kind: "long" | "short";
2263
+ place?: boolean;
2264
+ limit?: boolean;
2265
+ tp?: boolean;
2266
+ stop?: boolean;
2267
+ raw?: boolean;
2268
+ cancel?: boolean;
2269
+ ignore_config?: boolean;
2270
+ target_pnl?: number;
558
2271
  }): Promise<any>;
559
- generate_config_params(payload: {
560
- entry: number;
561
- stop: number;
562
- risk_reward: number;
563
- risk: number;
2272
+ updateConfigPnl(payload: {
2273
+ symbol: string;
2274
+ kind: "long" | "short";
2275
+ }): Promise<void>;
2276
+ determineReduceTp(payload: {
564
2277
  symbol: string;
2278
+ factor: number;
565
2279
  }): Promise<{
566
- place_stop: boolean;
567
- profit_percent: number;
568
- entry: number;
569
- stop: number;
570
- avg_size: any;
571
- avg_entry: any;
572
- risk_reward: number;
573
- neg_pnl: any;
574
- risk: number;
2280
+ long_diff: number;
2281
+ short_diff: number;
2282
+ gap: number;
2283
+ gap_cost: number;
2284
+ long_tp: number;
2285
+ short_tp: number;
2286
+ long_percent: number;
2287
+ short_percent: number;
575
2288
  }>;
576
- extrapolateShortConfig(payload: {
577
- kind: "long" | "short";
2289
+ profitWithinGapStrategy(payload: {
578
2290
  symbol: string;
579
- risk_reward?: number;
580
2291
  }): Promise<{
581
- place_stop: boolean;
582
- profit_percent: number;
583
- entry: number;
584
- stop: number;
585
- avg_size: any;
586
- avg_entry: any;
587
- risk_reward: number;
588
- neg_pnl: any;
589
- risk: number;
2292
+ positions: {
2293
+ long: PositionsView & {
2294
+ expand?: {
2295
+ account_strategy?: AccountStrategy;
2296
+ };
2297
+ };
2298
+ short: PositionsView & {
2299
+ expand?: {
2300
+ account_strategy?: AccountStrategy;
2301
+ };
2302
+ };
2303
+ };
2304
+ config_details: {
2305
+ app_config: {
2306
+ fee: number;
2307
+ risk_per_trade: number;
2308
+ risk_reward: number;
2309
+ symbol?: string;
2310
+ focus: number;
2311
+ budget: number;
2312
+ support: number;
2313
+ resistance: number;
2314
+ percent_change: number;
2315
+ tradeSplit?: number;
2316
+ take_profit?: number;
2317
+ kind: "long" | "short";
2318
+ entry: number;
2319
+ stop: number;
2320
+ min_size: number;
2321
+ price_places?: string;
2322
+ strategy?: "quantity" | "entry";
2323
+ as_array?: boolean;
2324
+ decimal_places?: string;
2325
+ min_profit?: number;
2326
+ raw?: boolean;
2327
+ gap?: number;
2328
+ rr?: number;
2329
+ max_size?: number;
2330
+ max_quantity?: number;
2331
+ };
2332
+ last_value: any;
2333
+ config: {
2334
+ entry: number;
2335
+ stop: number;
2336
+ risk: number;
2337
+ risk_reward: number | {
2338
+ result: any[];
2339
+ value: number;
2340
+ total: number;
2341
+ risk_per_trade: number;
2342
+ max: number;
2343
+ min: number;
2344
+ neg_pnl: any;
2345
+ entry: any;
2346
+ };
2347
+ profit_percent: number;
2348
+ };
2349
+ pnl: number;
2350
+ };
590
2351
  }>;
591
- triggerTradeFromConfig(payload: {
2352
+ generateGapTp(payload: {
592
2353
  symbol: string;
593
- kind: "long" | "short";
594
- }): Promise<any>;
595
- verifyStopLoss(payload: {
2354
+ factor?: number;
2355
+ }): Promise<{
2356
+ profit_percent: {
2357
+ long: number;
2358
+ short: number;
2359
+ };
2360
+ risk: {
2361
+ short: number;
2362
+ long: number;
2363
+ };
2364
+ take_profit: {
2365
+ long: number;
2366
+ short: number;
2367
+ };
2368
+ to_reduce: {
2369
+ short: number;
2370
+ long: number;
2371
+ };
2372
+ full_reduce: {
2373
+ short: number;
2374
+ long: number;
2375
+ };
2376
+ sell_quantity: {
2377
+ short: number;
2378
+ long: number;
2379
+ };
2380
+ gap: number;
2381
+ gap_loss: number;
2382
+ }>;
2383
+ getSellPriceFromStrategy(payload: {
596
2384
  symbol: string;
2385
+ reduce_position: PositionsView;
2386
+ kind?: "long" | "short";
2387
+ }): Promise<{
2388
+ pnl: number;
2389
+ loss: number;
2390
+ original_pnl: number;
2391
+ reward_factor: number;
2392
+ profit_percent: number;
597
2393
  kind: "long" | "short";
598
- revert?: boolean;
599
- }): Promise<import("pocketbase").RecordModel[]>;
600
- windDownSymbol(symbol: string, risk_reward?: number): Promise<void>;
601
- triggerBullishMarket(symbol: string): Promise<any>;
2394
+ sell_price: number;
2395
+ quantity: number;
2396
+ price_places: string;
2397
+ decimal_places: string;
2398
+ }>;
2399
+ placeCompoundShortTrade(payload: {}): Promise<void>;
2400
+ placeCompoundLongTrade(payload: {
2401
+ symbol: string;
2402
+ params: {
2403
+ resistance: number;
2404
+ support: number;
2405
+ profit_percent: number;
2406
+ risk_reward: number;
2407
+ risk: number;
2408
+ };
2409
+ place?: boolean;
2410
+ }): Promise<void>;
602
2411
  }
2412
+ declare function getExchangeAccount(payload: {
2413
+ account: ExchangeType;
2414
+ app_db: AppDatabase;
2415
+ getCredentials: (payload: {
2416
+ account: string;
2417
+ exchange: string;
2418
+ app_db: AppDatabase;
2419
+ }) => Promise<{
2420
+ api_key: string;
2421
+ api_secret: string;
2422
+ email: string;
2423
+ }>;
2424
+ proxyOptions?: {
2425
+ proxy?: any;
2426
+ ignore_proxy?: boolean;
2427
+ };
2428
+ canWithdraw?: boolean;
2429
+ }): Promise<ExchangeAccount$1>;
603
2430
  declare class App {
604
- private app_db;
2431
+ app_db: AppDatabase;
2432
+ proxyOptions?: {
2433
+ proxy?: any;
2434
+ ignore_proxy?: boolean;
2435
+ canWithdraw?: boolean;
2436
+ };
605
2437
  private getCredentials;
606
- constructor(app_db: AppDatabase, getCredentials: (account: string, exchange: string) => (account: string, exchange: string) => Promise<{
2438
+ constructor(app_db: AppDatabase, getCredentials: (payload: {
2439
+ account: string;
2440
+ exchange: string;
2441
+ }) => Promise<{
607
2442
  api_key: string;
608
2443
  api_secret: string;
609
- }>);
2444
+ email: string;
2445
+ }>, proxyOptions?: {
2446
+ proxy?: any;
2447
+ ignore_proxy?: boolean;
2448
+ canWithdraw?: boolean;
2449
+ });
610
2450
  getExchangeAccount(account: ExchangeType): Promise<ExchangeAccount$1>;
611
2451
  syncAccount(payload: {
612
2452
  account: ExchangeType;
@@ -617,6 +2457,7 @@ declare class App {
617
2457
  }): Promise<PositionsView | (PositionsView & {
618
2458
  expand?: {
619
2459
  config: ScheduledTrade;
2460
+ account: ExchangeAccount;
620
2461
  };
621
2462
  })[]>;
622
2463
  syncOrders(payload: {
@@ -631,7 +2472,7 @@ declare class App {
631
2472
  price?: number;
632
2473
  all?: boolean;
633
2474
  stop?: boolean;
634
- }): Promise<{
2475
+ }): Promise<any[] | {
635
2476
  success: boolean;
636
2477
  message: string;
637
2478
  exchange_result?: undefined;
@@ -647,39 +2488,6 @@ declare class App {
647
2488
  message?: undefined;
648
2489
  exchange_result?: undefined;
649
2490
  }>;
650
- generateConfig(payload: {
651
- account: ExchangeType;
652
- symbol: string;
653
- kind: "long" | "short";
654
- update_orders?: boolean;
655
- place_orders?: boolean;
656
- }): Promise<any>;
657
- updateReduceRatio(payload: {
658
- account: ExchangeType;
659
- symbol: string;
660
- }): Promise<{
661
- long_position: any;
662
- short_position: any;
663
- long_db_position: any;
664
- short_db_position: any;
665
- balance: any;
666
- }>;
667
- verifyStopLoss(payload: {
668
- account: ExchangeType;
669
- symbol: string;
670
- kind: "long" | "short";
671
- revert?: boolean;
672
- }): Promise<import("pocketbase").RecordModel[]>;
673
- updateTopMovers(payload?: {
674
- new_markets: {
675
- symbol: string;
676
- percent: number;
677
- }[];
678
- totalRisk: number;
679
- }): Promise<{
680
- updated_bullish: BullishMarket[];
681
- moved_to_winding: WindingDownMarket[];
682
- }>;
683
2491
  getWindingDownMarkets(): Promise<WindingDownMarket[]>;
684
2492
  updateSymbolConfigs(payload: {
685
2493
  configs: {
@@ -696,7 +2504,136 @@ declare class App {
696
2504
  created: number;
697
2505
  }>;
698
2506
  updateAllAccountWithSymbols(with_positions?: boolean): Promise<void>;
699
- windDownSymbol(symbol: string): Promise<boolean>;
2507
+ windDownSymbol(payload: {
2508
+ symbol: string;
2509
+ risk?: number;
2510
+ }): Promise<boolean>;
2511
+ getNonEssentialSymbols(): Promise<Set<any>>;
2512
+ refreshAllPositionsWithSymbol(payload: {
2513
+ symbol: string;
2514
+ }): Promise<void>;
2515
+ autoFollowPositions(): Promise<void>;
2516
+ getMoverExchangeInstances(): Promise<ExchangeAccount[]>;
2517
+ updateTpOnAllMarkets(): Promise<void>;
2518
+ triggerMoverTask(payload: {
2519
+ callback: (params: {
2520
+ symbol: string;
2521
+ account: ExchangeType;
2522
+ }) => Promise<any>;
2523
+ removeCallback?: (params: {
2524
+ symbol: string;
2525
+ account: ExchangeType;
2526
+ }) => Promise<any>;
2527
+ }): Promise<void>;
2528
+ placeTrade(payload: {
2529
+ account: ExchangeType;
2530
+ symbol: string;
2531
+ kind: "long" | "short";
2532
+ place?: boolean;
2533
+ tp?: boolean;
2534
+ cancel?: boolean;
2535
+ raw?: boolean;
2536
+ }): Promise<any>;
2537
+ runDbStrategyAccounts(callback: (params: {
2538
+ symbol: string;
2539
+ account: ExchangeType;
2540
+ }) => Promise<any>): Promise<void>;
2541
+ profitWithinGapStrategy(payload: {
2542
+ account: ExchangeType;
2543
+ symbol: string;
2544
+ }): Promise<{
2545
+ positions: {
2546
+ long: PositionsView & {
2547
+ expand?: {
2548
+ account_strategy?: AccountStrategy;
2549
+ };
2550
+ };
2551
+ short: PositionsView & {
2552
+ expand?: {
2553
+ account_strategy?: AccountStrategy;
2554
+ };
2555
+ };
2556
+ };
2557
+ config_details: {
2558
+ app_config: {
2559
+ fee: number;
2560
+ risk_per_trade: number;
2561
+ risk_reward: number;
2562
+ symbol?: string;
2563
+ focus: number;
2564
+ budget: number;
2565
+ support: number;
2566
+ resistance: number;
2567
+ percent_change: number;
2568
+ tradeSplit?: number;
2569
+ take_profit?: number;
2570
+ kind: "long" | "short";
2571
+ entry: number;
2572
+ stop: number;
2573
+ min_size: number;
2574
+ price_places?: string;
2575
+ strategy?: "quantity" | "entry";
2576
+ as_array?: boolean;
2577
+ decimal_places?: string;
2578
+ min_profit?: number;
2579
+ raw?: boolean;
2580
+ gap?: number;
2581
+ rr?: number;
2582
+ max_size?: number;
2583
+ max_quantity?: number;
2584
+ };
2585
+ last_value: any;
2586
+ config: {
2587
+ entry: number;
2588
+ stop: number;
2589
+ risk: number;
2590
+ risk_reward: number | {
2591
+ result: any[];
2592
+ value: number;
2593
+ total: number;
2594
+ risk_per_trade: number;
2595
+ max: number;
2596
+ min: number;
2597
+ neg_pnl: any;
2598
+ entry: any;
2599
+ };
2600
+ profit_percent: number;
2601
+ };
2602
+ pnl: number;
2603
+ };
2604
+ }>;
2605
+ compoundLongTrade(payload: {
2606
+ main_account: ExchangeType & {
2607
+ symbol: string;
2608
+ };
2609
+ focus_account: ExchangeType & {
2610
+ symbol: string;
2611
+ };
2612
+ place?: boolean;
2613
+ rr?: number;
2614
+ }): Promise<{
2615
+ start_risk: number;
2616
+ short_profit: number;
2617
+ support: number;
2618
+ resistance: number;
2619
+ long_v: any;
2620
+ profit_percent: number;
2621
+ result: any;
2622
+ short_max_size: any;
2623
+ }>;
2624
+ reduceExistingPosition(payload: {
2625
+ main_account: ExchangeType & {
2626
+ symbol: string;
2627
+ kind?: "long" | "short";
2628
+ };
2629
+ reduce_account: ExchangeType & {
2630
+ symbol: string;
2631
+ };
2632
+ kind: "long" | "short";
2633
+ place?: boolean;
2634
+ increase?: boolean;
2635
+ cancel_limit?: boolean;
2636
+ }): Promise<any>;
700
2637
  }
701
2638
  export declare function initApp(payload: {
702
2639
  db: {
@@ -704,14 +2641,50 @@ export declare function initApp(payload: {
704
2641
  email: string;
705
2642
  password: string;
706
2643
  };
707
- getCredentials: (account: string, exchange: string) => (account: string, exchange: string) => Promise<{
2644
+ password?: string;
2645
+ salt?: string;
2646
+ email?: string;
2647
+ getCredentials: (payload: {
2648
+ account: string;
2649
+ exchange: string;
2650
+ app_db: AppDatabase;
2651
+ }) => Promise<{
708
2652
  api_key: string;
709
2653
  api_secret: string;
2654
+ email: string;
710
2655
  }>;
2656
+ proxy?: any;
2657
+ ignore_proxy?: boolean;
2658
+ canWithdraw?: boolean;
2659
+ triggerToken?: string;
2660
+ }): Promise<App>;
2661
+ declare function getCredentials(payload: {
2662
+ account: string;
2663
+ exchange: string;
2664
+ app_db: AppDatabase;
2665
+ }): Promise<any>;
2666
+ export declare function initialize(payload: {
2667
+ password?: string;
2668
+ proxy?: any;
2669
+ ignore_proxy?: boolean;
2670
+ canWithdraw?: boolean;
711
2671
  }): Promise<App>;
712
2672
 
2673
+ declare namespace database {
2674
+ export { AppDatabase, ExchangeType, decryptObject, encryptObject, initPocketBaseClient };
2675
+ }
2676
+ declare namespace exchange_account {
2677
+ export { ExchangeAccount$1 as ExchangeAccount, getExchangeAccount };
2678
+ }
2679
+ declare namespace app {
2680
+ export { App, getCredentials, initApp, initialize };
2681
+ }
2682
+
713
2683
  export {
714
2684
  ExchangeAccount$1 as ExchangeAccount,
2685
+ app,
2686
+ database,
2687
+ exchange_account,
715
2688
  };
716
2689
 
717
2690
  export {};