@gbozee/ultimate 0.0.2-30 → 0.0.2-31
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 +235 -0
- package/dist/index.js +31 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,26 @@ import PocketBase from 'pocketbase';
|
|
|
5
5
|
import { RecordModel } from 'pocketbase';
|
|
6
6
|
import { SocksProxyAgent } from 'socks-proxy-agent';
|
|
7
7
|
|
|
8
|
+
export type GlobalConfig = {
|
|
9
|
+
profit_percent: number;
|
|
10
|
+
symbol: string;
|
|
11
|
+
profit: number;
|
|
12
|
+
risk: number;
|
|
13
|
+
stop_percent: number;
|
|
14
|
+
kind: "long" | "short";
|
|
15
|
+
reduce_percent: number;
|
|
16
|
+
support: number;
|
|
17
|
+
resistance: number;
|
|
18
|
+
price_places: string;
|
|
19
|
+
decimal_places: string;
|
|
20
|
+
min_size: number;
|
|
21
|
+
accounts: {
|
|
22
|
+
owner: string;
|
|
23
|
+
exchange?: string;
|
|
24
|
+
}[];
|
|
25
|
+
risk_reward: number;
|
|
26
|
+
reverse_factor: number;
|
|
27
|
+
};
|
|
8
28
|
interface Position$1 {
|
|
9
29
|
id: number;
|
|
10
30
|
kind: "long" | "short";
|
|
@@ -446,6 +466,144 @@ export declare class AppDatabase {
|
|
|
446
466
|
removePosition(position: any): Promise<void>;
|
|
447
467
|
removePositionConfig(position: any): Promise<void>;
|
|
448
468
|
}
|
|
469
|
+
export type SignalConfigType = {
|
|
470
|
+
focus: number;
|
|
471
|
+
budget: number;
|
|
472
|
+
percent_change?: number;
|
|
473
|
+
price_places?: string;
|
|
474
|
+
decimal_places?: string;
|
|
475
|
+
zone_risk?: number;
|
|
476
|
+
fee?: number;
|
|
477
|
+
support?: number;
|
|
478
|
+
risk_reward?: number;
|
|
479
|
+
resistance?: number;
|
|
480
|
+
risk_per_trade?: number;
|
|
481
|
+
increase_size?: boolean;
|
|
482
|
+
additional_increase?: number;
|
|
483
|
+
minimum_pnl?: number;
|
|
484
|
+
take_profit?: number;
|
|
485
|
+
increase_position?: boolean;
|
|
486
|
+
minimum_size?: number;
|
|
487
|
+
first_order_size?: number;
|
|
488
|
+
gap?: number;
|
|
489
|
+
max_size?: number;
|
|
490
|
+
};
|
|
491
|
+
declare class Signal {
|
|
492
|
+
focus: number;
|
|
493
|
+
budget: number;
|
|
494
|
+
percent_change: number;
|
|
495
|
+
price_places: string;
|
|
496
|
+
decimal_places: string;
|
|
497
|
+
zone_risk: number;
|
|
498
|
+
fee: number;
|
|
499
|
+
support?: number;
|
|
500
|
+
risk_reward: number;
|
|
501
|
+
resistance?: number;
|
|
502
|
+
risk_per_trade?: number;
|
|
503
|
+
increase_size: boolean;
|
|
504
|
+
additional_increase: number;
|
|
505
|
+
minimum_pnl: number;
|
|
506
|
+
take_profit?: number;
|
|
507
|
+
increase_position: boolean;
|
|
508
|
+
minimum_size: any;
|
|
509
|
+
first_order_size: number;
|
|
510
|
+
gap: number;
|
|
511
|
+
max_size: number;
|
|
512
|
+
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);
|
|
513
|
+
build_entry({ current_price, stop_loss, pnl, stop_percent, kind, risk, no_of_trades, take_profit, }: {
|
|
514
|
+
take_profit?: number;
|
|
515
|
+
no_of_trades?: number;
|
|
516
|
+
current_price: number;
|
|
517
|
+
stop_loss?: number;
|
|
518
|
+
kind?: "long" | "short";
|
|
519
|
+
risk: number;
|
|
520
|
+
stop_percent?: number;
|
|
521
|
+
pnl?: number;
|
|
522
|
+
}): any;
|
|
523
|
+
get risk(): number;
|
|
524
|
+
get min_trades(): number;
|
|
525
|
+
get min_price(): number;
|
|
526
|
+
build_opposite_order({ current_price, kind, }: {
|
|
527
|
+
current_price: number;
|
|
528
|
+
kind?: "long" | "short";
|
|
529
|
+
}): any;
|
|
530
|
+
special_build_orders({ current_price, kind, }: {
|
|
531
|
+
current_price: number;
|
|
532
|
+
kind?: "long" | "short";
|
|
533
|
+
}): any;
|
|
534
|
+
build_orders({ current_price, kind, limit, replace_focus, max_index, min_index, }: {
|
|
535
|
+
current_price: number;
|
|
536
|
+
kind?: "long" | "short";
|
|
537
|
+
limit?: boolean;
|
|
538
|
+
replace_focus?: boolean;
|
|
539
|
+
max_index?: number;
|
|
540
|
+
min_index?: number;
|
|
541
|
+
}): any;
|
|
542
|
+
build_orders_old({ current_price, kind, limit, replace_focus, max_index, min_index, }: {
|
|
543
|
+
current_price: number;
|
|
544
|
+
kind?: "long" | "short";
|
|
545
|
+
limit?: boolean;
|
|
546
|
+
replace_focus?: boolean;
|
|
547
|
+
max_index?: number;
|
|
548
|
+
min_index?: number;
|
|
549
|
+
}): any;
|
|
550
|
+
get_bulk_trade_zones({ current_price, kind, limit, }: {
|
|
551
|
+
current_price: number;
|
|
552
|
+
kind?: "long" | "short";
|
|
553
|
+
limit?: boolean;
|
|
554
|
+
}): any;
|
|
555
|
+
get_future_zones({ current_price, kind, raw, }: {
|
|
556
|
+
raw?: boolean;
|
|
557
|
+
current_price: number;
|
|
558
|
+
kind?: "long" | "short";
|
|
559
|
+
}): number[];
|
|
560
|
+
to_f(value: number, places?: string): number;
|
|
561
|
+
get_margin_zones({ current_price, kind, }: {
|
|
562
|
+
current_price: number;
|
|
563
|
+
kind?: "long" | "short";
|
|
564
|
+
}): number[][];
|
|
565
|
+
get_margin_range(current_price: number, kind?: string): number[];
|
|
566
|
+
process_orders({ current_price, stop_loss, trade_zones, kind, }: {
|
|
567
|
+
current_price: number;
|
|
568
|
+
stop_loss: number;
|
|
569
|
+
trade_zones: number[];
|
|
570
|
+
kind?: "long" | "short";
|
|
571
|
+
}): any[];
|
|
572
|
+
get_risk_per_trade(number_of_orders: number): number;
|
|
573
|
+
build_trade_dict({ entry, stop, risk, arr, index, new_fees, kind, start, take_profit, }: {
|
|
574
|
+
entry: number;
|
|
575
|
+
stop: number;
|
|
576
|
+
risk: number;
|
|
577
|
+
arr: number[];
|
|
578
|
+
index: number;
|
|
579
|
+
new_fees?: number;
|
|
580
|
+
kind?: "long" | "short";
|
|
581
|
+
start?: number;
|
|
582
|
+
take_profit?: number;
|
|
583
|
+
}): {
|
|
584
|
+
entry: number;
|
|
585
|
+
risk: number;
|
|
586
|
+
quantity: number;
|
|
587
|
+
sell_price: number;
|
|
588
|
+
risk_sell: number;
|
|
589
|
+
stop: number;
|
|
590
|
+
pnl: number;
|
|
591
|
+
fee: number;
|
|
592
|
+
net: number;
|
|
593
|
+
incurred: number;
|
|
594
|
+
stop_percent: number;
|
|
595
|
+
};
|
|
596
|
+
to_df(currentPrice: number, places?: string): number;
|
|
597
|
+
}
|
|
598
|
+
export declare function determine_average_entry_and_size(orders: Array<{
|
|
599
|
+
price: number;
|
|
600
|
+
quantity: number;
|
|
601
|
+
}>, places?: string, price_places?: string): {
|
|
602
|
+
entry: number;
|
|
603
|
+
price: number;
|
|
604
|
+
quantity: number;
|
|
605
|
+
};
|
|
606
|
+
export declare const createArray: (start: number, stop: number, step: number) => number[];
|
|
449
607
|
export type AppConfig = {
|
|
450
608
|
fee: number;
|
|
451
609
|
risk_per_trade: number;
|
|
@@ -474,6 +632,83 @@ export type AppConfig = {
|
|
|
474
632
|
last_value?: any;
|
|
475
633
|
entries?: any[];
|
|
476
634
|
};
|
|
635
|
+
export type ExtendConfigType = {
|
|
636
|
+
take_profit?: number;
|
|
637
|
+
entry: number;
|
|
638
|
+
risk?: number;
|
|
639
|
+
stop?: number;
|
|
640
|
+
risk_reward?: number;
|
|
641
|
+
raw_instance?: boolean;
|
|
642
|
+
no_of_trades?: number;
|
|
643
|
+
increase?: boolean;
|
|
644
|
+
price_places?: string;
|
|
645
|
+
decimal_places?: string;
|
|
646
|
+
min_profit?: number;
|
|
647
|
+
kind?: "long" | "short";
|
|
648
|
+
gap?: number;
|
|
649
|
+
rr?: number;
|
|
650
|
+
};
|
|
651
|
+
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;
|
|
652
|
+
export declare function buildAvg({ _trades, kind, }: {
|
|
653
|
+
_trades: any[];
|
|
654
|
+
kind: "long" | "short";
|
|
655
|
+
}): any;
|
|
656
|
+
export declare function sortedBuildConfig(app_config: AppConfig, options: any): any[];
|
|
657
|
+
export declare function get_app_config_and_max_size(config: GlobalConfig, payload: {
|
|
658
|
+
entry: number;
|
|
659
|
+
stop: number;
|
|
660
|
+
kind: "long" | "short";
|
|
661
|
+
}): {
|
|
662
|
+
app_config: AppConfig;
|
|
663
|
+
max_size: any;
|
|
664
|
+
last_value: any;
|
|
665
|
+
entries: {
|
|
666
|
+
entry: any;
|
|
667
|
+
avg_entry: any;
|
|
668
|
+
avg_size: any;
|
|
669
|
+
neg_pnl: any;
|
|
670
|
+
quantity: any;
|
|
671
|
+
}[];
|
|
672
|
+
};
|
|
673
|
+
export declare function buildAppConfig(config: GlobalConfig, payload: {
|
|
674
|
+
entry: number;
|
|
675
|
+
stop: number;
|
|
676
|
+
risk_reward: number;
|
|
677
|
+
risk: number;
|
|
678
|
+
symbol: string;
|
|
679
|
+
profit?: number;
|
|
680
|
+
}): AppConfig;
|
|
681
|
+
export declare function getOptimumStopAndRisk(app_config: AppConfig, params: {
|
|
682
|
+
max_size: number;
|
|
683
|
+
target_stop: number;
|
|
684
|
+
highest_risk?: number;
|
|
685
|
+
}): {
|
|
686
|
+
optimal_stop: number;
|
|
687
|
+
optimal_risk: number;
|
|
688
|
+
avg_size: any;
|
|
689
|
+
avg_entry: any;
|
|
690
|
+
result: any[];
|
|
691
|
+
first_entry: any;
|
|
692
|
+
neg_pnl: any;
|
|
693
|
+
risk_reward: number;
|
|
694
|
+
size_diff: number;
|
|
695
|
+
entry_diff: number;
|
|
696
|
+
};
|
|
697
|
+
export declare function generate_config_params(app_config: AppConfig, payload: {
|
|
698
|
+
entry: number;
|
|
699
|
+
stop: number;
|
|
700
|
+
risk_reward: number;
|
|
701
|
+
risk: number;
|
|
702
|
+
symbol: string;
|
|
703
|
+
}): {
|
|
704
|
+
entry: number;
|
|
705
|
+
stop: number;
|
|
706
|
+
avg_size: any;
|
|
707
|
+
avg_entry: any;
|
|
708
|
+
risk_reward: number;
|
|
709
|
+
neg_pnl: any;
|
|
710
|
+
risk: number;
|
|
711
|
+
};
|
|
477
712
|
declare class ExchangeAccount$1 {
|
|
478
713
|
private instance;
|
|
479
714
|
exchange: BaseExchange;
|
package/dist/index.js
CHANGED
|
@@ -33660,6 +33660,15 @@ function determine_average_entry_and_size(orders, places = "%.3f", price_places
|
|
|
33660
33660
|
quantity: to_f(total_quantity, places)
|
|
33661
33661
|
};
|
|
33662
33662
|
}
|
|
33663
|
+
var createArray = (start, stop, step) => {
|
|
33664
|
+
const result = [];
|
|
33665
|
+
let current = start;
|
|
33666
|
+
while (current <= stop) {
|
|
33667
|
+
result.push(current);
|
|
33668
|
+
current += step;
|
|
33669
|
+
}
|
|
33670
|
+
return result;
|
|
33671
|
+
};
|
|
33663
33672
|
var groupIntoPairsWithSumLessThan = (arr, targetSum, key = "quantity", firstSize = 0) => {
|
|
33664
33673
|
if (firstSize) {
|
|
33665
33674
|
const totalSize = arr.reduce((sum, order) => sum + order[key], 0);
|
|
@@ -35914,6 +35923,19 @@ function buildConfig(app_config, {
|
|
|
35914
35923
|
}) || [] : [];
|
|
35915
35924
|
return computeTotalAverageForEachTrade(result, config);
|
|
35916
35925
|
}
|
|
35926
|
+
function buildAvg({
|
|
35927
|
+
_trades,
|
|
35928
|
+
kind
|
|
35929
|
+
}) {
|
|
35930
|
+
let avg = determine_average_entry_and_size(_trades?.map((r2) => ({
|
|
35931
|
+
price: r2.entry,
|
|
35932
|
+
quantity: r2.quantity
|
|
35933
|
+
})) || []);
|
|
35934
|
+
const stop_prices = _trades.map((o) => o.stop);
|
|
35935
|
+
const stop_loss = kind === "long" ? Math.min(...stop_prices) : Math.max(...stop_prices);
|
|
35936
|
+
avg.pnl = pnl_default.determine_pnl(avg.price, stop_loss, avg.quantity, kind);
|
|
35937
|
+
return avg;
|
|
35938
|
+
}
|
|
35917
35939
|
function sortedBuildConfig(app_config, options) {
|
|
35918
35940
|
const sorted = buildConfig(app_config, options).sort((a, b) => app_config.kind === "long" ? a.entry - b.entry : b.entry - b.entry).filter((x) => {
|
|
35919
35941
|
if (app_config.symbol === "BTCUSDT") {
|
|
@@ -38213,8 +38235,17 @@ async function initialize(payload) {
|
|
|
38213
38235
|
return app;
|
|
38214
38236
|
}
|
|
38215
38237
|
export {
|
|
38238
|
+
sortedBuildConfig,
|
|
38216
38239
|
initialize,
|
|
38217
38240
|
initApp,
|
|
38241
|
+
get_app_config_and_max_size,
|
|
38242
|
+
getOptimumStopAndRisk,
|
|
38243
|
+
generate_config_params,
|
|
38244
|
+
determine_average_entry_and_size,
|
|
38245
|
+
createArray,
|
|
38246
|
+
buildConfig,
|
|
38247
|
+
buildAvg,
|
|
38248
|
+
buildAppConfig,
|
|
38218
38249
|
ExchangeAccount,
|
|
38219
38250
|
AppDatabase
|
|
38220
38251
|
};
|