@gbozee/ultimate 0.0.2-0

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +619 -0
  2. package/dist/index.js +35440 -0
  3. package/package.json +37 -0
@@ -0,0 +1,619 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ import { HttpsProxyAgent } from 'https-proxy-agent';
4
+ import PocketBase from 'pocketbase';
5
+ import { SocksProxyAgent } from 'socks-proxy-agent';
6
+
7
+ interface Position$1 {
8
+ id: number;
9
+ kind: string;
10
+ entry: number;
11
+ symbol: string;
12
+ quantity: number;
13
+ avg_entry: number | null;
14
+ config_id: number;
15
+ stop_loss: number;
16
+ take_profit: number;
17
+ tp_quantity: number;
18
+ stop_quantity: number;
19
+ }
20
+ export interface Account {
21
+ id: number | string;
22
+ owner: string;
23
+ exchange?: string;
24
+ settings: {
25
+ default_take_profit: number;
26
+ stop_buying: boolean;
27
+ };
28
+ balance: number;
29
+ usd_balance?: number;
30
+ position: {
31
+ long: Position$1;
32
+ short: Position$1;
33
+ };
34
+ orders: {
35
+ long: {
36
+ entries: any[];
37
+ stop_orders: any[];
38
+ tp_orders: any[];
39
+ };
40
+ short: {
41
+ entries: any[];
42
+ stop_orders: any[];
43
+ tp_orders: any[];
44
+ };
45
+ };
46
+ config_id: number;
47
+ price_places: string;
48
+ decimal_places: string;
49
+ liquidation?: {
50
+ long: number;
51
+ short: number;
52
+ };
53
+ entry?: {
54
+ long: any;
55
+ short: any;
56
+ };
57
+ }
58
+ export interface BaseExchange {
59
+ client: any;
60
+ placeStopOrders(payload: {
61
+ symbol: string;
62
+ quantity: number;
63
+ kind: "long" | "short";
64
+ stop: number;
65
+ price_places?: string;
66
+ decimal_places?: string;
67
+ place?: boolean;
68
+ }): Promise<any>;
69
+ bulkPlaceLimitOrders(payload: {
70
+ orders: any[];
71
+ kind: "long" | "short";
72
+ decimal_places?: string;
73
+ price_places?: string;
74
+ symbol: string;
75
+ place?: boolean;
76
+ }): Promise<any>;
77
+ get_current_price(symbol: string): Promise<any>;
78
+ analyzeCharts(payload: {
79
+ symbol: string;
80
+ chartType: any;
81
+ count: number;
82
+ raw?: boolean;
83
+ }): Promise<any>;
84
+ getExchangeAccountInfo(account: {
85
+ owner: string;
86
+ exchange: string;
87
+ }, symbol: string): Promise<any>;
88
+ cancelOrders(payload: {
89
+ symbol: string;
90
+ orders: number[];
91
+ }): Promise<any>;
92
+ placeTpOrder(payload: {
93
+ symbol: string;
94
+ take_profit: number;
95
+ kind: "long" | "short";
96
+ cancel?: boolean;
97
+ price_places?: string;
98
+ decimal_places?: string;
99
+ }): Promise<any>;
100
+ placeLimitOrder(payload: {
101
+ symbol: string;
102
+ quantity: number;
103
+ kind: "long" | "short";
104
+ price: number;
105
+ price_places?: string;
106
+ decimal_places?: string;
107
+ }): Promise<any>;
108
+ placeStopOrder(payload: {
109
+ symbol: string;
110
+ stop: number;
111
+ quantity: number;
112
+ kind: "long" | "short";
113
+ price_places?: string;
114
+ decimal_places?: string;
115
+ }): Promise<any>;
116
+ }
117
+ /**
118
+ * TypeScript type definitions for PocketBase collections and views
119
+ */
120
+ export interface BaseSystemFields {
121
+ id: string;
122
+ created: string;
123
+ updated: string;
124
+ }
125
+ export interface ExchangeAccount extends BaseSystemFields {
126
+ exchange: "binance" | "bybit";
127
+ owner: string;
128
+ email?: string;
129
+ user?: string;
130
+ usdt?: number;
131
+ usdc?: number;
132
+ proxy?: string;
133
+ }
134
+ export interface SymbolConfig extends BaseSystemFields {
135
+ symbol: string;
136
+ support?: number;
137
+ resistance?: number;
138
+ stop_percent?: number;
139
+ price_places?: string;
140
+ decimal_places?: string;
141
+ min_size?: number;
142
+ weight?: number;
143
+ leverage?: number;
144
+ }
145
+ export interface ScheduledTrade extends BaseSystemFields {
146
+ symbol: string;
147
+ account: string;
148
+ profit?: number;
149
+ risk?: number;
150
+ entry?: number;
151
+ stop?: number;
152
+ risk_reward?: number;
153
+ profit_percent?: number;
154
+ place_tp?: boolean;
155
+ kind?: "long" | "short";
156
+ current_price?: number;
157
+ }
158
+ export interface Strategy extends BaseSystemFields {
159
+ name: string;
160
+ short_risk_factor?: number;
161
+ long_risk_factor?: number;
162
+ profit_percent?: number;
163
+ cancel_short?: boolean;
164
+ cancel_long?: boolean;
165
+ recompute_short_config?: boolean;
166
+ update_stop_loss?: boolean;
167
+ liquidation_as_entry?: boolean;
168
+ stop_as_entry?: boolean;
169
+ tp_as_stop?: boolean;
170
+ entry_as_stop?: boolean;
171
+ place_stop?: boolean;
172
+ save_config?: boolean;
173
+ }
174
+ interface Proxy$1 extends BaseSystemFields {
175
+ ip_address?: string;
176
+ type?: "http" | "socks5";
177
+ }
178
+ export interface TradeBlockTracking extends BaseSystemFields {
179
+ account?: string;
180
+ symbol?: string;
181
+ running?: boolean;
182
+ }
183
+ export interface PositionsView {
184
+ id: string;
185
+ symbol?: any;
186
+ entry?: any;
187
+ quantity?: any;
188
+ take_profit?: any;
189
+ account?: any;
190
+ kind?: any;
191
+ target_pnl?: number;
192
+ liquidation?: number;
193
+ avg_price?: number;
194
+ avg_qty?: number;
195
+ next_order?: number;
196
+ last_order?: number;
197
+ config?: any;
198
+ stop_loss?: {
199
+ price: number;
200
+ quantity: number;
201
+ };
202
+ stop_pnl?: any;
203
+ leverage?: any;
204
+ avg_liquidation?: any;
205
+ balance?: any;
206
+ }
207
+ export type ExchangeType = {
208
+ owner: string;
209
+ exchange: string;
210
+ };
211
+ export declare class AppDatabase {
212
+ private pb;
213
+ constructor(pb: PocketBase);
214
+ getProxyForAccount(account: ExchangeType): Promise<HttpsProxyAgent<`http://${string}`> | SocksProxyAgent>;
215
+ get_exchange_db_instance(account: ExchangeType): Promise<ExchangeAccount & {
216
+ expand?: {
217
+ proxy: Proxy$1;
218
+ };
219
+ }>;
220
+ getPositions(account: ExchangeType, options: {
221
+ symbol: string;
222
+ as_view?: boolean;
223
+ }): Promise<(PositionsView & {
224
+ expand?: {
225
+ config: ScheduledTrade;
226
+ };
227
+ })[]>;
228
+ private _createOrUpdatePosition;
229
+ createOrUpdatePositions(account: ExchangeType, options: {
230
+ symbol: string;
231
+ long_position: Position$1;
232
+ short_position: Position$1;
233
+ usd_balance: number;
234
+ }): Promise<(PositionsView & {
235
+ expand?: {
236
+ config: ScheduledTrade;
237
+ };
238
+ })[]>;
239
+ update_db_position(position: any, payload: any): Promise<import("pocketbase").RecordModel>;
240
+ getSymbolConfigFromDB(symbol: string): Promise<SymbolConfig>;
241
+ getRunningInstanceFromDB(account: ExchangeType, symbol: string, options?: {
242
+ delay?: number;
243
+ }): Promise<TradeBlockTracking>;
244
+ updateRunningInstance(id: string, running: boolean): Promise<import("pocketbase").RecordModel>;
245
+ getOrders(account: ExchangeType, options: {
246
+ symbol: string;
247
+ kind: "long" | "short";
248
+ }): Promise<import("pocketbase").RecordModel[]>;
249
+ deleteAndRecreateOrders(account: ExchangeType, options: {
250
+ symbol: string;
251
+ kind: "long" | "short";
252
+ }, all_orders?: Array<{
253
+ symbol: string;
254
+ price: number;
255
+ quantity: number;
256
+ kind: "long" | "short";
257
+ side: "buy" | "sell";
258
+ stop: number;
259
+ order_id: string;
260
+ triggerPrice?: number;
261
+ }>): Promise<import("pocketbase").RecordModel[]>;
262
+ cancelOrders(payload: {
263
+ cancelExchangeOrders: (payload: {
264
+ symbol: string;
265
+ orders: number[];
266
+ }) => Promise<any>;
267
+ all?: boolean;
268
+ kind: "long" | "short";
269
+ stop?: boolean;
270
+ account: ExchangeType;
271
+ symbol: string;
272
+ price?: number;
273
+ }): Promise<{
274
+ success: boolean;
275
+ message: string;
276
+ exchange_result?: undefined;
277
+ error?: undefined;
278
+ } | {
279
+ success: boolean;
280
+ exchange_result: any;
281
+ message?: undefined;
282
+ error?: undefined;
283
+ } | {
284
+ success: boolean;
285
+ error: any;
286
+ message?: undefined;
287
+ exchange_result?: undefined;
288
+ }>;
289
+ createOrUpdatePositionConfig(db_position: any, payload: {
290
+ entry: number;
291
+ stop: number;
292
+ risk_reward: number;
293
+ risk: number;
294
+ profit_percent?: number;
295
+ }): Promise<void>;
296
+ getPositionConfig(payload: {
297
+ symbol: string;
298
+ kind: "long" | "short";
299
+ account: ExchangeType;
300
+ }): Promise<import("pocketbase").RecordModel>;
301
+ getPositionStrategy(account: ExchangeType): Promise<{
302
+ strategy_instance: Strategy;
303
+ focus_account: ExchangeAccount;
304
+ }>;
305
+ }
306
+ export interface CodeNode {
307
+ minimum_pnl: number;
308
+ max_size: number;
309
+ profit: number;
310
+ ratio?: number;
311
+ increase: boolean;
312
+ not_reduce?: boolean;
313
+ reduce_ratio?: number;
314
+ use_full?: boolean;
315
+ }
316
+ export type AppConfig = {
317
+ fee: number;
318
+ risk_per_trade: number;
319
+ risk_reward: number;
320
+ symbol?: string;
321
+ focus: number;
322
+ budget: number;
323
+ support: number;
324
+ resistance: number;
325
+ percent_change: number;
326
+ tradeSplit?: number;
327
+ take_profit?: number;
328
+ kind: "long" | "short";
329
+ entry: number;
330
+ stop: number;
331
+ min_size: number;
332
+ price_places?: string;
333
+ strategy?: "quantity" | "entry";
334
+ as_array?: boolean;
335
+ decimal_places?: string;
336
+ min_profit?: number;
337
+ raw?: boolean;
338
+ gap?: number;
339
+ rr?: number;
340
+ max_size?: number;
341
+ };
342
+ declare class ExchangeAccount$1 {
343
+ private instance;
344
+ private exchange;
345
+ private app_db;
346
+ constructor(payload: ExchangeType, options: {
347
+ exchange: BaseExchange;
348
+ app_db: AppDatabase;
349
+ });
350
+ getActiveAccount(symbol: string, full?: boolean): Promise<Account | {
351
+ liquidation: {
352
+ long: number;
353
+ short: number;
354
+ };
355
+ active_account: Account;
356
+ current_price: any;
357
+ exchange: any;
358
+ }>;
359
+ syncAccount(options: {
360
+ symbol: string;
361
+ kind?: "long" | "short";
362
+ update?: boolean;
363
+ as_view?: boolean;
364
+ }): Promise<(PositionsView & {
365
+ expand?: {
366
+ config: ScheduledTrade;
367
+ };
368
+ }) | (PositionsView & {
369
+ expand?: {
370
+ config: ScheduledTrade;
371
+ };
372
+ })[]>;
373
+ getRunningInstanceFromDB(symbol: string): Promise<TradeBlockTracking>;
374
+ syncOrders(options: {
375
+ symbol: string;
376
+ kind: "long" | "short";
377
+ update?: boolean;
378
+ }): Promise<import("pocketbase").RecordModel[]>;
379
+ cancelOrders(payload: {
380
+ symbol: string;
381
+ kind: "long" | "short";
382
+ price?: number;
383
+ all?: boolean;
384
+ stop?: boolean;
385
+ }): Promise<{
386
+ success: boolean;
387
+ message: string;
388
+ exchange_result?: undefined;
389
+ error?: undefined;
390
+ } | {
391
+ success: boolean;
392
+ exchange_result: any;
393
+ message?: undefined;
394
+ error?: undefined;
395
+ } | {
396
+ success: boolean;
397
+ error: any;
398
+ message?: undefined;
399
+ exchange_result?: undefined;
400
+ }>;
401
+ cancelExchangeOrders(payload: {
402
+ symbol: string;
403
+ orders: number[];
404
+ }): Promise<any>;
405
+ buildAppConfig(payload: {
406
+ entry: number;
407
+ stop: number;
408
+ risk_reward: number;
409
+ risk: number;
410
+ symbol: string;
411
+ profit?: number;
412
+ update_db?: boolean;
413
+ profit_percent?: number;
414
+ }): Promise<AppConfig>;
415
+ placeConfigOrders(app_config: AppConfig, solution: {
416
+ risk_reward: number;
417
+ entry: number;
418
+ stop: number;
419
+ risk_per_trade: number;
420
+ avg_size: number;
421
+ neg_pnl: number;
422
+ min_size: number;
423
+ symbol: string;
424
+ }, place?: boolean, skip_stop?: boolean): Promise<{
425
+ entry_orders: {
426
+ orders: {
427
+ entry: any;
428
+ quantity: any;
429
+ reverse_avg_entry: any;
430
+ reverse_avg_quantity: any;
431
+ avg_entry: any;
432
+ avg_size: any;
433
+ }[];
434
+ kind: "long" | "short";
435
+ };
436
+ stop_orders: {
437
+ stop: number;
438
+ final_stop: number;
439
+ kind: "long" | "short";
440
+ quantity: any;
441
+ is_limit: boolean;
442
+ };
443
+ trades: any[];
444
+ }>;
445
+ placeSharedOrder(action: "place_limit_orders" | "place_stop_orders" | "place_tp_orders", payload: {
446
+ symbol: string;
447
+ entry: number;
448
+ stop: number;
449
+ risk_reward: number;
450
+ risk: number;
451
+ place?: boolean;
452
+ update_db?: boolean;
453
+ }): Promise<any>;
454
+ getPositionConfig(payload: {
455
+ symbol: string;
456
+ kind: "long" | "short";
457
+ params?: {
458
+ entry: number;
459
+ stop: number;
460
+ risk_reward: number;
461
+ risk: number;
462
+ profit_percent?: number;
463
+ };
464
+ }): Promise<import("pocketbase").RecordModel>;
465
+ getCurrentPrice(symbol: string): Promise<any>;
466
+ getPositionStrategy(): Promise<{
467
+ strategy_instance: Strategy;
468
+ focus_account: ExchangeAccount;
469
+ }>;
470
+ getOriginalPlannedStop(payload: {
471
+ symbol: string;
472
+ kind: "long" | "short";
473
+ }): Promise<any>;
474
+ syncReduceClosePosition(symbol: string, payload?: {
475
+ kind?: "long" | "short";
476
+ long?: CodeNode;
477
+ short?: CodeNode;
478
+ trigger?: {
479
+ long: boolean;
480
+ short: boolean;
481
+ };
482
+ }): Promise<any>;
483
+ }
484
+ declare class App {
485
+ private app_db;
486
+ private getCredentials;
487
+ constructor(app_db: AppDatabase, getCredentials: (account: string, exchange: string) => (account: string) => Promise<{
488
+ api_key: string;
489
+ api_secret: string;
490
+ }>);
491
+ getExchangeAccount(account: ExchangeType): Promise<ExchangeAccount$1>;
492
+ syncAccount(payload: {
493
+ account: ExchangeType;
494
+ symbol: string;
495
+ kind?: "long" | "short";
496
+ update?: boolean;
497
+ as_view?: boolean;
498
+ }): Promise<(PositionsView & {
499
+ expand?: {
500
+ config: ScheduledTrade;
501
+ };
502
+ }) | (PositionsView & {
503
+ expand?: {
504
+ config: ScheduledTrade;
505
+ };
506
+ })[]>;
507
+ syncOrders(payload: {
508
+ account: ExchangeType;
509
+ symbol: string;
510
+ kind: "long" | "short";
511
+ }): Promise<any>;
512
+ cancelOrders(payload: {
513
+ account: ExchangeType;
514
+ symbol: string;
515
+ kind: "long" | "short";
516
+ price?: number;
517
+ all?: boolean;
518
+ stop?: boolean;
519
+ }): Promise<{
520
+ success: boolean;
521
+ message: string;
522
+ exchange_result?: undefined;
523
+ error?: undefined;
524
+ } | {
525
+ success: boolean;
526
+ exchange_result: any;
527
+ message?: undefined;
528
+ error?: undefined;
529
+ } | {
530
+ success: boolean;
531
+ error: any;
532
+ message?: undefined;
533
+ exchange_result?: undefined;
534
+ }>;
535
+ triggerTradeFromConfig(payload: {
536
+ account: ExchangeType;
537
+ symbol: string;
538
+ kind: "long" | "short";
539
+ }): Promise<any>;
540
+ toggleStopBuying(payload: {
541
+ account: ExchangeType;
542
+ symbol: string;
543
+ kind: "long" | "short";
544
+ should_stop?: boolean;
545
+ }): Promise<import("pocketbase").RecordModel>;
546
+ generate_config_params(exchange_account: ExchangeAccount$1, payload: {
547
+ entry: number;
548
+ stop: number;
549
+ risk_reward: number;
550
+ risk: number;
551
+ symbol: string;
552
+ }): Promise<{
553
+ place_stop: boolean;
554
+ profit_percent: number;
555
+ entry: number;
556
+ stop: number;
557
+ avg_size: any;
558
+ avg_entry: any;
559
+ risk_reward: number;
560
+ neg_pnl: any;
561
+ risk: number;
562
+ }>;
563
+ generateConfig(payload: {
564
+ account: ExchangeType;
565
+ symbol: string;
566
+ kind: "long" | "short";
567
+ update_orders?: boolean;
568
+ place_orders?: boolean;
569
+ }): Promise<any>;
570
+ updateReduceRatio(payload: {
571
+ account: ExchangeType;
572
+ symbol: string;
573
+ }): Promise<{
574
+ long_position: any;
575
+ short_position: any;
576
+ long_db_position: any;
577
+ short_db_position: any;
578
+ balance: any;
579
+ }>;
580
+ extrapolateShortConfig(payload: {
581
+ account: ExchangeType;
582
+ kind: "long" | "short";
583
+ symbol: string;
584
+ risk_reward?: number;
585
+ }): Promise<PositionsView | {
586
+ place_stop: boolean;
587
+ profit_percent: number;
588
+ entry: number;
589
+ stop: number;
590
+ avg_size: any;
591
+ avg_entry: any;
592
+ risk_reward: number;
593
+ neg_pnl: any;
594
+ risk: number;
595
+ }>;
596
+ verifyStopLoss(payload: {
597
+ account: ExchangeType;
598
+ symbol: string;
599
+ kind: "long" | "short";
600
+ revert?: boolean;
601
+ }): Promise<import("pocketbase").RecordModel[]>;
602
+ }
603
+ export declare function initApp(payload: {
604
+ db: {
605
+ host: string;
606
+ email: string;
607
+ password: string;
608
+ };
609
+ getCredentials: (account: string, exchange: string) => (account: string) => Promise<{
610
+ api_key: string;
611
+ api_secret: string;
612
+ }>;
613
+ }): Promise<App>;
614
+
615
+ export {
616
+ ExchangeAccount$1 as ExchangeAccount,
617
+ };
618
+
619
+ export {};