@gbozee/ultimate 0.0.2-112 → 0.0.2-114
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.cjs +362 -396
- package/dist/index.d.ts +113 -27
- package/dist/index.js +362 -396
- package/dist/mcp-server.cjs +356 -357
- package/dist/mcp-server.js +356 -357
- package/package.json +2 -2
package/dist/mcp-server.js
CHANGED
|
@@ -61430,13 +61430,207 @@ class Strategy {
|
|
|
61430
61430
|
|
|
61431
61431
|
// src/exchanges/binance.ts
|
|
61432
61432
|
var import_binance = __toESM(require_lib2(), 1);
|
|
61433
|
-
|
|
61434
61433
|
// src/types/index.ts
|
|
61435
61434
|
class BaseExchange {
|
|
61436
61435
|
client;
|
|
61436
|
+
getCredentials;
|
|
61437
|
+
proxyAgent;
|
|
61437
61438
|
constructor(client) {
|
|
61438
61439
|
this.client = client;
|
|
61439
61440
|
}
|
|
61441
|
+
async rawCreateLimitPurchaseOrders(payload) {
|
|
61442
|
+
const { symbol, orders, price_places, decimal_places } = payload;
|
|
61443
|
+
return this._createLimitPurchaseOrders({
|
|
61444
|
+
symbol,
|
|
61445
|
+
price_places,
|
|
61446
|
+
decimal_places,
|
|
61447
|
+
orders
|
|
61448
|
+
});
|
|
61449
|
+
}
|
|
61450
|
+
async placeStopOrders(payload) {
|
|
61451
|
+
if (payload.place) {
|
|
61452
|
+
const current_price = await this.getCurrentPrice(payload.symbol);
|
|
61453
|
+
return this._placeStopOrder({
|
|
61454
|
+
symbol: payload.symbol,
|
|
61455
|
+
stop: payload.stop,
|
|
61456
|
+
final_stop: payload.stop,
|
|
61457
|
+
quantity: Math.abs(payload.quantity),
|
|
61458
|
+
kind: payload.kind,
|
|
61459
|
+
cancel: true,
|
|
61460
|
+
is_limit: true,
|
|
61461
|
+
price_places: payload.price_places,
|
|
61462
|
+
decimal_places: payload.decimal_places,
|
|
61463
|
+
current_price
|
|
61464
|
+
});
|
|
61465
|
+
}
|
|
61466
|
+
}
|
|
61467
|
+
async bulkPlaceLimitOrders(payload) {
|
|
61468
|
+
const {
|
|
61469
|
+
orders,
|
|
61470
|
+
kind,
|
|
61471
|
+
decimal_places = "%.3f",
|
|
61472
|
+
price_places = "%.1f",
|
|
61473
|
+
symbol,
|
|
61474
|
+
place = false
|
|
61475
|
+
} = payload;
|
|
61476
|
+
const totalQuantity = orders.reduce((sum, order) => sum + (order.quantity || 0), 0);
|
|
61477
|
+
let runningTotal = to_f2(totalQuantity, decimal_places);
|
|
61478
|
+
let sortedOrders = [...orders].sort((a, b) => (a.entry || 0) - (b.entry || 0));
|
|
61479
|
+
if (kind === "short") {
|
|
61480
|
+
sortedOrders.reverse();
|
|
61481
|
+
}
|
|
61482
|
+
const withCumulative = [];
|
|
61483
|
+
for (const order of sortedOrders) {
|
|
61484
|
+
withCumulative.push({
|
|
61485
|
+
...order,
|
|
61486
|
+
cumulative_quantity: runningTotal
|
|
61487
|
+
});
|
|
61488
|
+
runningTotal -= order.quantity;
|
|
61489
|
+
runningTotal = to_f2(runningTotal, decimal_places);
|
|
61490
|
+
}
|
|
61491
|
+
const positions = await this.getPositionInfo(symbol);
|
|
61492
|
+
const position2 = positions[kind] || {
|
|
61493
|
+
kind,
|
|
61494
|
+
size: 0,
|
|
61495
|
+
entryPrice: 0,
|
|
61496
|
+
symbol
|
|
61497
|
+
};
|
|
61498
|
+
const filteredOrders = withCumulative.filter((order) => (order.cumulative_quantity || 0) > position2.size).map((order) => ({
|
|
61499
|
+
...order,
|
|
61500
|
+
price: order.entry,
|
|
61501
|
+
kind,
|
|
61502
|
+
side: kind.toLowerCase() === "long" ? "buy" : "sell"
|
|
61503
|
+
}));
|
|
61504
|
+
if (filteredOrders.length > 0 && place) {
|
|
61505
|
+
await this.cancelAllOrders(symbol, {
|
|
61506
|
+
type: "limit",
|
|
61507
|
+
kind
|
|
61508
|
+
});
|
|
61509
|
+
await this._createLimitPurchaseOrders({
|
|
61510
|
+
symbol,
|
|
61511
|
+
orders: filteredOrders,
|
|
61512
|
+
price_places,
|
|
61513
|
+
decimal_places
|
|
61514
|
+
});
|
|
61515
|
+
}
|
|
61516
|
+
return filteredOrders;
|
|
61517
|
+
}
|
|
61518
|
+
async get_current_price(symbol) {
|
|
61519
|
+
return await this.getCurrentPrice(symbol);
|
|
61520
|
+
}
|
|
61521
|
+
async getExchangeAccountInfo(options) {
|
|
61522
|
+
const {
|
|
61523
|
+
price_places = "%.1f",
|
|
61524
|
+
decimal_places = "%.3f",
|
|
61525
|
+
account,
|
|
61526
|
+
symbol
|
|
61527
|
+
} = options;
|
|
61528
|
+
return await this.getExchangeInfo({
|
|
61529
|
+
price_places,
|
|
61530
|
+
decimal_places,
|
|
61531
|
+
account,
|
|
61532
|
+
symbol
|
|
61533
|
+
});
|
|
61534
|
+
}
|
|
61535
|
+
async cancelOrders(payload) {
|
|
61536
|
+
return await this._cancelOrders({
|
|
61537
|
+
symbol: payload.symbol,
|
|
61538
|
+
orders: payload.orders.map((x) => ({ orderId: x }))
|
|
61539
|
+
});
|
|
61540
|
+
}
|
|
61541
|
+
async placeTpOrder(payload) {
|
|
61542
|
+
return await this._placeTpOrder({
|
|
61543
|
+
symbol: payload.symbol,
|
|
61544
|
+
tp: payload.take_profit,
|
|
61545
|
+
kind: payload.kind,
|
|
61546
|
+
quantity: payload.quantity,
|
|
61547
|
+
cancel: true,
|
|
61548
|
+
price_places: payload.price_places,
|
|
61549
|
+
decimal_places: payload.decimal_places
|
|
61550
|
+
});
|
|
61551
|
+
}
|
|
61552
|
+
async placeLimitOrder(payload) {
|
|
61553
|
+
return await this.placeLimitOrders({
|
|
61554
|
+
symbol: payload.symbol,
|
|
61555
|
+
orders: [
|
|
61556
|
+
{
|
|
61557
|
+
entry: payload.price,
|
|
61558
|
+
quantity: payload.quantity
|
|
61559
|
+
}
|
|
61560
|
+
],
|
|
61561
|
+
kind: payload.kind,
|
|
61562
|
+
price_places: payload.price_places,
|
|
61563
|
+
decimal_places: payload.decimal_places
|
|
61564
|
+
});
|
|
61565
|
+
}
|
|
61566
|
+
async placeStopOrder(payload) {
|
|
61567
|
+
const current_price = await this.getCurrentPrice(payload.symbol);
|
|
61568
|
+
return await this._placeStopOrder({
|
|
61569
|
+
symbol: payload.symbol,
|
|
61570
|
+
stop: payload.stop,
|
|
61571
|
+
final_stop: payload.stop,
|
|
61572
|
+
quantity: Math.abs(payload.quantity),
|
|
61573
|
+
kind: payload.kind,
|
|
61574
|
+
cancel: true,
|
|
61575
|
+
is_limit: true,
|
|
61576
|
+
price_places: payload.price_places,
|
|
61577
|
+
decimal_places: payload.decimal_places,
|
|
61578
|
+
current_price
|
|
61579
|
+
});
|
|
61580
|
+
}
|
|
61581
|
+
async closePosition(payload) {
|
|
61582
|
+
const { symbol, kind, price_places, decimal_places } = payload;
|
|
61583
|
+
const currentPrice = await this.getCurrentPrice(symbol);
|
|
61584
|
+
return this.placeTpOrder({
|
|
61585
|
+
price_places,
|
|
61586
|
+
decimal_places,
|
|
61587
|
+
symbol,
|
|
61588
|
+
take_profit: currentPrice,
|
|
61589
|
+
kind
|
|
61590
|
+
});
|
|
61591
|
+
}
|
|
61592
|
+
async getAllOpenSymbols() {
|
|
61593
|
+
const response = await this.getAllOpenOrders();
|
|
61594
|
+
return Array.from(new Set(response.map((x) => x.symbol)));
|
|
61595
|
+
}
|
|
61596
|
+
async createLimitPurchaseOrders(payload) {
|
|
61597
|
+
const {
|
|
61598
|
+
orders,
|
|
61599
|
+
kind,
|
|
61600
|
+
decimal_places = "%.3f",
|
|
61601
|
+
price_places = "%.1f",
|
|
61602
|
+
symbol
|
|
61603
|
+
} = payload;
|
|
61604
|
+
return await this._createLimitPurchaseOrders({
|
|
61605
|
+
symbol,
|
|
61606
|
+
price_places,
|
|
61607
|
+
decimal_places,
|
|
61608
|
+
orders: orders.map((order) => ({
|
|
61609
|
+
...order,
|
|
61610
|
+
price: order.entry,
|
|
61611
|
+
kind,
|
|
61612
|
+
side: kind.toLowerCase() === "long" ? "buy" : "sell"
|
|
61613
|
+
}))
|
|
61614
|
+
});
|
|
61615
|
+
}
|
|
61616
|
+
async placeMarketOrder(payload) {
|
|
61617
|
+
const { symbol, kind, quantity, price_places, decimal_places } = payload;
|
|
61618
|
+
const currentPrice = await this.get_current_price(symbol);
|
|
61619
|
+
return this._createLimitPurchaseOrders({
|
|
61620
|
+
symbol,
|
|
61621
|
+
price_places,
|
|
61622
|
+
decimal_places,
|
|
61623
|
+
orders: [
|
|
61624
|
+
{
|
|
61625
|
+
force_market: true,
|
|
61626
|
+
side: kind === "long" ? "buy" : "sell",
|
|
61627
|
+
kind,
|
|
61628
|
+
quantity,
|
|
61629
|
+
price: currentPrice
|
|
61630
|
+
}
|
|
61631
|
+
]
|
|
61632
|
+
});
|
|
61633
|
+
}
|
|
61440
61634
|
async customStopLoss(payload) {
|
|
61441
61635
|
const {
|
|
61442
61636
|
symbol,
|
|
@@ -61475,6 +61669,33 @@ class BaseExchange {
|
|
|
61475
61669
|
decimal_places
|
|
61476
61670
|
});
|
|
61477
61671
|
}
|
|
61672
|
+
async placeBadStopEntry(payload) {
|
|
61673
|
+
const { symbol, orders, price_places, decimal_places } = payload;
|
|
61674
|
+
const openOrders = await this.getOpenOrders({ symbol });
|
|
61675
|
+
const existingBadEntry = openOrders.filter((k) => {
|
|
61676
|
+
if (k.stopPrice > 0) {
|
|
61677
|
+
if (k.kind === "long" && k.price > k.stopPrice || k.kind === "short" && k.price < k.stopPrice) {
|
|
61678
|
+
return true;
|
|
61679
|
+
}
|
|
61680
|
+
return false;
|
|
61681
|
+
}
|
|
61682
|
+
return false;
|
|
61683
|
+
});
|
|
61684
|
+
if (existingBadEntry.length > 0) {
|
|
61685
|
+
console.log("Cancelling existing bad entry");
|
|
61686
|
+
await this._cancelOrders({
|
|
61687
|
+
symbol,
|
|
61688
|
+
orders: existingBadEntry.map((x) => ({ orderId: x.orderId }))
|
|
61689
|
+
});
|
|
61690
|
+
}
|
|
61691
|
+
console.log("Placing new order");
|
|
61692
|
+
return this._createLimitPurchaseOrders({
|
|
61693
|
+
symbol,
|
|
61694
|
+
price_places,
|
|
61695
|
+
decimal_places,
|
|
61696
|
+
orders
|
|
61697
|
+
});
|
|
61698
|
+
}
|
|
61478
61699
|
async analyzeCandlesticks(payload) {
|
|
61479
61700
|
const { symbol } = payload;
|
|
61480
61701
|
const arr = [
|
|
@@ -61525,6 +61746,10 @@ class BaseExchange {
|
|
|
61525
61746
|
minimum_weekly: minimumWeekly
|
|
61526
61747
|
};
|
|
61527
61748
|
}
|
|
61749
|
+
setAccountDetails(payload) {
|
|
61750
|
+
this.getCredentials = payload.getCredentials;
|
|
61751
|
+
this.proxyAgent = payload.proxyAgent;
|
|
61752
|
+
}
|
|
61528
61753
|
}
|
|
61529
61754
|
|
|
61530
61755
|
// src/exchanges/binance.ts
|
|
@@ -62310,98 +62535,22 @@ async function getAllOpenOrders(payload) {
|
|
|
62310
62535
|
class BinanceExchange extends BaseExchange {
|
|
62311
62536
|
client;
|
|
62312
62537
|
main_client;
|
|
62313
|
-
getCredentials;
|
|
62314
|
-
proxyAgent;
|
|
62315
62538
|
constructor(client, main_client) {
|
|
62316
62539
|
super(client);
|
|
62317
62540
|
this.client = client;
|
|
62318
62541
|
this.main_client = main_client;
|
|
62319
62542
|
}
|
|
62320
|
-
|
|
62321
|
-
this.
|
|
62322
|
-
this.proxyAgent = payload.proxyAgent;
|
|
62323
|
-
}
|
|
62324
|
-
async placeStopOrders(payload) {
|
|
62325
|
-
if (payload.place) {
|
|
62326
|
-
const current_price = await this.get_current_price(payload.symbol);
|
|
62327
|
-
return placeStopOrder(this.client, {
|
|
62328
|
-
symbol: payload.symbol,
|
|
62329
|
-
stop: payload.stop,
|
|
62330
|
-
final_stop: payload.stop,
|
|
62331
|
-
quantity: Math.abs(payload.quantity),
|
|
62332
|
-
kind: payload.kind,
|
|
62333
|
-
cancel: true,
|
|
62334
|
-
is_limit: true,
|
|
62335
|
-
price_places: payload.price_places,
|
|
62336
|
-
decimal_places: payload.decimal_places,
|
|
62337
|
-
current_price
|
|
62338
|
-
});
|
|
62339
|
-
}
|
|
62543
|
+
async getPositionInfo(symbol) {
|
|
62544
|
+
return await getPositionInfo(this.client, symbol);
|
|
62340
62545
|
}
|
|
62341
|
-
async
|
|
62342
|
-
|
|
62343
|
-
orders,
|
|
62344
|
-
kind,
|
|
62345
|
-
decimal_places = "%.3f",
|
|
62346
|
-
price_places = "%.1f",
|
|
62347
|
-
symbol
|
|
62348
|
-
} = payload;
|
|
62349
|
-
const _orders = orders.map((order) => ({
|
|
62350
|
-
...order,
|
|
62351
|
-
price: order.entry,
|
|
62352
|
-
kind,
|
|
62353
|
-
side: kind.toLowerCase() === "long" ? "buy" : "sell"
|
|
62354
|
-
}));
|
|
62355
|
-
return await createLimitPurchaseOrders(this.client, symbol, price_places, decimal_places, _orders);
|
|
62546
|
+
async getCurrentPrice(symbol) {
|
|
62547
|
+
return await getCurrentPrice(this.client, symbol);
|
|
62356
62548
|
}
|
|
62357
|
-
async
|
|
62358
|
-
|
|
62359
|
-
orders,
|
|
62360
|
-
kind,
|
|
62361
|
-
decimal_places = "%.3f",
|
|
62362
|
-
price_places = "%.1f",
|
|
62363
|
-
symbol,
|
|
62364
|
-
place = false
|
|
62365
|
-
} = payload;
|
|
62366
|
-
const totalQuantity = orders.reduce((sum, order) => sum + (order.quantity || 0), 0);
|
|
62367
|
-
let runningTotal = to_f2(totalQuantity, decimal_places);
|
|
62368
|
-
let sortedOrders = [...orders].sort((a, b) => (a.entry || 0) - (b.entry || 0));
|
|
62369
|
-
if (kind === "short") {
|
|
62370
|
-
sortedOrders.reverse();
|
|
62371
|
-
}
|
|
62372
|
-
const withCumulative = [];
|
|
62373
|
-
for (const order of sortedOrders) {
|
|
62374
|
-
withCumulative.push({
|
|
62375
|
-
...order,
|
|
62376
|
-
cumulative_quantity: runningTotal
|
|
62377
|
-
});
|
|
62378
|
-
runningTotal -= order.quantity;
|
|
62379
|
-
runningTotal = to_f2(runningTotal, decimal_places);
|
|
62380
|
-
}
|
|
62381
|
-
const positions = await getPositionInfo(this.client, symbol);
|
|
62382
|
-
const position2 = positions[kind] || {
|
|
62383
|
-
kind,
|
|
62384
|
-
size: 0,
|
|
62385
|
-
entryPrice: 0,
|
|
62386
|
-
symbol
|
|
62387
|
-
};
|
|
62388
|
-
const filteredOrders = withCumulative.filter((order) => (order.cumulative_quantity || 0) > position2.size).map((order) => ({
|
|
62389
|
-
...order,
|
|
62390
|
-
price: order.entry,
|
|
62391
|
-
kind,
|
|
62392
|
-
side: kind.toLowerCase() === "long" ? "buy" : "sell"
|
|
62393
|
-
}));
|
|
62394
|
-
if (filteredOrders.length > 0 && place) {
|
|
62395
|
-
await cancelAllOrders(this.client, symbol, {
|
|
62396
|
-
type: "limit",
|
|
62397
|
-
kind
|
|
62398
|
-
});
|
|
62399
|
-
await createLimitPurchaseOrders(this.client, symbol, price_places, decimal_places, filteredOrders);
|
|
62400
|
-
}
|
|
62401
|
-
return filteredOrders;
|
|
62549
|
+
async cancelAllOrders(symbol, payload) {
|
|
62550
|
+
return await cancelAllOrders(this.client, symbol, payload);
|
|
62402
62551
|
}
|
|
62403
|
-
async
|
|
62404
|
-
return await
|
|
62552
|
+
async _createLimitPurchaseOrders(payload) {
|
|
62553
|
+
return await createLimitPurchaseOrders(this.client, payload.symbol, payload.price_places, payload.decimal_places, payload.orders);
|
|
62405
62554
|
}
|
|
62406
62555
|
async analyzeCharts(payload) {
|
|
62407
62556
|
return await analyzeCharts({
|
|
@@ -62412,67 +62561,30 @@ class BinanceExchange extends BaseExchange {
|
|
|
62412
62561
|
raw: payload.raw
|
|
62413
62562
|
});
|
|
62414
62563
|
}
|
|
62415
|
-
async
|
|
62416
|
-
const {
|
|
62417
|
-
price_places = "%.1f",
|
|
62418
|
-
decimal_places = "%.3f",
|
|
62419
|
-
account,
|
|
62420
|
-
symbol
|
|
62421
|
-
} = options;
|
|
62564
|
+
async getExchangeInfo(options) {
|
|
62422
62565
|
return await fetchBinanceAccount(this.client, {
|
|
62423
|
-
owner: account.owner,
|
|
62424
|
-
symbol
|
|
62566
|
+
owner: options.account.owner,
|
|
62567
|
+
symbol: options.symbol
|
|
62425
62568
|
}, {
|
|
62426
|
-
price_places,
|
|
62427
|
-
decimal_places
|
|
62569
|
+
price_places: options.price_places,
|
|
62570
|
+
decimal_places: options.decimal_places
|
|
62428
62571
|
});
|
|
62429
62572
|
}
|
|
62430
|
-
async
|
|
62573
|
+
async _cancelOrders(payload) {
|
|
62431
62574
|
return await cancelOrders({
|
|
62432
62575
|
symbol: payload.symbol,
|
|
62433
|
-
orders: payload.orders
|
|
62576
|
+
orders: payload.orders,
|
|
62434
62577
|
custom_client: this.client
|
|
62435
62578
|
});
|
|
62436
62579
|
}
|
|
62437
|
-
async
|
|
62438
|
-
return await placeTpOrder(this.client,
|
|
62439
|
-
symbol: payload.symbol,
|
|
62440
|
-
tp: payload.take_profit,
|
|
62441
|
-
kind: payload.kind,
|
|
62442
|
-
quantity: payload.quantity,
|
|
62443
|
-
cancel: true,
|
|
62444
|
-
price_places: payload.price_places,
|
|
62445
|
-
decimal_places: payload.decimal_places
|
|
62446
|
-
});
|
|
62580
|
+
async _placeTpOrder(payload) {
|
|
62581
|
+
return await placeTpOrder(this.client, payload);
|
|
62447
62582
|
}
|
|
62448
|
-
async
|
|
62449
|
-
return await placeLimitOrders(this.client,
|
|
62450
|
-
symbol: payload.symbol,
|
|
62451
|
-
orders: [
|
|
62452
|
-
{
|
|
62453
|
-
entry: payload.price,
|
|
62454
|
-
quantity: payload.quantity
|
|
62455
|
-
}
|
|
62456
|
-
],
|
|
62457
|
-
kind: payload.kind,
|
|
62458
|
-
price_places: payload.price_places,
|
|
62459
|
-
decimal_places: payload.decimal_places
|
|
62460
|
-
});
|
|
62583
|
+
async placeLimitOrders(payload) {
|
|
62584
|
+
return await placeLimitOrders(this.client, payload);
|
|
62461
62585
|
}
|
|
62462
|
-
async
|
|
62463
|
-
|
|
62464
|
-
return await placeStopOrder(this.client, {
|
|
62465
|
-
symbol: payload.symbol,
|
|
62466
|
-
stop: payload.stop,
|
|
62467
|
-
final_stop: payload.stop,
|
|
62468
|
-
quantity: Math.abs(payload.quantity),
|
|
62469
|
-
kind: payload.kind,
|
|
62470
|
-
cancel: true,
|
|
62471
|
-
is_limit: true,
|
|
62472
|
-
price_places: payload.price_places,
|
|
62473
|
-
decimal_places: payload.decimal_places,
|
|
62474
|
-
current_price
|
|
62475
|
-
});
|
|
62586
|
+
async _placeStopOrder(payload) {
|
|
62587
|
+
return await placeStopOrder(this.client, payload);
|
|
62476
62588
|
}
|
|
62477
62589
|
async setLeverage(payload) {
|
|
62478
62590
|
let maxLeverage = payload.leverage;
|
|
@@ -62566,20 +62678,8 @@ class BinanceExchange extends BaseExchange {
|
|
|
62566
62678
|
const _movers = activeMovers.filter((m) => !toBeDelisted.includes(m.symbol));
|
|
62567
62679
|
return { movers: _movers, delisted };
|
|
62568
62680
|
}
|
|
62569
|
-
async
|
|
62570
|
-
|
|
62571
|
-
const currentPrice = await this.get_current_price(symbol);
|
|
62572
|
-
return this.placeTpOrder({
|
|
62573
|
-
price_places,
|
|
62574
|
-
decimal_places,
|
|
62575
|
-
symbol,
|
|
62576
|
-
take_profit: currentPrice,
|
|
62577
|
-
kind
|
|
62578
|
-
});
|
|
62579
|
-
}
|
|
62580
|
-
async getAllOpenSymbols() {
|
|
62581
|
-
const response = await getAllOpenOrders({ client: this.client });
|
|
62582
|
-
return Array.from(new Set(response.map((x) => x.symbol)));
|
|
62681
|
+
async getAllOpenOrders() {
|
|
62682
|
+
return await getAllOpenOrders({ client: this.client });
|
|
62583
62683
|
}
|
|
62584
62684
|
async getDelistedSpotSymbols() {
|
|
62585
62685
|
if (this.main_client) {
|
|
@@ -62612,49 +62712,9 @@ class BinanceExchange extends BaseExchange {
|
|
|
62612
62712
|
return result;
|
|
62613
62713
|
}
|
|
62614
62714
|
}
|
|
62615
|
-
async placeMarketOrder(payload) {
|
|
62616
|
-
const { symbol, kind, quantity, price_places, decimal_places } = payload;
|
|
62617
|
-
const currentPrice = await this.get_current_price(symbol);
|
|
62618
|
-
return createLimitPurchaseOrders(this.client, symbol, price_places, decimal_places, [
|
|
62619
|
-
{
|
|
62620
|
-
force_market: true,
|
|
62621
|
-
side: kind === "long" ? "buy" : "sell",
|
|
62622
|
-
kind,
|
|
62623
|
-
quantity,
|
|
62624
|
-
price: currentPrice
|
|
62625
|
-
}
|
|
62626
|
-
]);
|
|
62627
|
-
}
|
|
62628
|
-
async rawCreateLimitPurchaseOrders(payload) {
|
|
62629
|
-
const { symbol, orders, price_places, decimal_places } = payload;
|
|
62630
|
-
return createLimitPurchaseOrders(this.client, symbol, price_places, decimal_places, orders);
|
|
62631
|
-
}
|
|
62632
62715
|
async getOpenOrders(payload) {
|
|
62633
62716
|
return await getOpenOrders(this.client, payload.symbol);
|
|
62634
62717
|
}
|
|
62635
|
-
async placeBadStopEntry(payload) {
|
|
62636
|
-
const { symbol, orders, price_places, decimal_places } = payload;
|
|
62637
|
-
const openOrders = await this.getOpenOrders({ symbol });
|
|
62638
|
-
const existingBadEntry = openOrders.filter((k) => {
|
|
62639
|
-
if (k.stopPrice > 0) {
|
|
62640
|
-
if (k.kind === "long" && k.price > k.stopPrice || k.kind === "short" && k.price < k.stopPrice) {
|
|
62641
|
-
return true;
|
|
62642
|
-
}
|
|
62643
|
-
return false;
|
|
62644
|
-
}
|
|
62645
|
-
return false;
|
|
62646
|
-
});
|
|
62647
|
-
if (existingBadEntry.length > 0) {
|
|
62648
|
-
console.log("Cancelling existing bad entry");
|
|
62649
|
-
await cancelOrders({
|
|
62650
|
-
symbol,
|
|
62651
|
-
orders: existingBadEntry.map((x) => ({ orderId: x.orderId })),
|
|
62652
|
-
custom_client: this.client
|
|
62653
|
-
});
|
|
62654
|
-
}
|
|
62655
|
-
console.log("Placing new order");
|
|
62656
|
-
return createLimitPurchaseOrders(this.client, symbol, price_places, decimal_places, orders);
|
|
62657
|
-
}
|
|
62658
62718
|
}
|
|
62659
62719
|
function getPricePlaces(target) {
|
|
62660
62720
|
const numStr = target.toString();
|
|
@@ -62852,10 +62912,11 @@ async function placeStopOrder2(client, payload) {
|
|
|
62852
62912
|
kind: payload.kind
|
|
62853
62913
|
});
|
|
62854
62914
|
}
|
|
62915
|
+
const spread = 1.00005;
|
|
62855
62916
|
const order = {
|
|
62856
62917
|
kind: payload.kind,
|
|
62857
62918
|
side: payload.kind === "long" ? "sell" : "buy",
|
|
62858
|
-
price: payload.stop,
|
|
62919
|
+
price: payload.kind === "long" ? payload.stop * spread ** -1 : payload.stop * spread,
|
|
62859
62920
|
quantity: payload.quantity,
|
|
62860
62921
|
stop: payload.final_stop,
|
|
62861
62922
|
is_market: !payload.is_limit
|
|
@@ -63151,6 +63212,28 @@ async function analyzeCharts2(params) {
|
|
|
63151
63212
|
}
|
|
63152
63213
|
return finalPairs;
|
|
63153
63214
|
}
|
|
63215
|
+
async function getAllOpenOrders2(payload) {
|
|
63216
|
+
const { client, currency = "USDT" } = payload;
|
|
63217
|
+
const response = await client.getActiveOrders({
|
|
63218
|
+
category: "linear",
|
|
63219
|
+
openOnly: 0,
|
|
63220
|
+
settleCoin: currency
|
|
63221
|
+
});
|
|
63222
|
+
let cursor = response.result.nextPageCursor;
|
|
63223
|
+
const orders = response.result.list || [];
|
|
63224
|
+
while (Boolean(cursor)) {
|
|
63225
|
+
const nextResponse = await client.getActiveOrders({
|
|
63226
|
+
category: "linear",
|
|
63227
|
+
openOnly: 0,
|
|
63228
|
+
settleCoin: currency,
|
|
63229
|
+
cursor
|
|
63230
|
+
});
|
|
63231
|
+
orders.push(...nextResponse.result.list);
|
|
63232
|
+
cursor = nextResponse.result.nextPageCursor;
|
|
63233
|
+
console.log("getAllOpenOrders cursor", cursor);
|
|
63234
|
+
}
|
|
63235
|
+
return orders;
|
|
63236
|
+
}
|
|
63154
63237
|
|
|
63155
63238
|
class BybitExchange extends BaseExchange {
|
|
63156
63239
|
client;
|
|
@@ -63160,68 +63243,16 @@ class BybitExchange extends BaseExchange {
|
|
|
63160
63243
|
this.client = client;
|
|
63161
63244
|
this.main_client = main_client;
|
|
63162
63245
|
}
|
|
63163
|
-
async
|
|
63164
|
-
|
|
63165
|
-
return placeStopOrder2(this.client, {
|
|
63166
|
-
symbol: payload.symbol,
|
|
63167
|
-
stop: payload.stop,
|
|
63168
|
-
final_stop: payload.stop,
|
|
63169
|
-
quantity: Math.abs(payload.quantity),
|
|
63170
|
-
kind: payload.kind,
|
|
63171
|
-
cancel: true,
|
|
63172
|
-
is_limit: true,
|
|
63173
|
-
price_places: payload.price_places,
|
|
63174
|
-
decimal_places: payload.decimal_places
|
|
63175
|
-
});
|
|
63176
|
-
}
|
|
63246
|
+
async getPositionInfo(symbol) {
|
|
63247
|
+
return await getPositionInfo2(this.client, symbol);
|
|
63177
63248
|
}
|
|
63178
|
-
async
|
|
63179
|
-
|
|
63180
|
-
orders,
|
|
63181
|
-
kind,
|
|
63182
|
-
decimal_places = "%.3f",
|
|
63183
|
-
price_places = "%.1f",
|
|
63184
|
-
symbol,
|
|
63185
|
-
place = false
|
|
63186
|
-
} = payload;
|
|
63187
|
-
const totalQuantity = orders.reduce((sum, order) => sum + (order.quantity || 0), 0);
|
|
63188
|
-
let runningTotal = to_f2(totalQuantity, decimal_places);
|
|
63189
|
-
let sortedOrders = [...orders].sort((a, b) => (a.entry || 0) - (b.entry || 0));
|
|
63190
|
-
if (kind === "short") {
|
|
63191
|
-
sortedOrders.reverse();
|
|
63192
|
-
}
|
|
63193
|
-
const withCumulative = [];
|
|
63194
|
-
for (const order of sortedOrders) {
|
|
63195
|
-
withCumulative.push({
|
|
63196
|
-
...order,
|
|
63197
|
-
cumulative_quantity: runningTotal
|
|
63198
|
-
});
|
|
63199
|
-
runningTotal -= order.quantity;
|
|
63200
|
-
runningTotal = to_f2(runningTotal, decimal_places);
|
|
63201
|
-
}
|
|
63202
|
-
const positions = await getPositionInfo2(this.client, symbol);
|
|
63203
|
-
const position2 = positions[kind] || {
|
|
63204
|
-
kind,
|
|
63205
|
-
size: 0,
|
|
63206
|
-
entryPrice: 0,
|
|
63207
|
-
symbol
|
|
63208
|
-
};
|
|
63209
|
-
const filteredOrders = withCumulative.filter((order) => (order.cumulative_quantity || 0) > position2.size).map((order) => ({
|
|
63210
|
-
...order,
|
|
63211
|
-
price: order.entry,
|
|
63212
|
-
kind,
|
|
63213
|
-
side: kind.toLowerCase() === "long" ? "buy" : "sell"
|
|
63214
|
-
}));
|
|
63215
|
-
if (filteredOrders.length > 0 && place) {
|
|
63216
|
-
await cancelAllOrders2(this.client, symbol, {
|
|
63217
|
-
type: "limit",
|
|
63218
|
-
kind
|
|
63219
|
-
});
|
|
63220
|
-
await createLimitPurchaseOrders2(this.client, symbol, price_places, decimal_places, filteredOrders);
|
|
63221
|
-
}
|
|
63222
|
-
return filteredOrders;
|
|
63249
|
+
async cancelAllOrders(symbol, payload) {
|
|
63250
|
+
return await cancelAllOrders2(this.client, symbol, payload);
|
|
63223
63251
|
}
|
|
63224
|
-
async
|
|
63252
|
+
async _createLimitPurchaseOrders(payload) {
|
|
63253
|
+
return await createLimitPurchaseOrders2(this.client, payload.symbol, payload.price_places, payload.decimal_places, payload.orders);
|
|
63254
|
+
}
|
|
63255
|
+
async getCurrentPrice(symbol) {
|
|
63225
63256
|
return await getCurrentPrice2(this.client, symbol);
|
|
63226
63257
|
}
|
|
63227
63258
|
async analyzeCharts(payload) {
|
|
@@ -63233,60 +63264,30 @@ class BybitExchange extends BaseExchange {
|
|
|
63233
63264
|
raw: payload.raw || false
|
|
63234
63265
|
});
|
|
63235
63266
|
}
|
|
63236
|
-
async
|
|
63237
|
-
const {
|
|
63238
|
-
price_places = "%.1f",
|
|
63239
|
-
decimal_places = "%.3f",
|
|
63240
|
-
account,
|
|
63241
|
-
symbol
|
|
63242
|
-
} = options;
|
|
63267
|
+
async getExchangeInfo(options) {
|
|
63243
63268
|
return await fetchBybitAccount(this.client, {
|
|
63244
|
-
owner: account.owner,
|
|
63245
|
-
symbol
|
|
63269
|
+
owner: options.account.owner,
|
|
63270
|
+
symbol: options.symbol
|
|
63246
63271
|
}, {
|
|
63247
|
-
price_places,
|
|
63248
|
-
decimal_places
|
|
63272
|
+
price_places: options.price_places,
|
|
63273
|
+
decimal_places: options.decimal_places
|
|
63249
63274
|
});
|
|
63250
63275
|
}
|
|
63251
|
-
async
|
|
63276
|
+
async _cancelOrders(payload) {
|
|
63252
63277
|
return await cancelOrders2({
|
|
63253
63278
|
symbol: payload.symbol,
|
|
63254
|
-
orders: payload.orders
|
|
63279
|
+
orders: payload.orders,
|
|
63255
63280
|
custom_client: this.client
|
|
63256
63281
|
});
|
|
63257
63282
|
}
|
|
63258
|
-
async
|
|
63259
|
-
return await placeTpOrder2(this.client,
|
|
63260
|
-
symbol: payload.symbol,
|
|
63261
|
-
tp: payload.take_profit,
|
|
63262
|
-
kind: payload.kind,
|
|
63263
|
-
cancel: true
|
|
63264
|
-
});
|
|
63283
|
+
async _placeTpOrder(payload) {
|
|
63284
|
+
return await placeTpOrder2(this.client, payload);
|
|
63265
63285
|
}
|
|
63266
|
-
async
|
|
63267
|
-
return await placeLimitOrders2(this.client,
|
|
63268
|
-
symbol: payload.symbol,
|
|
63269
|
-
orders: [
|
|
63270
|
-
{
|
|
63271
|
-
entry: payload.price,
|
|
63272
|
-
quantity: payload.quantity
|
|
63273
|
-
}
|
|
63274
|
-
],
|
|
63275
|
-
kind: payload.kind
|
|
63276
|
-
});
|
|
63286
|
+
async placeLimitOrders(payload) {
|
|
63287
|
+
return await placeLimitOrders2(this.client, payload);
|
|
63277
63288
|
}
|
|
63278
|
-
async
|
|
63279
|
-
return await placeStopOrder2(this.client,
|
|
63280
|
-
symbol: payload.symbol,
|
|
63281
|
-
stop: payload.stop,
|
|
63282
|
-
final_stop: payload.stop,
|
|
63283
|
-
quantity: Math.abs(payload.quantity),
|
|
63284
|
-
kind: payload.kind,
|
|
63285
|
-
cancel: true,
|
|
63286
|
-
is_limit: true,
|
|
63287
|
-
price_places: payload.price_places,
|
|
63288
|
-
decimal_places: payload.decimal_places
|
|
63289
|
-
});
|
|
63289
|
+
async _placeStopOrder(payload) {
|
|
63290
|
+
return await placeStopOrder2(this.client, payload);
|
|
63290
63291
|
}
|
|
63291
63292
|
async setLeverage(payload) {
|
|
63292
63293
|
return await this.client.setLeverage({
|
|
@@ -63300,40 +63301,18 @@ class BybitExchange extends BaseExchange {
|
|
|
63300
63301
|
}
|
|
63301
63302
|
async checkDelistedMovers(payload) {
|
|
63302
63303
|
}
|
|
63303
|
-
async
|
|
63304
|
-
|
|
63305
|
-
|
|
63306
|
-
return [];
|
|
63304
|
+
async getAllOpenOrders() {
|
|
63305
|
+
const result = await getAllOpenOrders2({ client: this.client });
|
|
63306
|
+
return result;
|
|
63307
63307
|
}
|
|
63308
63308
|
async getOpenPositions() {
|
|
63309
63309
|
return [];
|
|
63310
63310
|
}
|
|
63311
|
-
async createLimitPurchaseOrders(payload) {
|
|
63312
|
-
const {
|
|
63313
|
-
orders,
|
|
63314
|
-
kind,
|
|
63315
|
-
decimal_places = "%.3f",
|
|
63316
|
-
price_places = "%.1f",
|
|
63317
|
-
symbol
|
|
63318
|
-
} = payload;
|
|
63319
|
-
return await createLimitPurchaseOrders2(this.client, symbol, price_places, decimal_places, orders.map((order) => ({
|
|
63320
|
-
...order,
|
|
63321
|
-
price: order.entry,
|
|
63322
|
-
kind,
|
|
63323
|
-
side: kind.toLowerCase() === "long" ? "buy" : "sell"
|
|
63324
|
-
})));
|
|
63325
|
-
}
|
|
63326
63311
|
async getDelistedSpotSymbols() {
|
|
63327
63312
|
return [];
|
|
63328
63313
|
}
|
|
63329
63314
|
async crossAccountTransfer(payload) {
|
|
63330
63315
|
}
|
|
63331
|
-
async placeMarketOrder(payload) {
|
|
63332
|
-
}
|
|
63333
|
-
async rawCreateLimitPurchaseOrders(payload) {
|
|
63334
|
-
const { symbol, orders, price_places, decimal_places } = payload;
|
|
63335
|
-
return createLimitPurchaseOrders2(this.client, symbol, price_places, decimal_places, orders);
|
|
63336
|
-
}
|
|
63337
63316
|
getOpenOrders(payload) {
|
|
63338
63317
|
return getOpenOrders2(this.client, payload.symbol);
|
|
63339
63318
|
}
|
|
@@ -64769,6 +64748,9 @@ class ExchangeAccount {
|
|
|
64769
64748
|
long_config,
|
|
64770
64749
|
short_config
|
|
64771
64750
|
});
|
|
64751
|
+
if (!long_config || !short_config) {
|
|
64752
|
+
return null;
|
|
64753
|
+
}
|
|
64772
64754
|
let long_target_pnl = payload.kind == "long" ? payload.target_pnl : 0;
|
|
64773
64755
|
let short_target_pnl = payload.kind == "short" ? payload.target_pnl : 0;
|
|
64774
64756
|
const long_sell_ratio = long_config.sell_ratio || long_position?.sell_ratio;
|
|
@@ -64893,7 +64875,7 @@ class ExchangeAccount {
|
|
|
64893
64875
|
});
|
|
64894
64876
|
const long_pause_tp = long_config?.pause_tp;
|
|
64895
64877
|
const short_pause_tp = short_config?.pause_tp;
|
|
64896
|
-
if (payload.trigger && !long_pause_tp && !short_pause_tp) {
|
|
64878
|
+
if (payload.trigger && !long_pause_tp && !short_pause_tp && config2) {
|
|
64897
64879
|
return await this.reduceMajorPositionEntry({
|
|
64898
64880
|
symbol,
|
|
64899
64881
|
long: config2.long,
|
|
@@ -65457,15 +65439,15 @@ class ExchangeAccount {
|
|
|
65457
65439
|
}
|
|
65458
65440
|
async buildOppositeTrades(payload) {
|
|
65459
65441
|
const { symbol, kind, place, place_symbol } = payload;
|
|
65460
|
-
const
|
|
65442
|
+
const strategy2 = await this.runSimulation({
|
|
65461
65443
|
symbol,
|
|
65462
65444
|
kind,
|
|
65463
65445
|
raw: true
|
|
65464
65446
|
});
|
|
65465
65447
|
try {
|
|
65466
|
-
const result =
|
|
65448
|
+
const result = strategy2.generateOppositeTrades({
|
|
65467
65449
|
kind,
|
|
65468
|
-
avg_entry:
|
|
65450
|
+
avg_entry: strategy2.position[kind].avg_price
|
|
65469
65451
|
});
|
|
65470
65452
|
if (place && result?.kind) {
|
|
65471
65453
|
const _symbol = place_symbol || symbol;
|
|
@@ -65516,7 +65498,7 @@ class ExchangeAccount {
|
|
|
65516
65498
|
reduce_ratio,
|
|
65517
65499
|
global_config: symbol_config
|
|
65518
65500
|
};
|
|
65519
|
-
const
|
|
65501
|
+
const strategy2 = new Strategy({
|
|
65520
65502
|
long: {
|
|
65521
65503
|
entry: long_position.entry,
|
|
65522
65504
|
quantity: long_position.quantity,
|
|
@@ -65532,9 +65514,9 @@ class ExchangeAccount {
|
|
|
65532
65514
|
config: strategy_config
|
|
65533
65515
|
});
|
|
65534
65516
|
if (raw) {
|
|
65535
|
-
return
|
|
65517
|
+
return strategy2;
|
|
65536
65518
|
}
|
|
65537
|
-
return
|
|
65519
|
+
return strategy2.runIterations({
|
|
65538
65520
|
iterations,
|
|
65539
65521
|
kind
|
|
65540
65522
|
});
|
|
@@ -66223,31 +66205,31 @@ class ExchangeAccount {
|
|
|
66223
66205
|
if (!focus_position) {
|
|
66224
66206
|
return;
|
|
66225
66207
|
}
|
|
66226
|
-
const
|
|
66227
|
-
if (!
|
|
66208
|
+
const strategy2 = focus_position?.expand?.account_strategy;
|
|
66209
|
+
if (!strategy2) {
|
|
66228
66210
|
return;
|
|
66229
66211
|
}
|
|
66230
|
-
const risk =
|
|
66231
|
-
const kind =
|
|
66232
|
-
const support =
|
|
66233
|
-
const resistance =
|
|
66212
|
+
const risk = strategy2.risk;
|
|
66213
|
+
const kind = strategy2.kind;
|
|
66214
|
+
const support = strategy2.support;
|
|
66215
|
+
const resistance = strategy2.resistance;
|
|
66234
66216
|
console.log("Getting long and short positions for ", symbol);
|
|
66235
66217
|
const long_position = positions.find((k) => k.kind === "long");
|
|
66236
66218
|
const short_position = positions.find((k) => k.kind === "short");
|
|
66237
66219
|
console.log("Getting focus position for ", symbol, kind);
|
|
66238
66220
|
const reverse_position = kind === "long" ? short_position : long_position;
|
|
66239
|
-
if (
|
|
66240
|
-
reward_factor =
|
|
66221
|
+
if (strategy2.max_reward_factor === 0) {
|
|
66222
|
+
reward_factor = strategy2.reward_factor;
|
|
66241
66223
|
}
|
|
66242
|
-
if (focus_position.avg_qty >= focus_position.quantity &&
|
|
66243
|
-
if (
|
|
66224
|
+
if (focus_position.avg_qty >= focus_position.quantity && strategy2.max_reward_factor) {
|
|
66225
|
+
if (strategy2.dynamic) {
|
|
66244
66226
|
const quantity_ratio = focus_position.quantity / focus_position.avg_qty;
|
|
66245
|
-
reward_factor = to_f2(quantity_ratio ** 2 *
|
|
66227
|
+
reward_factor = to_f2(quantity_ratio ** 2 * strategy2.max_reward_factor, "%.2f");
|
|
66246
66228
|
} else {
|
|
66247
|
-
reward_factor = to_f2(focus_position.quantity *
|
|
66229
|
+
reward_factor = to_f2(focus_position.quantity * strategy2.max_reward_factor / focus_position.avg_qty, "%.4f");
|
|
66248
66230
|
}
|
|
66249
66231
|
} else {
|
|
66250
|
-
reward_factor =
|
|
66232
|
+
reward_factor = strategy2.reward_factor;
|
|
66251
66233
|
}
|
|
66252
66234
|
console.log("Getting entry and stop for ", symbol, kind);
|
|
66253
66235
|
const entry = kind === "long" ? resistance : support;
|
|
@@ -66261,7 +66243,7 @@ class ExchangeAccount {
|
|
|
66261
66243
|
symbol
|
|
66262
66244
|
});
|
|
66263
66245
|
console.log("Computing risk reward for ", symbol, kind);
|
|
66264
|
-
const risk_reward =
|
|
66246
|
+
const risk_reward = strategy2.risk_reward || computeRiskReward({
|
|
66265
66247
|
app_config: initial_app_config,
|
|
66266
66248
|
entry: initial_app_config.entry,
|
|
66267
66249
|
stop: initial_app_config.stop,
|
|
@@ -66394,7 +66376,7 @@ class ExchangeAccount {
|
|
|
66394
66376
|
const max_size = app_config.max_size * 0.98;
|
|
66395
66377
|
if (reverse_config.threshold_qty !== max_size) {
|
|
66396
66378
|
await this.app_db.updateScheduledTrade(reverse_config.id, {
|
|
66397
|
-
follow:
|
|
66379
|
+
follow: strategy2.follow,
|
|
66398
66380
|
threshold_qty: max_size
|
|
66399
66381
|
});
|
|
66400
66382
|
}
|
|
@@ -66468,8 +66450,8 @@ class ExchangeAccount {
|
|
|
66468
66450
|
}
|
|
66469
66451
|
const reverse_kind = focus_position.kind === "long" ? "short" : "long";
|
|
66470
66452
|
const reverse_position = positions.find((k) => k.kind === reverse_kind);
|
|
66471
|
-
const
|
|
66472
|
-
if (!
|
|
66453
|
+
const strategy2 = focus_position?.expand?.account_strategy;
|
|
66454
|
+
if (!strategy2) {
|
|
66473
66455
|
return;
|
|
66474
66456
|
}
|
|
66475
66457
|
return computeProfitDetail({
|
|
@@ -66482,9 +66464,9 @@ class ExchangeAccount {
|
|
|
66482
66464
|
},
|
|
66483
66465
|
pnl: focus_position.target_pnl,
|
|
66484
66466
|
strategy: {
|
|
66485
|
-
reward_factor:
|
|
66486
|
-
risk:
|
|
66487
|
-
max_reward_factor:
|
|
66467
|
+
reward_factor: strategy2.reward_factor,
|
|
66468
|
+
risk: strategy2.risk,
|
|
66469
|
+
max_reward_factor: strategy2.max_reward_factor
|
|
66488
66470
|
},
|
|
66489
66471
|
reduce_position: {
|
|
66490
66472
|
kind: reduce_position.kind,
|
|
@@ -66508,7 +66490,10 @@ function getExchangeKlass(exchange) {
|
|
|
66508
66490
|
const func = exchange === "binance" ? BinanceExchange : BybitExchange;
|
|
66509
66491
|
const clientFunc = exchange === "binance" ? initClient : initClient2;
|
|
66510
66492
|
return async (payload) => {
|
|
66511
|
-
const credentials = payload.getCredentials(
|
|
66493
|
+
const credentials = await payload.getCredentials({
|
|
66494
|
+
account: payload.account,
|
|
66495
|
+
exchange
|
|
66496
|
+
});
|
|
66512
66497
|
const client = await clientFunc(credentials, {
|
|
66513
66498
|
type: "future",
|
|
66514
66499
|
proxyAgent: payload.proxyAgent
|
|
@@ -66539,7 +66524,9 @@ async function getExchangeAccount(payload) {
|
|
|
66539
66524
|
const proxyAgent = proxyOptions?.ignore_proxy ? null : proxyOptions?.proxy || _proxyAgent;
|
|
66540
66525
|
const exchange_instance = await getExchangeKlass(account.exchange)({
|
|
66541
66526
|
account: account.owner,
|
|
66542
|
-
getCredentials:
|
|
66527
|
+
getCredentials: async (_payload) => {
|
|
66528
|
+
return await payload.getCredentials({ ..._payload, app_db });
|
|
66529
|
+
},
|
|
66543
66530
|
proxyAgent,
|
|
66544
66531
|
canWithdraw
|
|
66545
66532
|
});
|
|
@@ -66563,7 +66550,7 @@ class App {
|
|
|
66563
66550
|
return await getExchangeAccount({
|
|
66564
66551
|
account,
|
|
66565
66552
|
app_db: this.app_db,
|
|
66566
|
-
getCredentials: this.getCredentials,
|
|
66553
|
+
getCredentials: (p) => this.getCredentials({ ...p, app_db: this.app_db }),
|
|
66567
66554
|
proxyOptions: this.proxyOptions,
|
|
66568
66555
|
canWithdraw: this.proxyOptions?.canWithdraw
|
|
66569
66556
|
});
|
|
@@ -66725,6 +66712,9 @@ class App {
|
|
|
66725
66712
|
owner: exchange.owner,
|
|
66726
66713
|
exchange: exchange.exchange
|
|
66727
66714
|
});
|
|
66715
|
+
if (exchange.exchange === "bybit" && symbol === "BTCUSDC") {
|
|
66716
|
+
continue;
|
|
66717
|
+
}
|
|
66728
66718
|
await exchange_account.placeProfitAndStop({
|
|
66729
66719
|
symbol,
|
|
66730
66720
|
trigger: true,
|
|
@@ -66819,11 +66809,11 @@ class App {
|
|
|
66819
66809
|
}
|
|
66820
66810
|
async runDbStrategyAccounts(callback) {
|
|
66821
66811
|
const strategies = await this.app_db.getRunningAccountStrategies();
|
|
66822
|
-
for (const
|
|
66823
|
-
console.log("Running strategy for ",
|
|
66812
|
+
for (const strategy2 of strategies) {
|
|
66813
|
+
console.log("Running strategy for ", strategy2.symbol, "for account", strategy2.expand.account.owner, strategy2.expand.account.exchange);
|
|
66824
66814
|
await callback({
|
|
66825
|
-
symbol:
|
|
66826
|
-
account:
|
|
66815
|
+
symbol: strategy2.symbol,
|
|
66816
|
+
account: strategy2.expand.account
|
|
66827
66817
|
});
|
|
66828
66818
|
}
|
|
66829
66819
|
}
|
|
@@ -66881,7 +66871,8 @@ async function initApp(payload) {
|
|
|
66881
66871
|
password: payload.password
|
|
66882
66872
|
});
|
|
66883
66873
|
if (credentials) {
|
|
66884
|
-
_getCredentials = (
|
|
66874
|
+
_getCredentials = async (payload2) => {
|
|
66875
|
+
const { account, exchange } = payload2;
|
|
66885
66876
|
const credential = credentials.find((c) => c.name === account && c.exchange === exchange);
|
|
66886
66877
|
if (!credential) {
|
|
66887
66878
|
throw new Error(`Missing API Key or Secret for account '${account}' in .env file. Please check your environment variables.`);
|
|
@@ -66919,11 +66910,19 @@ async function getApp() {
|
|
|
66919
66910
|
password: process.env.POCKETBASE_PASSWORD
|
|
66920
66911
|
},
|
|
66921
66912
|
password: process.env.POCKETBASE_PASSWORD,
|
|
66922
|
-
getCredentials: (
|
|
66913
|
+
getCredentials: async (payload) => {
|
|
66914
|
+
const { account, exchange, app_db } = payload;
|
|
66915
|
+
const credentials = await app_db.getCredentials({
|
|
66916
|
+
password: process.env.POCKETBASE_PASSWORD
|
|
66917
|
+
});
|
|
66918
|
+
const credential = credentials.find((c) => c.name === account && c.exchange === exchange);
|
|
66919
|
+
if (!credential) {
|
|
66920
|
+
throw new Error(`Missing API Key or Secret for account '${account}' in .env file. Please check your environment variables.`);
|
|
66921
|
+
}
|
|
66923
66922
|
return {
|
|
66924
|
-
api_key:
|
|
66925
|
-
api_secret:
|
|
66926
|
-
email:
|
|
66923
|
+
api_key: credential.api_key,
|
|
66924
|
+
api_secret: credential.api_secret,
|
|
66925
|
+
email: credential.email
|
|
66927
66926
|
};
|
|
66928
66927
|
}
|
|
66929
66928
|
});
|