@gbozee/ultimate 0.0.2-78 → 0.0.2-79
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.js +1 -12
- package/dist/index.cjs +18 -15
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -15
- package/dist/mcp-server.cjs +18 -15
- package/dist/mcp-server.js +18 -15
- package/package.json +1 -1
package/dist/frontend-index.js
CHANGED
|
@@ -1203,9 +1203,7 @@ function buildConfig(app_config, {
|
|
|
1203
1203
|
}
|
|
1204
1204
|
const condition = (kind === "long" ? entry > app_config.support : entry >= app_config.support) && stop >= app_config.support * 0.999;
|
|
1205
1205
|
if (kind === "short") {
|
|
1206
|
-
console.log("condition", condition, entry === stop);
|
|
1207
1206
|
}
|
|
1208
|
-
console.log({ entry, support: app_config.support, stop });
|
|
1209
1207
|
const result = entry === stop ? [] : condition ? instance.build_entry({
|
|
1210
1208
|
current_price: entry,
|
|
1211
1209
|
stop_loss: stop,
|
|
@@ -1534,7 +1532,6 @@ function generateOptimumAppConfig(config, payload, position2) {
|
|
|
1534
1532
|
const tolerance = 0.1;
|
|
1535
1533
|
const max_iterations = 150;
|
|
1536
1534
|
let iterations = 0;
|
|
1537
|
-
console.log(`Starting risk search for ${position2.kind} position. Target Entry: ${position2.entry}, Initial Risk Range: [${low_risk}, ${high_risk}]`);
|
|
1538
1535
|
while (high_risk - low_risk > tolerance && iterations < max_iterations) {
|
|
1539
1536
|
iterations++;
|
|
1540
1537
|
const mid_risk = (low_risk + high_risk) / 2;
|
|
@@ -1580,9 +1577,7 @@ function generateOptimumAppConfig(config, payload, position2) {
|
|
|
1580
1577
|
price_places: current_app_config.price_places,
|
|
1581
1578
|
decimal_places: current_app_config.decimal_places
|
|
1582
1579
|
});
|
|
1583
|
-
console.log(`Iteration ${iterations}: Risk=${mid_risk.toFixed(2)}, Low=${low_risk.toFixed(2)}, High=${high_risk.toFixed(2)}`);
|
|
1584
1580
|
if (full_trades.length === 0) {
|
|
1585
|
-
console.log(` -> No trades generated by sortedBuildConfig at Risk=${mid_risk.toFixed(2)}. Adjusting high_risk down.`);
|
|
1586
1581
|
high_risk = mid_risk;
|
|
1587
1582
|
continue;
|
|
1588
1583
|
}
|
|
@@ -1595,29 +1590,23 @@ function generateOptimumAppConfig(config, payload, position2) {
|
|
|
1595
1590
|
existingOrders: []
|
|
1596
1591
|
});
|
|
1597
1592
|
if (trades.length === 0) {
|
|
1598
|
-
console.log(` -> No trades met quantity requirement after filtering at Risk=${mid_risk.toFixed(2)}. Adjusting low_risk up.`);
|
|
1599
1593
|
low_risk = mid_risk;
|
|
1600
1594
|
continue;
|
|
1601
1595
|
}
|
|
1602
1596
|
const last_trade = trades[trades.length - 1];
|
|
1603
1597
|
const last_entry = last_trade.entry;
|
|
1604
|
-
console.log(` -> Last Trade Entry (Filtered): ${last_entry.toFixed(4)}`);
|
|
1605
1598
|
if (position2.kind === "long") {
|
|
1606
1599
|
if (last_entry > position2.entry) {
|
|
1607
|
-
console.log(` -> Constraint VIOLATED (Long): last_entry (${last_entry.toFixed(4)}) > position.entry (${position2.entry.toFixed(4)}). Reducing high_risk.`);
|
|
1608
1600
|
high_risk = mid_risk;
|
|
1609
1601
|
} else {
|
|
1610
|
-
console.log(` -> Constraint MET (Long): last_entry (${last_entry.toFixed(4)}) <= position.entry (${position2.entry.toFixed(4)}). Storing as best, increasing low_risk.`);
|
|
1611
1602
|
best_risk = mid_risk;
|
|
1612
1603
|
best_app_config = current_app_config;
|
|
1613
1604
|
low_risk = mid_risk;
|
|
1614
1605
|
}
|
|
1615
1606
|
} else {
|
|
1616
1607
|
if (last_entry < position2.entry) {
|
|
1617
|
-
console.log(` -> Constraint VIOLATED (Short): last_entry (${last_entry.toFixed(4)}) < position.entry (${position2.entry.toFixed(4)}). Reducing high_risk.`);
|
|
1618
1608
|
high_risk = mid_risk;
|
|
1619
1609
|
} else {
|
|
1620
|
-
console.log(` -> Constraint MET (Short): last_entry (${last_entry.toFixed(4)}) >= position.entry (${position2.entry.toFixed(4)}). Storing as best, increasing low_risk.`);
|
|
1621
1610
|
best_risk = mid_risk;
|
|
1622
1611
|
best_app_config = current_app_config;
|
|
1623
1612
|
low_risk = mid_risk;
|
|
@@ -1854,7 +1843,6 @@ class Strategy {
|
|
|
1854
1843
|
quantity,
|
|
1855
1844
|
kind
|
|
1856
1845
|
};
|
|
1857
|
-
console.log({ second_payload, third_payload });
|
|
1858
1846
|
const app_config = generateOptimumAppConfig(this.config.global_config, second_payload, third_payload);
|
|
1859
1847
|
let entries = [];
|
|
1860
1848
|
let risk_per_trade = this.config.budget;
|
|
@@ -1867,6 +1855,7 @@ class Strategy {
|
|
|
1867
1855
|
if (ignore_entries) {
|
|
1868
1856
|
entries = [];
|
|
1869
1857
|
}
|
|
1858
|
+
console.log({ app_config });
|
|
1870
1859
|
}
|
|
1871
1860
|
const risk = this.to_f(risk_per_trade);
|
|
1872
1861
|
let below_reverse_entries = kind === "long" ? entries.filter((u) => {
|
package/dist/index.cjs
CHANGED
|
@@ -51509,6 +51509,18 @@ class AppDatabase {
|
|
|
51509
51509
|
await this.saveCredentials(password, credentials);
|
|
51510
51510
|
}
|
|
51511
51511
|
}
|
|
51512
|
+
async getAccountWithActivePositions() {
|
|
51513
|
+
const positions = await this.pb.collection("positions").getFullList({
|
|
51514
|
+
filter: `quantity > 0`,
|
|
51515
|
+
fields: `account`
|
|
51516
|
+
});
|
|
51517
|
+
const accounts = Array.from(new Set(positions.map((p) => p.account)));
|
|
51518
|
+
const filter = accounts.map((a) => `id = "${a}"`).join(" || ");
|
|
51519
|
+
const account_instances = await this.pb.collection("exchange_accounts").getFullList({
|
|
51520
|
+
filter
|
|
51521
|
+
});
|
|
51522
|
+
return account_instances;
|
|
51523
|
+
}
|
|
51512
51524
|
async getAllSymbolsFromPositions(options) {
|
|
51513
51525
|
const { no_position = false, kind = "long", custom_filter } = options || {};
|
|
51514
51526
|
let filter = custom_filter || (no_position ? `quantity = 0` : undefined);
|
|
@@ -53262,9 +53274,7 @@ function buildConfig(app_config, {
|
|
|
53262
53274
|
}
|
|
53263
53275
|
const condition = (kind === "long" ? entry > app_config.support : entry >= app_config.support) && stop >= app_config.support * 0.999;
|
|
53264
53276
|
if (kind === "short") {
|
|
53265
|
-
console.log("condition", condition, entry === stop);
|
|
53266
53277
|
}
|
|
53267
|
-
console.log({ entry, support: app_config.support, stop });
|
|
53268
53278
|
const result = entry === stop ? [] : condition ? instance.build_entry({
|
|
53269
53279
|
current_price: entry,
|
|
53270
53280
|
stop_loss: stop,
|
|
@@ -53593,7 +53603,6 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
53593
53603
|
const tolerance = 0.1;
|
|
53594
53604
|
const max_iterations = 150;
|
|
53595
53605
|
let iterations = 0;
|
|
53596
|
-
console.log(`Starting risk search for ${position2.kind} position. Target Entry: ${position2.entry}, Initial Risk Range: [${low_risk}, ${high_risk}]`);
|
|
53597
53606
|
while (high_risk - low_risk > tolerance && iterations < max_iterations) {
|
|
53598
53607
|
iterations++;
|
|
53599
53608
|
const mid_risk = (low_risk + high_risk) / 2;
|
|
@@ -53639,9 +53648,7 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
53639
53648
|
price_places: current_app_config.price_places,
|
|
53640
53649
|
decimal_places: current_app_config.decimal_places
|
|
53641
53650
|
});
|
|
53642
|
-
console.log(`Iteration ${iterations}: Risk=${mid_risk.toFixed(2)}, Low=${low_risk.toFixed(2)}, High=${high_risk.toFixed(2)}`);
|
|
53643
53651
|
if (full_trades.length === 0) {
|
|
53644
|
-
console.log(` -> No trades generated by sortedBuildConfig at Risk=${mid_risk.toFixed(2)}. Adjusting high_risk down.`);
|
|
53645
53652
|
high_risk = mid_risk;
|
|
53646
53653
|
continue;
|
|
53647
53654
|
}
|
|
@@ -53654,29 +53661,23 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
53654
53661
|
existingOrders: []
|
|
53655
53662
|
});
|
|
53656
53663
|
if (trades.length === 0) {
|
|
53657
|
-
console.log(` -> No trades met quantity requirement after filtering at Risk=${mid_risk.toFixed(2)}. Adjusting low_risk up.`);
|
|
53658
53664
|
low_risk = mid_risk;
|
|
53659
53665
|
continue;
|
|
53660
53666
|
}
|
|
53661
53667
|
const last_trade = trades[trades.length - 1];
|
|
53662
53668
|
const last_entry = last_trade.entry;
|
|
53663
|
-
console.log(` -> Last Trade Entry (Filtered): ${last_entry.toFixed(4)}`);
|
|
53664
53669
|
if (position2.kind === "long") {
|
|
53665
53670
|
if (last_entry > position2.entry) {
|
|
53666
|
-
console.log(` -> Constraint VIOLATED (Long): last_entry (${last_entry.toFixed(4)}) > position.entry (${position2.entry.toFixed(4)}). Reducing high_risk.`);
|
|
53667
53671
|
high_risk = mid_risk;
|
|
53668
53672
|
} else {
|
|
53669
|
-
console.log(` -> Constraint MET (Long): last_entry (${last_entry.toFixed(4)}) <= position.entry (${position2.entry.toFixed(4)}). Storing as best, increasing low_risk.`);
|
|
53670
53673
|
best_risk = mid_risk;
|
|
53671
53674
|
best_app_config = current_app_config;
|
|
53672
53675
|
low_risk = mid_risk;
|
|
53673
53676
|
}
|
|
53674
53677
|
} else {
|
|
53675
53678
|
if (last_entry < position2.entry) {
|
|
53676
|
-
console.log(` -> Constraint VIOLATED (Short): last_entry (${last_entry.toFixed(4)}) < position.entry (${position2.entry.toFixed(4)}). Reducing high_risk.`);
|
|
53677
53679
|
high_risk = mid_risk;
|
|
53678
53680
|
} else {
|
|
53679
|
-
console.log(` -> Constraint MET (Short): last_entry (${last_entry.toFixed(4)}) >= position.entry (${position2.entry.toFixed(4)}). Storing as best, increasing low_risk.`);
|
|
53680
53681
|
best_risk = mid_risk;
|
|
53681
53682
|
best_app_config = current_app_config;
|
|
53682
53683
|
low_risk = mid_risk;
|
|
@@ -53914,7 +53915,6 @@ class Strategy {
|
|
|
53914
53915
|
quantity,
|
|
53915
53916
|
kind
|
|
53916
53917
|
};
|
|
53917
|
-
console.log({ second_payload, third_payload });
|
|
53918
53918
|
const app_config = generateOptimumAppConfig(this.config.global_config, second_payload, third_payload);
|
|
53919
53919
|
let entries = [];
|
|
53920
53920
|
let risk_per_trade = this.config.budget;
|
|
@@ -53927,6 +53927,7 @@ class Strategy {
|
|
|
53927
53927
|
if (ignore_entries) {
|
|
53928
53928
|
entries = [];
|
|
53929
53929
|
}
|
|
53930
|
+
console.log({ app_config });
|
|
53930
53931
|
}
|
|
53931
53932
|
const risk = this.to_f(risk_per_trade);
|
|
53932
53933
|
let below_reverse_entries = kind === "long" ? entries.filter((u) => {
|
|
@@ -58660,6 +58661,7 @@ class ExchangeAccount {
|
|
|
58660
58661
|
kind,
|
|
58661
58662
|
place,
|
|
58662
58663
|
tp,
|
|
58664
|
+
limit = true,
|
|
58663
58665
|
raw: _raw,
|
|
58664
58666
|
cancel,
|
|
58665
58667
|
stop,
|
|
@@ -58672,13 +58674,14 @@ class ExchangeAccount {
|
|
|
58672
58674
|
kind
|
|
58673
58675
|
});
|
|
58674
58676
|
}
|
|
58675
|
-
if (
|
|
58677
|
+
if (limit) {
|
|
58676
58678
|
return await this.triggerTradeFromConfig({
|
|
58677
58679
|
symbol,
|
|
58678
58680
|
kind,
|
|
58679
58681
|
raw: payload.raw,
|
|
58680
58682
|
stop,
|
|
58681
|
-
ignore_config
|
|
58683
|
+
ignore_config,
|
|
58684
|
+
place
|
|
58682
58685
|
});
|
|
58683
58686
|
}
|
|
58684
58687
|
await this.syncAccount({
|
|
@@ -59005,7 +59008,7 @@ class App {
|
|
|
59005
59008
|
return await this.app_db.getMoverExchangeInstances();
|
|
59006
59009
|
}
|
|
59007
59010
|
async updateTpOnAllMarkets() {
|
|
59008
|
-
const move_instances = await this.
|
|
59011
|
+
const move_instances = await this.app_db.getAccountWithActivePositions();
|
|
59009
59012
|
for (const instance of move_instances) {
|
|
59010
59013
|
const params = {
|
|
59011
59014
|
account: {
|
package/dist/index.d.ts
CHANGED
|
@@ -340,6 +340,7 @@ export declare class AppDatabase {
|
|
|
340
340
|
api_key: string;
|
|
341
341
|
api_secret: string;
|
|
342
342
|
}): Promise<void>;
|
|
343
|
+
getAccountWithActivePositions(): Promise<import("pocketbase").RecordModel[]>;
|
|
343
344
|
getAllSymbolsFromPositions(options?: {
|
|
344
345
|
no_position?: boolean;
|
|
345
346
|
kind?: "long" | "short";
|
|
@@ -1651,6 +1652,7 @@ declare class ExchangeAccount$1 {
|
|
|
1651
1652
|
symbol: string;
|
|
1652
1653
|
kind: "long" | "short";
|
|
1653
1654
|
place?: boolean;
|
|
1655
|
+
limit?: boolean;
|
|
1654
1656
|
tp?: boolean;
|
|
1655
1657
|
stop?: boolean;
|
|
1656
1658
|
raw?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -51464,6 +51464,18 @@ class AppDatabase {
|
|
|
51464
51464
|
await this.saveCredentials(password, credentials);
|
|
51465
51465
|
}
|
|
51466
51466
|
}
|
|
51467
|
+
async getAccountWithActivePositions() {
|
|
51468
|
+
const positions = await this.pb.collection("positions").getFullList({
|
|
51469
|
+
filter: `quantity > 0`,
|
|
51470
|
+
fields: `account`
|
|
51471
|
+
});
|
|
51472
|
+
const accounts = Array.from(new Set(positions.map((p) => p.account)));
|
|
51473
|
+
const filter = accounts.map((a) => `id = "${a}"`).join(" || ");
|
|
51474
|
+
const account_instances = await this.pb.collection("exchange_accounts").getFullList({
|
|
51475
|
+
filter
|
|
51476
|
+
});
|
|
51477
|
+
return account_instances;
|
|
51478
|
+
}
|
|
51467
51479
|
async getAllSymbolsFromPositions(options) {
|
|
51468
51480
|
const { no_position = false, kind = "long", custom_filter } = options || {};
|
|
51469
51481
|
let filter = custom_filter || (no_position ? `quantity = 0` : undefined);
|
|
@@ -53217,9 +53229,7 @@ function buildConfig(app_config, {
|
|
|
53217
53229
|
}
|
|
53218
53230
|
const condition = (kind === "long" ? entry > app_config.support : entry >= app_config.support) && stop >= app_config.support * 0.999;
|
|
53219
53231
|
if (kind === "short") {
|
|
53220
|
-
console.log("condition", condition, entry === stop);
|
|
53221
53232
|
}
|
|
53222
|
-
console.log({ entry, support: app_config.support, stop });
|
|
53223
53233
|
const result = entry === stop ? [] : condition ? instance.build_entry({
|
|
53224
53234
|
current_price: entry,
|
|
53225
53235
|
stop_loss: stop,
|
|
@@ -53548,7 +53558,6 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
53548
53558
|
const tolerance = 0.1;
|
|
53549
53559
|
const max_iterations = 150;
|
|
53550
53560
|
let iterations = 0;
|
|
53551
|
-
console.log(`Starting risk search for ${position2.kind} position. Target Entry: ${position2.entry}, Initial Risk Range: [${low_risk}, ${high_risk}]`);
|
|
53552
53561
|
while (high_risk - low_risk > tolerance && iterations < max_iterations) {
|
|
53553
53562
|
iterations++;
|
|
53554
53563
|
const mid_risk = (low_risk + high_risk) / 2;
|
|
@@ -53594,9 +53603,7 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
53594
53603
|
price_places: current_app_config.price_places,
|
|
53595
53604
|
decimal_places: current_app_config.decimal_places
|
|
53596
53605
|
});
|
|
53597
|
-
console.log(`Iteration ${iterations}: Risk=${mid_risk.toFixed(2)}, Low=${low_risk.toFixed(2)}, High=${high_risk.toFixed(2)}`);
|
|
53598
53606
|
if (full_trades.length === 0) {
|
|
53599
|
-
console.log(` -> No trades generated by sortedBuildConfig at Risk=${mid_risk.toFixed(2)}. Adjusting high_risk down.`);
|
|
53600
53607
|
high_risk = mid_risk;
|
|
53601
53608
|
continue;
|
|
53602
53609
|
}
|
|
@@ -53609,29 +53616,23 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
53609
53616
|
existingOrders: []
|
|
53610
53617
|
});
|
|
53611
53618
|
if (trades.length === 0) {
|
|
53612
|
-
console.log(` -> No trades met quantity requirement after filtering at Risk=${mid_risk.toFixed(2)}. Adjusting low_risk up.`);
|
|
53613
53619
|
low_risk = mid_risk;
|
|
53614
53620
|
continue;
|
|
53615
53621
|
}
|
|
53616
53622
|
const last_trade = trades[trades.length - 1];
|
|
53617
53623
|
const last_entry = last_trade.entry;
|
|
53618
|
-
console.log(` -> Last Trade Entry (Filtered): ${last_entry.toFixed(4)}`);
|
|
53619
53624
|
if (position2.kind === "long") {
|
|
53620
53625
|
if (last_entry > position2.entry) {
|
|
53621
|
-
console.log(` -> Constraint VIOLATED (Long): last_entry (${last_entry.toFixed(4)}) > position.entry (${position2.entry.toFixed(4)}). Reducing high_risk.`);
|
|
53622
53626
|
high_risk = mid_risk;
|
|
53623
53627
|
} else {
|
|
53624
|
-
console.log(` -> Constraint MET (Long): last_entry (${last_entry.toFixed(4)}) <= position.entry (${position2.entry.toFixed(4)}). Storing as best, increasing low_risk.`);
|
|
53625
53628
|
best_risk = mid_risk;
|
|
53626
53629
|
best_app_config = current_app_config;
|
|
53627
53630
|
low_risk = mid_risk;
|
|
53628
53631
|
}
|
|
53629
53632
|
} else {
|
|
53630
53633
|
if (last_entry < position2.entry) {
|
|
53631
|
-
console.log(` -> Constraint VIOLATED (Short): last_entry (${last_entry.toFixed(4)}) < position.entry (${position2.entry.toFixed(4)}). Reducing high_risk.`);
|
|
53632
53634
|
high_risk = mid_risk;
|
|
53633
53635
|
} else {
|
|
53634
|
-
console.log(` -> Constraint MET (Short): last_entry (${last_entry.toFixed(4)}) >= position.entry (${position2.entry.toFixed(4)}). Storing as best, increasing low_risk.`);
|
|
53635
53636
|
best_risk = mid_risk;
|
|
53636
53637
|
best_app_config = current_app_config;
|
|
53637
53638
|
low_risk = mid_risk;
|
|
@@ -53869,7 +53870,6 @@ class Strategy {
|
|
|
53869
53870
|
quantity,
|
|
53870
53871
|
kind
|
|
53871
53872
|
};
|
|
53872
|
-
console.log({ second_payload, third_payload });
|
|
53873
53873
|
const app_config = generateOptimumAppConfig(this.config.global_config, second_payload, third_payload);
|
|
53874
53874
|
let entries = [];
|
|
53875
53875
|
let risk_per_trade = this.config.budget;
|
|
@@ -53882,6 +53882,7 @@ class Strategy {
|
|
|
53882
53882
|
if (ignore_entries) {
|
|
53883
53883
|
entries = [];
|
|
53884
53884
|
}
|
|
53885
|
+
console.log({ app_config });
|
|
53885
53886
|
}
|
|
53886
53887
|
const risk = this.to_f(risk_per_trade);
|
|
53887
53888
|
let below_reverse_entries = kind === "long" ? entries.filter((u) => {
|
|
@@ -58615,6 +58616,7 @@ class ExchangeAccount {
|
|
|
58615
58616
|
kind,
|
|
58616
58617
|
place,
|
|
58617
58618
|
tp,
|
|
58619
|
+
limit = true,
|
|
58618
58620
|
raw: _raw,
|
|
58619
58621
|
cancel,
|
|
58620
58622
|
stop,
|
|
@@ -58627,13 +58629,14 @@ class ExchangeAccount {
|
|
|
58627
58629
|
kind
|
|
58628
58630
|
});
|
|
58629
58631
|
}
|
|
58630
|
-
if (
|
|
58632
|
+
if (limit) {
|
|
58631
58633
|
return await this.triggerTradeFromConfig({
|
|
58632
58634
|
symbol,
|
|
58633
58635
|
kind,
|
|
58634
58636
|
raw: payload.raw,
|
|
58635
58637
|
stop,
|
|
58636
|
-
ignore_config
|
|
58638
|
+
ignore_config,
|
|
58639
|
+
place
|
|
58637
58640
|
});
|
|
58638
58641
|
}
|
|
58639
58642
|
await this.syncAccount({
|
|
@@ -58960,7 +58963,7 @@ class App {
|
|
|
58960
58963
|
return await this.app_db.getMoverExchangeInstances();
|
|
58961
58964
|
}
|
|
58962
58965
|
async updateTpOnAllMarkets() {
|
|
58963
|
-
const move_instances = await this.
|
|
58966
|
+
const move_instances = await this.app_db.getAccountWithActivePositions();
|
|
58964
58967
|
for (const instance of move_instances) {
|
|
58965
58968
|
const params = {
|
|
58966
58969
|
account: {
|
package/dist/mcp-server.cjs
CHANGED
|
@@ -58220,6 +58220,18 @@ class AppDatabase {
|
|
|
58220
58220
|
await this.saveCredentials(password, credentials);
|
|
58221
58221
|
}
|
|
58222
58222
|
}
|
|
58223
|
+
async getAccountWithActivePositions() {
|
|
58224
|
+
const positions = await this.pb.collection("positions").getFullList({
|
|
58225
|
+
filter: `quantity > 0`,
|
|
58226
|
+
fields: `account`
|
|
58227
|
+
});
|
|
58228
|
+
const accounts = Array.from(new Set(positions.map((p) => p.account)));
|
|
58229
|
+
const filter = accounts.map((a) => `id = "${a}"`).join(" || ");
|
|
58230
|
+
const account_instances = await this.pb.collection("exchange_accounts").getFullList({
|
|
58231
|
+
filter
|
|
58232
|
+
});
|
|
58233
|
+
return account_instances;
|
|
58234
|
+
}
|
|
58223
58235
|
async getAllSymbolsFromPositions(options) {
|
|
58224
58236
|
const { no_position = false, kind = "long", custom_filter } = options || {};
|
|
58225
58237
|
let filter = custom_filter || (no_position ? `quantity = 0` : undefined);
|
|
@@ -59966,9 +59978,7 @@ function buildConfig(app_config, {
|
|
|
59966
59978
|
}
|
|
59967
59979
|
const condition = (kind === "long" ? entry > app_config.support : entry >= app_config.support) && stop >= app_config.support * 0.999;
|
|
59968
59980
|
if (kind === "short") {
|
|
59969
|
-
console.log("condition", condition, entry === stop);
|
|
59970
59981
|
}
|
|
59971
|
-
console.log({ entry, support: app_config.support, stop });
|
|
59972
59982
|
const result = entry === stop ? [] : condition ? instance.build_entry({
|
|
59973
59983
|
current_price: entry,
|
|
59974
59984
|
stop_loss: stop,
|
|
@@ -60284,7 +60294,6 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
60284
60294
|
const tolerance = 0.1;
|
|
60285
60295
|
const max_iterations = 150;
|
|
60286
60296
|
let iterations = 0;
|
|
60287
|
-
console.log(`Starting risk search for ${position2.kind} position. Target Entry: ${position2.entry}, Initial Risk Range: [${low_risk}, ${high_risk}]`);
|
|
60288
60297
|
while (high_risk - low_risk > tolerance && iterations < max_iterations) {
|
|
60289
60298
|
iterations++;
|
|
60290
60299
|
const mid_risk = (low_risk + high_risk) / 2;
|
|
@@ -60330,9 +60339,7 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
60330
60339
|
price_places: current_app_config.price_places,
|
|
60331
60340
|
decimal_places: current_app_config.decimal_places
|
|
60332
60341
|
});
|
|
60333
|
-
console.log(`Iteration ${iterations}: Risk=${mid_risk.toFixed(2)}, Low=${low_risk.toFixed(2)}, High=${high_risk.toFixed(2)}`);
|
|
60334
60342
|
if (full_trades.length === 0) {
|
|
60335
|
-
console.log(` -> No trades generated by sortedBuildConfig at Risk=${mid_risk.toFixed(2)}. Adjusting high_risk down.`);
|
|
60336
60343
|
high_risk = mid_risk;
|
|
60337
60344
|
continue;
|
|
60338
60345
|
}
|
|
@@ -60345,29 +60352,23 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
60345
60352
|
existingOrders: []
|
|
60346
60353
|
});
|
|
60347
60354
|
if (trades.length === 0) {
|
|
60348
|
-
console.log(` -> No trades met quantity requirement after filtering at Risk=${mid_risk.toFixed(2)}. Adjusting low_risk up.`);
|
|
60349
60355
|
low_risk = mid_risk;
|
|
60350
60356
|
continue;
|
|
60351
60357
|
}
|
|
60352
60358
|
const last_trade = trades[trades.length - 1];
|
|
60353
60359
|
const last_entry = last_trade.entry;
|
|
60354
|
-
console.log(` -> Last Trade Entry (Filtered): ${last_entry.toFixed(4)}`);
|
|
60355
60360
|
if (position2.kind === "long") {
|
|
60356
60361
|
if (last_entry > position2.entry) {
|
|
60357
|
-
console.log(` -> Constraint VIOLATED (Long): last_entry (${last_entry.toFixed(4)}) > position.entry (${position2.entry.toFixed(4)}). Reducing high_risk.`);
|
|
60358
60362
|
high_risk = mid_risk;
|
|
60359
60363
|
} else {
|
|
60360
|
-
console.log(` -> Constraint MET (Long): last_entry (${last_entry.toFixed(4)}) <= position.entry (${position2.entry.toFixed(4)}). Storing as best, increasing low_risk.`);
|
|
60361
60364
|
best_risk = mid_risk;
|
|
60362
60365
|
best_app_config = current_app_config;
|
|
60363
60366
|
low_risk = mid_risk;
|
|
60364
60367
|
}
|
|
60365
60368
|
} else {
|
|
60366
60369
|
if (last_entry < position2.entry) {
|
|
60367
|
-
console.log(` -> Constraint VIOLATED (Short): last_entry (${last_entry.toFixed(4)}) < position.entry (${position2.entry.toFixed(4)}). Reducing high_risk.`);
|
|
60368
60370
|
high_risk = mid_risk;
|
|
60369
60371
|
} else {
|
|
60370
|
-
console.log(` -> Constraint MET (Short): last_entry (${last_entry.toFixed(4)}) >= position.entry (${position2.entry.toFixed(4)}). Storing as best, increasing low_risk.`);
|
|
60371
60372
|
best_risk = mid_risk;
|
|
60372
60373
|
best_app_config = current_app_config;
|
|
60373
60374
|
low_risk = mid_risk;
|
|
@@ -60605,7 +60606,6 @@ class Strategy {
|
|
|
60605
60606
|
quantity,
|
|
60606
60607
|
kind
|
|
60607
60608
|
};
|
|
60608
|
-
console.log({ second_payload, third_payload });
|
|
60609
60609
|
const app_config = generateOptimumAppConfig(this.config.global_config, second_payload, third_payload);
|
|
60610
60610
|
let entries = [];
|
|
60611
60611
|
let risk_per_trade = this.config.budget;
|
|
@@ -60618,6 +60618,7 @@ class Strategy {
|
|
|
60618
60618
|
if (ignore_entries) {
|
|
60619
60619
|
entries = [];
|
|
60620
60620
|
}
|
|
60621
|
+
console.log({ app_config });
|
|
60621
60622
|
}
|
|
60622
60623
|
const risk = this.to_f(risk_per_trade);
|
|
60623
60624
|
let below_reverse_entries = kind === "long" ? entries.filter((u) => {
|
|
@@ -65351,6 +65352,7 @@ class ExchangeAccount {
|
|
|
65351
65352
|
kind,
|
|
65352
65353
|
place,
|
|
65353
65354
|
tp,
|
|
65355
|
+
limit = true,
|
|
65354
65356
|
raw: _raw,
|
|
65355
65357
|
cancel,
|
|
65356
65358
|
stop,
|
|
@@ -65363,13 +65365,14 @@ class ExchangeAccount {
|
|
|
65363
65365
|
kind
|
|
65364
65366
|
});
|
|
65365
65367
|
}
|
|
65366
|
-
if (
|
|
65368
|
+
if (limit) {
|
|
65367
65369
|
return await this.triggerTradeFromConfig({
|
|
65368
65370
|
symbol,
|
|
65369
65371
|
kind,
|
|
65370
65372
|
raw: payload.raw,
|
|
65371
65373
|
stop,
|
|
65372
|
-
ignore_config
|
|
65374
|
+
ignore_config,
|
|
65375
|
+
place
|
|
65373
65376
|
});
|
|
65374
65377
|
}
|
|
65375
65378
|
await this.syncAccount({
|
|
@@ -65696,7 +65699,7 @@ class App {
|
|
|
65696
65699
|
return await this.app_db.getMoverExchangeInstances();
|
|
65697
65700
|
}
|
|
65698
65701
|
async updateTpOnAllMarkets() {
|
|
65699
|
-
const move_instances = await this.
|
|
65702
|
+
const move_instances = await this.app_db.getAccountWithActivePositions();
|
|
65700
65703
|
for (const instance of move_instances) {
|
|
65701
65704
|
const params = {
|
|
65702
65705
|
account: {
|
package/dist/mcp-server.js
CHANGED
|
@@ -58197,6 +58197,18 @@ class AppDatabase {
|
|
|
58197
58197
|
await this.saveCredentials(password, credentials);
|
|
58198
58198
|
}
|
|
58199
58199
|
}
|
|
58200
|
+
async getAccountWithActivePositions() {
|
|
58201
|
+
const positions = await this.pb.collection("positions").getFullList({
|
|
58202
|
+
filter: `quantity > 0`,
|
|
58203
|
+
fields: `account`
|
|
58204
|
+
});
|
|
58205
|
+
const accounts = Array.from(new Set(positions.map((p) => p.account)));
|
|
58206
|
+
const filter = accounts.map((a) => `id = "${a}"`).join(" || ");
|
|
58207
|
+
const account_instances = await this.pb.collection("exchange_accounts").getFullList({
|
|
58208
|
+
filter
|
|
58209
|
+
});
|
|
58210
|
+
return account_instances;
|
|
58211
|
+
}
|
|
58200
58212
|
async getAllSymbolsFromPositions(options) {
|
|
58201
58213
|
const { no_position = false, kind = "long", custom_filter } = options || {};
|
|
58202
58214
|
let filter = custom_filter || (no_position ? `quantity = 0` : undefined);
|
|
@@ -59943,9 +59955,7 @@ function buildConfig(app_config, {
|
|
|
59943
59955
|
}
|
|
59944
59956
|
const condition = (kind === "long" ? entry > app_config.support : entry >= app_config.support) && stop >= app_config.support * 0.999;
|
|
59945
59957
|
if (kind === "short") {
|
|
59946
|
-
console.log("condition", condition, entry === stop);
|
|
59947
59958
|
}
|
|
59948
|
-
console.log({ entry, support: app_config.support, stop });
|
|
59949
59959
|
const result = entry === stop ? [] : condition ? instance.build_entry({
|
|
59950
59960
|
current_price: entry,
|
|
59951
59961
|
stop_loss: stop,
|
|
@@ -60261,7 +60271,6 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
60261
60271
|
const tolerance = 0.1;
|
|
60262
60272
|
const max_iterations = 150;
|
|
60263
60273
|
let iterations = 0;
|
|
60264
|
-
console.log(`Starting risk search for ${position2.kind} position. Target Entry: ${position2.entry}, Initial Risk Range: [${low_risk}, ${high_risk}]`);
|
|
60265
60274
|
while (high_risk - low_risk > tolerance && iterations < max_iterations) {
|
|
60266
60275
|
iterations++;
|
|
60267
60276
|
const mid_risk = (low_risk + high_risk) / 2;
|
|
@@ -60307,9 +60316,7 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
60307
60316
|
price_places: current_app_config.price_places,
|
|
60308
60317
|
decimal_places: current_app_config.decimal_places
|
|
60309
60318
|
});
|
|
60310
|
-
console.log(`Iteration ${iterations}: Risk=${mid_risk.toFixed(2)}, Low=${low_risk.toFixed(2)}, High=${high_risk.toFixed(2)}`);
|
|
60311
60319
|
if (full_trades.length === 0) {
|
|
60312
|
-
console.log(` -> No trades generated by sortedBuildConfig at Risk=${mid_risk.toFixed(2)}. Adjusting high_risk down.`);
|
|
60313
60320
|
high_risk = mid_risk;
|
|
60314
60321
|
continue;
|
|
60315
60322
|
}
|
|
@@ -60322,29 +60329,23 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
60322
60329
|
existingOrders: []
|
|
60323
60330
|
});
|
|
60324
60331
|
if (trades.length === 0) {
|
|
60325
|
-
console.log(` -> No trades met quantity requirement after filtering at Risk=${mid_risk.toFixed(2)}. Adjusting low_risk up.`);
|
|
60326
60332
|
low_risk = mid_risk;
|
|
60327
60333
|
continue;
|
|
60328
60334
|
}
|
|
60329
60335
|
const last_trade = trades[trades.length - 1];
|
|
60330
60336
|
const last_entry = last_trade.entry;
|
|
60331
|
-
console.log(` -> Last Trade Entry (Filtered): ${last_entry.toFixed(4)}`);
|
|
60332
60337
|
if (position2.kind === "long") {
|
|
60333
60338
|
if (last_entry > position2.entry) {
|
|
60334
|
-
console.log(` -> Constraint VIOLATED (Long): last_entry (${last_entry.toFixed(4)}) > position.entry (${position2.entry.toFixed(4)}). Reducing high_risk.`);
|
|
60335
60339
|
high_risk = mid_risk;
|
|
60336
60340
|
} else {
|
|
60337
|
-
console.log(` -> Constraint MET (Long): last_entry (${last_entry.toFixed(4)}) <= position.entry (${position2.entry.toFixed(4)}). Storing as best, increasing low_risk.`);
|
|
60338
60341
|
best_risk = mid_risk;
|
|
60339
60342
|
best_app_config = current_app_config;
|
|
60340
60343
|
low_risk = mid_risk;
|
|
60341
60344
|
}
|
|
60342
60345
|
} else {
|
|
60343
60346
|
if (last_entry < position2.entry) {
|
|
60344
|
-
console.log(` -> Constraint VIOLATED (Short): last_entry (${last_entry.toFixed(4)}) < position.entry (${position2.entry.toFixed(4)}). Reducing high_risk.`);
|
|
60345
60347
|
high_risk = mid_risk;
|
|
60346
60348
|
} else {
|
|
60347
|
-
console.log(` -> Constraint MET (Short): last_entry (${last_entry.toFixed(4)}) >= position.entry (${position2.entry.toFixed(4)}). Storing as best, increasing low_risk.`);
|
|
60348
60349
|
best_risk = mid_risk;
|
|
60349
60350
|
best_app_config = current_app_config;
|
|
60350
60351
|
low_risk = mid_risk;
|
|
@@ -60582,7 +60583,6 @@ class Strategy {
|
|
|
60582
60583
|
quantity,
|
|
60583
60584
|
kind
|
|
60584
60585
|
};
|
|
60585
|
-
console.log({ second_payload, third_payload });
|
|
60586
60586
|
const app_config = generateOptimumAppConfig(this.config.global_config, second_payload, third_payload);
|
|
60587
60587
|
let entries = [];
|
|
60588
60588
|
let risk_per_trade = this.config.budget;
|
|
@@ -60595,6 +60595,7 @@ class Strategy {
|
|
|
60595
60595
|
if (ignore_entries) {
|
|
60596
60596
|
entries = [];
|
|
60597
60597
|
}
|
|
60598
|
+
console.log({ app_config });
|
|
60598
60599
|
}
|
|
60599
60600
|
const risk = this.to_f(risk_per_trade);
|
|
60600
60601
|
let below_reverse_entries = kind === "long" ? entries.filter((u) => {
|
|
@@ -65328,6 +65329,7 @@ class ExchangeAccount {
|
|
|
65328
65329
|
kind,
|
|
65329
65330
|
place,
|
|
65330
65331
|
tp,
|
|
65332
|
+
limit = true,
|
|
65331
65333
|
raw: _raw,
|
|
65332
65334
|
cancel,
|
|
65333
65335
|
stop,
|
|
@@ -65340,13 +65342,14 @@ class ExchangeAccount {
|
|
|
65340
65342
|
kind
|
|
65341
65343
|
});
|
|
65342
65344
|
}
|
|
65343
|
-
if (
|
|
65345
|
+
if (limit) {
|
|
65344
65346
|
return await this.triggerTradeFromConfig({
|
|
65345
65347
|
symbol,
|
|
65346
65348
|
kind,
|
|
65347
65349
|
raw: payload.raw,
|
|
65348
65350
|
stop,
|
|
65349
|
-
ignore_config
|
|
65351
|
+
ignore_config,
|
|
65352
|
+
place
|
|
65350
65353
|
});
|
|
65351
65354
|
}
|
|
65352
65355
|
await this.syncAccount({
|
|
@@ -65673,7 +65676,7 @@ class App {
|
|
|
65673
65676
|
return await this.app_db.getMoverExchangeInstances();
|
|
65674
65677
|
}
|
|
65675
65678
|
async updateTpOnAllMarkets() {
|
|
65676
|
-
const move_instances = await this.
|
|
65679
|
+
const move_instances = await this.app_db.getAccountWithActivePositions();
|
|
65677
65680
|
for (const instance of move_instances) {
|
|
65678
65681
|
const params = {
|
|
65679
65682
|
account: {
|