@gbozee/ultimate 0.0.2-51 → 0.0.2-54
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/frontend-index.d.ts +5 -4
- package/dist/frontend-index.js +20 -9
- package/dist/index.cjs +58338 -0
- package/dist/index.d.ts +53 -8
- package/dist/index.js +76 -26
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -59,7 +59,11 @@ export interface ScheduledTrade extends BaseSystemFields {
|
|
|
59
59
|
export interface AccountStrategy extends BaseSystemFields {
|
|
60
60
|
account: string;
|
|
61
61
|
symbol: string;
|
|
62
|
-
|
|
62
|
+
tp_percent: number;
|
|
63
|
+
short_tp_factor: number;
|
|
64
|
+
fee_percent: number;
|
|
65
|
+
budget: number;
|
|
66
|
+
risk_reward: number;
|
|
63
67
|
}
|
|
64
68
|
interface Proxy$1 extends BaseSystemFields {
|
|
65
69
|
ip_address?: string;
|
|
@@ -291,6 +295,12 @@ export interface BaseExchange {
|
|
|
291
295
|
decimal_places?: string;
|
|
292
296
|
}): Promise<any>;
|
|
293
297
|
}
|
|
298
|
+
declare function initPocketBaseClient(proxy_credentials: {
|
|
299
|
+
host: string;
|
|
300
|
+
email: string;
|
|
301
|
+
password: string;
|
|
302
|
+
auto_cancellation?: boolean;
|
|
303
|
+
}): Promise<PocketBase>;
|
|
294
304
|
export type ExchangeType = {
|
|
295
305
|
owner: string;
|
|
296
306
|
exchange: string;
|
|
@@ -1096,9 +1106,6 @@ declare class ExchangeAccount$1 {
|
|
|
1096
1106
|
}): Promise<ScheduledTrade | import("pocketbase").RecordModel>;
|
|
1097
1107
|
getCurrentPrice(symbol: string): Promise<any>;
|
|
1098
1108
|
getPositionStrategy(): Promise<AccountStrategy>;
|
|
1099
|
-
toUpdate(payload: {
|
|
1100
|
-
refresh?: boolean;
|
|
1101
|
-
}): Promise<void>;
|
|
1102
1109
|
buildReduceConfig(payload: {
|
|
1103
1110
|
symbol: string;
|
|
1104
1111
|
kind?: "long" | "short";
|
|
@@ -1223,6 +1230,11 @@ declare class ExchangeAccount$1 {
|
|
|
1223
1230
|
symbol: string;
|
|
1224
1231
|
kind: "long" | "short";
|
|
1225
1232
|
}): Promise<number>;
|
|
1233
|
+
getCurrentRun(payload: {
|
|
1234
|
+
symbol: string;
|
|
1235
|
+
kind?: "long" | "short";
|
|
1236
|
+
pnl?: number;
|
|
1237
|
+
}): Promise<true | import("pocketbase").RecordModel>;
|
|
1226
1238
|
recomputeSymbolConfig(payload: {
|
|
1227
1239
|
symbol: string;
|
|
1228
1240
|
refresh?: boolean;
|
|
@@ -1292,6 +1304,20 @@ declare class ExchangeAccount$1 {
|
|
|
1292
1304
|
kind: "long" | "short";
|
|
1293
1305
|
}): Promise<void>;
|
|
1294
1306
|
}
|
|
1307
|
+
declare function getExchangeAccount(payload: {
|
|
1308
|
+
account: ExchangeType;
|
|
1309
|
+
app_db: AppDatabase;
|
|
1310
|
+
getCredentials: (account: string, exchange: string) => {
|
|
1311
|
+
api_key: string;
|
|
1312
|
+
api_secret: string;
|
|
1313
|
+
email: string;
|
|
1314
|
+
};
|
|
1315
|
+
proxyOptions?: {
|
|
1316
|
+
proxy?: any;
|
|
1317
|
+
ignore_proxy?: boolean;
|
|
1318
|
+
};
|
|
1319
|
+
canWithdraw?: boolean;
|
|
1320
|
+
}): Promise<ExchangeAccount$1>;
|
|
1295
1321
|
declare class App {
|
|
1296
1322
|
app_db: AppDatabase;
|
|
1297
1323
|
proxyOptions?: {
|
|
@@ -1424,6 +1450,11 @@ export declare function initApp(payload: {
|
|
|
1424
1450
|
canWithdraw?: boolean;
|
|
1425
1451
|
triggerToken?: string;
|
|
1426
1452
|
}): Promise<App>;
|
|
1453
|
+
declare function getCredentials(account: string, exchange: string): {
|
|
1454
|
+
api_key: string;
|
|
1455
|
+
api_secret: string;
|
|
1456
|
+
email: string;
|
|
1457
|
+
};
|
|
1427
1458
|
export declare function initialize(payload: {
|
|
1428
1459
|
password?: string;
|
|
1429
1460
|
proxy?: any;
|
|
@@ -1435,13 +1466,11 @@ export type StrategyPosition = {
|
|
|
1435
1466
|
quantity: number;
|
|
1436
1467
|
};
|
|
1437
1468
|
export type Config = {
|
|
1438
|
-
leverage: number;
|
|
1439
1469
|
tp_percent: number;
|
|
1440
1470
|
short_tp_factor: number;
|
|
1441
|
-
price_places: string;
|
|
1442
|
-
decimal_places: string;
|
|
1443
1471
|
fee_percent?: number;
|
|
1444
1472
|
budget: number;
|
|
1473
|
+
risk_reward: number;
|
|
1445
1474
|
global_config: GlobalConfig;
|
|
1446
1475
|
};
|
|
1447
1476
|
export declare class Strategy {
|
|
@@ -1455,6 +1484,8 @@ export declare class Strategy {
|
|
|
1455
1484
|
short: StrategyPosition;
|
|
1456
1485
|
config: Config;
|
|
1457
1486
|
});
|
|
1487
|
+
get price_places(): string;
|
|
1488
|
+
get decimal_places(): string;
|
|
1458
1489
|
to_f(price: number): number;
|
|
1459
1490
|
to_df(quantity: number): number;
|
|
1460
1491
|
pnl(kind: "long" | "short"): number;
|
|
@@ -1467,10 +1498,10 @@ export declare class Strategy {
|
|
|
1467
1498
|
get short_tp(): number;
|
|
1468
1499
|
generateGapClosingAlgorithm(payload: {
|
|
1469
1500
|
kind: "long" | "short";
|
|
1470
|
-
risk_reward?: number;
|
|
1471
1501
|
}): {
|
|
1472
1502
|
[x: string]: any;
|
|
1473
1503
|
risk: number;
|
|
1504
|
+
risk_reward: number;
|
|
1474
1505
|
last_entry: any;
|
|
1475
1506
|
first_entry: any;
|
|
1476
1507
|
threshold: any;
|
|
@@ -1482,14 +1513,28 @@ export declare class Strategy {
|
|
|
1482
1513
|
}): {
|
|
1483
1514
|
[x: string]: any;
|
|
1484
1515
|
risk: number;
|
|
1516
|
+
risk_reward: number;
|
|
1485
1517
|
last_entry: any;
|
|
1486
1518
|
first_entry: any;
|
|
1487
1519
|
threshold: any;
|
|
1488
1520
|
}[];
|
|
1489
1521
|
}
|
|
1490
1522
|
|
|
1523
|
+
declare namespace database {
|
|
1524
|
+
export { AppDatabase, ExchangeType, initPocketBaseClient };
|
|
1525
|
+
}
|
|
1526
|
+
declare namespace exchange_account {
|
|
1527
|
+
export { ExchangeAccount$1 as ExchangeAccount, getExchangeAccount };
|
|
1528
|
+
}
|
|
1529
|
+
declare namespace app {
|
|
1530
|
+
export { App, getCredentials, initApp, initialize };
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1491
1533
|
export {
|
|
1492
1534
|
ExchangeAccount$1 as ExchangeAccount,
|
|
1535
|
+
app,
|
|
1536
|
+
database,
|
|
1537
|
+
exchange_account,
|
|
1493
1538
|
};
|
|
1494
1539
|
|
|
1495
1540
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -41711,6 +41711,15 @@ var require_lib3 = __commonJS((exports) => {
|
|
|
41711
41711
|
__exportStar(require_enum(), exports);
|
|
41712
41712
|
});
|
|
41713
41713
|
|
|
41714
|
+
// src/app.ts
|
|
41715
|
+
var exports_app = {};
|
|
41716
|
+
__export(exports_app, {
|
|
41717
|
+
initialize: () => initialize,
|
|
41718
|
+
initApp: () => initApp,
|
|
41719
|
+
getCredentials: () => getCredentials,
|
|
41720
|
+
App: () => App
|
|
41721
|
+
});
|
|
41722
|
+
|
|
41714
41723
|
// node_modules/zod/lib/index.mjs
|
|
41715
41724
|
var util;
|
|
41716
41725
|
(function(util2) {
|
|
@@ -50103,6 +50112,11 @@ function configure(options) {
|
|
|
50103
50112
|
apiClientManager.setGlobalAPIClientConfiguration(options);
|
|
50104
50113
|
}
|
|
50105
50114
|
// src/database.ts
|
|
50115
|
+
var exports_database = {};
|
|
50116
|
+
__export(exports_database, {
|
|
50117
|
+
initPocketBaseClient: () => initPocketBaseClient,
|
|
50118
|
+
AppDatabase: () => AppDatabase
|
|
50119
|
+
});
|
|
50106
50120
|
var import_https_proxy_agent = __toESM(require_dist2(), 1);
|
|
50107
50121
|
import {
|
|
50108
50122
|
createCipheriv as createCipheriv3,
|
|
@@ -51989,6 +52003,13 @@ class AppDatabase {
|
|
|
51989
52003
|
}
|
|
51990
52004
|
}
|
|
51991
52005
|
|
|
52006
|
+
// src/exchange-account.ts
|
|
52007
|
+
var exports_exchange_account = {};
|
|
52008
|
+
__export(exports_exchange_account, {
|
|
52009
|
+
getExchangeAccount: () => getExchangeAccount,
|
|
52010
|
+
ExchangeAccount: () => ExchangeAccount
|
|
52011
|
+
});
|
|
52012
|
+
|
|
51992
52013
|
// src/exchanges/binance.ts
|
|
51993
52014
|
var import_binance = __toESM(require_lib2(), 1);
|
|
51994
52015
|
|
|
@@ -56487,23 +56508,6 @@ class ExchangeAccount {
|
|
|
56487
56508
|
async getPositionStrategy() {
|
|
56488
56509
|
return await this.app_db.getPositionStrategy(this.instance);
|
|
56489
56510
|
}
|
|
56490
|
-
async toUpdate(payload) {
|
|
56491
|
-
const { refresh } = payload;
|
|
56492
|
-
const strategy = await this.getPositionStrategy();
|
|
56493
|
-
if (!strategy) {
|
|
56494
|
-
return;
|
|
56495
|
-
}
|
|
56496
|
-
const { symbol: _symbol, watch_symbol } = strategy;
|
|
56497
|
-
const watch_positions = await this.syncAccount({
|
|
56498
|
-
symbol: watch_symbol,
|
|
56499
|
-
live_refresh: refresh,
|
|
56500
|
-
update: true
|
|
56501
|
-
});
|
|
56502
|
-
const long_watch_position = watch_positions.find((x) => x.kind === "long");
|
|
56503
|
-
const short_watch_position = watch_positions.find((x) => x.kind === "short");
|
|
56504
|
-
if (long_watch_position.quantity === short_watch_position.quantity && long_watch_position.quantity > 0) {
|
|
56505
|
-
}
|
|
56506
|
-
}
|
|
56507
56511
|
async buildReduceConfig(payload) {
|
|
56508
56512
|
const positions = await this.syncAccount({
|
|
56509
56513
|
symbol: payload.symbol
|
|
@@ -57061,6 +57065,38 @@ class ExchangeAccount {
|
|
|
57061
57065
|
}
|
|
57062
57066
|
return 0;
|
|
57063
57067
|
}
|
|
57068
|
+
async getCurrentRun(payload) {
|
|
57069
|
+
const { symbol, kind = "long", pnl } = payload;
|
|
57070
|
+
const instances = await this.app_db.pb.collection("strategy_runs").getFullList({
|
|
57071
|
+
filter: `account.owner:lower = "${this.instance.owner.toLowerCase()}" && account.exchange:lower = "${this.instance.exchange.toLowerCase()}" && symbol = "${symbol}" && kind = "${kind}" && completed = false`
|
|
57072
|
+
});
|
|
57073
|
+
if (instances.length > 0) {
|
|
57074
|
+
const instance = instances[0];
|
|
57075
|
+
if (!pnl) {
|
|
57076
|
+
return instance;
|
|
57077
|
+
}
|
|
57078
|
+
await this.app_db.pb.collection("strategy_runs").update(instance.id, {
|
|
57079
|
+
completed: true,
|
|
57080
|
+
pnl
|
|
57081
|
+
});
|
|
57082
|
+
return true;
|
|
57083
|
+
}
|
|
57084
|
+
const position2 = await this.syncAccount({
|
|
57085
|
+
symbol,
|
|
57086
|
+
kind
|
|
57087
|
+
});
|
|
57088
|
+
if (position2.quantity == 0) {
|
|
57089
|
+
return null;
|
|
57090
|
+
}
|
|
57091
|
+
return await this.app_db.pb.collection("strategy_runs").create({
|
|
57092
|
+
account: position2.account,
|
|
57093
|
+
symbol,
|
|
57094
|
+
kind,
|
|
57095
|
+
entry: position2.entry,
|
|
57096
|
+
quantity: position2.quantity,
|
|
57097
|
+
completed: false
|
|
57098
|
+
});
|
|
57099
|
+
}
|
|
57064
57100
|
async recomputeSymbolConfig(payload) {
|
|
57065
57101
|
const { symbol, refresh = false } = payload;
|
|
57066
57102
|
const _config = await this.app_db.getSymbolConfigFromDB(symbol);
|
|
@@ -58084,11 +58120,17 @@ class Strategy {
|
|
|
58084
58120
|
this.config.fee_percent = 0.05;
|
|
58085
58121
|
}
|
|
58086
58122
|
}
|
|
58123
|
+
get price_places() {
|
|
58124
|
+
return this.config.global_config.price_places;
|
|
58125
|
+
}
|
|
58126
|
+
get decimal_places() {
|
|
58127
|
+
return this.config.global_config.decimal_places;
|
|
58128
|
+
}
|
|
58087
58129
|
to_f(price) {
|
|
58088
|
-
return to_f(price, this.
|
|
58130
|
+
return to_f(price, this.price_places);
|
|
58089
58131
|
}
|
|
58090
58132
|
to_df(quantity) {
|
|
58091
|
-
return to_f(quantity, this.
|
|
58133
|
+
return to_f(quantity, this.decimal_places);
|
|
58092
58134
|
}
|
|
58093
58135
|
pnl(kind) {
|
|
58094
58136
|
const position2 = this.position[kind];
|
|
@@ -58120,15 +58162,20 @@ class Strategy {
|
|
|
58120
58162
|
return this.tp("short");
|
|
58121
58163
|
}
|
|
58122
58164
|
generateGapClosingAlgorithm(payload) {
|
|
58123
|
-
const { kind
|
|
58165
|
+
const { kind } = payload;
|
|
58124
58166
|
const { entry, quantity } = this.position[kind];
|
|
58125
58167
|
const focus_position = this.position[kind];
|
|
58126
58168
|
const reverse_kind = kind == "long" ? "short" : "long";
|
|
58127
58169
|
const reverse_position = this.position[reverse_kind];
|
|
58170
|
+
let _entry = this.tp(kind);
|
|
58171
|
+
let _stop = this.tp(reverse_kind);
|
|
58172
|
+
if (!_entry && !_stop) {
|
|
58173
|
+
return null;
|
|
58174
|
+
}
|
|
58128
58175
|
const second_payload = {
|
|
58129
|
-
entry:
|
|
58130
|
-
stop:
|
|
58131
|
-
risk_reward,
|
|
58176
|
+
entry: _entry,
|
|
58177
|
+
stop: _stop,
|
|
58178
|
+
risk_reward: this.config.risk_reward,
|
|
58132
58179
|
start_risk: this.pnl(reverse_kind),
|
|
58133
58180
|
max_risk: this.config.budget
|
|
58134
58181
|
};
|
|
@@ -58205,6 +58252,7 @@ class Strategy {
|
|
|
58205
58252
|
const remaining_quantity = this.to_df(avg.quantity - quantity_to_sell);
|
|
58206
58253
|
return {
|
|
58207
58254
|
risk,
|
|
58255
|
+
risk_reward: this.config.risk_reward,
|
|
58208
58256
|
[kind]: {
|
|
58209
58257
|
avg_entry: avg.entry,
|
|
58210
58258
|
avg_size: avg.quantity,
|
|
@@ -58229,7 +58277,7 @@ class Strategy {
|
|
|
58229
58277
|
};
|
|
58230
58278
|
}
|
|
58231
58279
|
runIterations(payload) {
|
|
58232
|
-
const { kind, iterations
|
|
58280
|
+
const { kind, iterations } = payload;
|
|
58233
58281
|
const reverse_kind = kind == "long" ? "short" : "long";
|
|
58234
58282
|
const result = [];
|
|
58235
58283
|
let position2 = {
|
|
@@ -58246,8 +58294,7 @@ class Strategy {
|
|
|
58246
58294
|
}
|
|
58247
58295
|
});
|
|
58248
58296
|
const algorithm = instance.generateGapClosingAlgorithm({
|
|
58249
|
-
kind
|
|
58250
|
-
risk_reward
|
|
58297
|
+
kind
|
|
58251
58298
|
});
|
|
58252
58299
|
if (!algorithm) {
|
|
58253
58300
|
console.log("No algorithm found");
|
|
@@ -58275,13 +58322,16 @@ export {
|
|
|
58275
58322
|
getOptimumStopAndRisk,
|
|
58276
58323
|
generate_config_params,
|
|
58277
58324
|
generateOptimumAppConfig,
|
|
58325
|
+
exports_exchange_account as exchange_account,
|
|
58278
58326
|
determine_break_even_price,
|
|
58279
58327
|
determine_average_entry_and_size,
|
|
58280
58328
|
determine_amount_to_buy,
|
|
58329
|
+
exports_database as database,
|
|
58281
58330
|
createArray,
|
|
58282
58331
|
buildConfig,
|
|
58283
58332
|
buildAvg,
|
|
58284
58333
|
buildAppConfig,
|
|
58334
|
+
exports_app as app,
|
|
58285
58335
|
Strategy,
|
|
58286
58336
|
ExchangeAccount,
|
|
58287
58337
|
AppDatabase
|