@gbozee/ultimate 0.0.2-78 → 0.0.2-82
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 +2 -13
- package/dist/index.cjs +184 -48
- package/dist/index.d.ts +98 -10
- package/dist/index.js +184 -48
- package/dist/mcp-server.cjs +190 -54
- package/dist/mcp-server.js +190 -54
- package/package.json +1 -1
package/dist/frontend-index.js
CHANGED
|
@@ -610,7 +610,7 @@ class Signal {
|
|
|
610
610
|
new_stop
|
|
611
611
|
};
|
|
612
612
|
});
|
|
613
|
-
if (greater_than_min_size.length !==
|
|
613
|
+
if (greater_than_min_size.length !== total_orders.length) {
|
|
614
614
|
payload = greater_than_min_size.concat(less_than_min_size);
|
|
615
615
|
}
|
|
616
616
|
return payload;
|
|
@@ -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);
|
|
@@ -53102,7 +53114,7 @@ class Signal {
|
|
|
53102
53114
|
new_stop
|
|
53103
53115
|
};
|
|
53104
53116
|
});
|
|
53105
|
-
if (greater_than_min_size.length !==
|
|
53117
|
+
if (greater_than_min_size.length !== total_orders.length) {
|
|
53106
53118
|
payload = greater_than_min_size.concat(less_than_min_size);
|
|
53107
53119
|
}
|
|
53108
53120
|
return payload;
|
|
@@ -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({
|
|
@@ -58767,7 +58770,6 @@ async function getExchangeAccount(payload) {
|
|
|
58767
58770
|
app_db
|
|
58768
58771
|
});
|
|
58769
58772
|
}
|
|
58770
|
-
|
|
58771
58773
|
// src/app.ts
|
|
58772
58774
|
class App {
|
|
58773
58775
|
app_db;
|
|
@@ -58826,37 +58828,6 @@ class App {
|
|
|
58826
58828
|
stop: payload.stop
|
|
58827
58829
|
});
|
|
58828
58830
|
}
|
|
58829
|
-
async updateReduceRatio(payload) {
|
|
58830
|
-
const { symbol } = payload;
|
|
58831
|
-
const exchange_account = await this.getExchangeAccount(payload.account);
|
|
58832
|
-
const positions = await exchange_account.syncAccount({
|
|
58833
|
-
as_view: true,
|
|
58834
|
-
symbol
|
|
58835
|
-
});
|
|
58836
|
-
const active_account = await exchange_account.getActiveAccount({
|
|
58837
|
-
symbol
|
|
58838
|
-
});
|
|
58839
|
-
const long_position = active_account.position.long;
|
|
58840
|
-
const short_position = active_account.position.short;
|
|
58841
|
-
const long_db_position = positions.find((p) => p.kind === "long");
|
|
58842
|
-
const short_db_position = positions.find((p) => p.kind === "short");
|
|
58843
|
-
const balance = active_account.usd_balance || 0;
|
|
58844
|
-
const long_liquidation = long_db_position.avg_price * long_db_position.avg_qty / long_db_position.leverage - balance / long_db_position.avg_qty + long_db_position.avg_price;
|
|
58845
|
-
const short_liquidation = -(short_db_position.avg_price * short_db_position.avg_qty / short_db_position.leverage) + balance / short_db_position.avg_qty + short_db_position.avg_price;
|
|
58846
|
-
long_position.avg_liquidation = to_f2(long_liquidation, "%.3f");
|
|
58847
|
-
short_position.avg_liquidation = to_f2(short_liquidation, "%.3f");
|
|
58848
|
-
const long_ratio = Math.max(long_position.avg_liquidation, long_position.avg_entry) / Math.min(long_position.avg_liquidation, long_position.avg_entry) - 1;
|
|
58849
|
-
const short_ratio = Math.max(short_position.avg_liquidation, short_position.avg_entry) / Math.min(short_position.avg_liquidation, short_position.avg_entry) - 1;
|
|
58850
|
-
long_position.liquidation_ratio = to_f2(long_ratio, "%.3f") * 100;
|
|
58851
|
-
short_position.liquidation_ratio = to_f2(short_ratio, "%.3f") * 100;
|
|
58852
|
-
return {
|
|
58853
|
-
long_position,
|
|
58854
|
-
short_position,
|
|
58855
|
-
long_db_position,
|
|
58856
|
-
short_db_position,
|
|
58857
|
-
balance: active_account.usd_balance
|
|
58858
|
-
};
|
|
58859
|
-
}
|
|
58860
58831
|
async getWindingDownMarkets() {
|
|
58861
58832
|
return await this.app_db.getWindingDownMarkets();
|
|
58862
58833
|
}
|
|
@@ -59005,7 +58976,7 @@ class App {
|
|
|
59005
58976
|
return await this.app_db.getMoverExchangeInstances();
|
|
59006
58977
|
}
|
|
59007
58978
|
async updateTpOnAllMarkets() {
|
|
59008
|
-
const move_instances = await this.
|
|
58979
|
+
const move_instances = await this.app_db.getAccountWithActivePositions();
|
|
59009
58980
|
for (const instance of move_instances) {
|
|
59010
58981
|
const params = {
|
|
59011
58982
|
account: {
|
|
@@ -59066,6 +59037,171 @@ class App {
|
|
|
59066
59037
|
});
|
|
59067
59038
|
return result;
|
|
59068
59039
|
}
|
|
59040
|
+
async profitWithinGapStrategy(payload) {
|
|
59041
|
+
const {
|
|
59042
|
+
account,
|
|
59043
|
+
symbol,
|
|
59044
|
+
kind,
|
|
59045
|
+
risk,
|
|
59046
|
+
resistance,
|
|
59047
|
+
support,
|
|
59048
|
+
reward_factor = 1
|
|
59049
|
+
} = payload;
|
|
59050
|
+
const exchange_account = await this.getExchangeAccount(account);
|
|
59051
|
+
console.log("Getting entry and stop for ", symbol, kind);
|
|
59052
|
+
const entry = kind === "long" ? resistance : support;
|
|
59053
|
+
const stop = kind === "long" ? support : resistance;
|
|
59054
|
+
console.log("Building app config for ", symbol, kind);
|
|
59055
|
+
const initial_app_config = await exchange_account.buildAppConfig({
|
|
59056
|
+
entry,
|
|
59057
|
+
stop,
|
|
59058
|
+
risk_reward: 199,
|
|
59059
|
+
risk,
|
|
59060
|
+
symbol
|
|
59061
|
+
});
|
|
59062
|
+
console.log("Computing risk reward for ", symbol, kind);
|
|
59063
|
+
const risk_reward = computeRiskReward({
|
|
59064
|
+
app_config: initial_app_config,
|
|
59065
|
+
entry: initial_app_config.entry,
|
|
59066
|
+
stop: initial_app_config.stop,
|
|
59067
|
+
risk_per_trade: initial_app_config.risk_per_trade
|
|
59068
|
+
});
|
|
59069
|
+
console.log("Re-computing app config for ", symbol, kind);
|
|
59070
|
+
const { entries, last_value, ...app_config } = await exchange_account.buildAppConfig({
|
|
59071
|
+
entry: initial_app_config.entry,
|
|
59072
|
+
stop: initial_app_config.stop,
|
|
59073
|
+
risk_reward,
|
|
59074
|
+
risk,
|
|
59075
|
+
symbol
|
|
59076
|
+
});
|
|
59077
|
+
console.log("Computing profit percent for ", symbol, kind);
|
|
59078
|
+
const pnl = reward_factor * risk;
|
|
59079
|
+
const profit_percent = to_f2(pnl * 100 / (last_value.avg_entry * last_value.avg_size), "%.4f");
|
|
59080
|
+
let config2 = {
|
|
59081
|
+
entry,
|
|
59082
|
+
stop,
|
|
59083
|
+
risk,
|
|
59084
|
+
risk_reward,
|
|
59085
|
+
profit_percent
|
|
59086
|
+
};
|
|
59087
|
+
console.log("Saving new config for ", symbol, kind);
|
|
59088
|
+
const data = await exchange_account.getPositionConfig({
|
|
59089
|
+
symbol,
|
|
59090
|
+
kind,
|
|
59091
|
+
params: config2
|
|
59092
|
+
});
|
|
59093
|
+
console.log("Checking orders to place for ", symbol, kind);
|
|
59094
|
+
const orders_to_place = await exchange_account.placeTrade({
|
|
59095
|
+
symbol,
|
|
59096
|
+
raw: true,
|
|
59097
|
+
kind,
|
|
59098
|
+
place: false
|
|
59099
|
+
});
|
|
59100
|
+
config2 = {
|
|
59101
|
+
...config2,
|
|
59102
|
+
...data
|
|
59103
|
+
};
|
|
59104
|
+
console.log("Fetching positions for ", symbol);
|
|
59105
|
+
const positions = await exchange_account.syncAccount({
|
|
59106
|
+
symbol,
|
|
59107
|
+
as_view: true
|
|
59108
|
+
});
|
|
59109
|
+
console.log("Getting long and short positions for ", symbol);
|
|
59110
|
+
const long_position = positions.find((k) => k.kind === "long");
|
|
59111
|
+
const short_position = positions.find((k) => k.kind === "short");
|
|
59112
|
+
console.log("Getting focus position for ", symbol, kind);
|
|
59113
|
+
const focus_position = kind === "long" ? long_position : short_position;
|
|
59114
|
+
const reverse_position = kind === "long" ? short_position : long_position;
|
|
59115
|
+
let reverse_action = null;
|
|
59116
|
+
let reverse_orders_to_buy = [];
|
|
59117
|
+
let reverse_config = null;
|
|
59118
|
+
console.log("Checking if focus position has quantity for ", symbol, kind);
|
|
59119
|
+
if (focus_position.quantity > 0) {
|
|
59120
|
+
console.log("Getting details for ", reverse_position.kind);
|
|
59121
|
+
reverse_action = await exchange_account.buildOppositeTrades({
|
|
59122
|
+
symbol,
|
|
59123
|
+
kind
|
|
59124
|
+
});
|
|
59125
|
+
console.log("Updating config for ", symbol, reverse_action.kind);
|
|
59126
|
+
await exchange_account.getPositionConfig({
|
|
59127
|
+
symbol,
|
|
59128
|
+
kind: reverse_action.kind,
|
|
59129
|
+
params: {
|
|
59130
|
+
entry: reverse_action.entry,
|
|
59131
|
+
stop: reverse_action.stop,
|
|
59132
|
+
risk: reverse_action.risk_per_trade,
|
|
59133
|
+
profit_percent: reverse_action.profit_percent,
|
|
59134
|
+
risk_reward: reverse_action.risk_reward
|
|
59135
|
+
}
|
|
59136
|
+
});
|
|
59137
|
+
console.log("Checking reverse orders to buy for ", symbol, reverse_action.kind);
|
|
59138
|
+
reverse_orders_to_buy = await exchange_account.placeTrade({
|
|
59139
|
+
symbol,
|
|
59140
|
+
raw: true,
|
|
59141
|
+
kind: reverse_action.kind,
|
|
59142
|
+
place: false
|
|
59143
|
+
});
|
|
59144
|
+
let _reverse_config = {
|
|
59145
|
+
avg: reverse_action.avg,
|
|
59146
|
+
entry: reverse_action.entry,
|
|
59147
|
+
stop: reverse_action.stop,
|
|
59148
|
+
risk_per_trade: reverse_action.risk_per_trade,
|
|
59149
|
+
profit_percent: reverse_action.profit_percent,
|
|
59150
|
+
risk_reward: reverse_action.risk_reward
|
|
59151
|
+
};
|
|
59152
|
+
if (reverse_orders_to_buy.length > 0) {
|
|
59153
|
+
console.log("Placing opposite trade action for ", symbol, reverse_action.kind);
|
|
59154
|
+
let existing = await exchange_account.placeOppositeTradeAction({
|
|
59155
|
+
symbol,
|
|
59156
|
+
kind: reverse_action.kind,
|
|
59157
|
+
data: _reverse_config
|
|
59158
|
+
});
|
|
59159
|
+
_reverse_config = {
|
|
59160
|
+
...existing,
|
|
59161
|
+
..._reverse_config
|
|
59162
|
+
};
|
|
59163
|
+
}
|
|
59164
|
+
reverse_config = _reverse_config;
|
|
59165
|
+
if (!reverse_config?.id) {
|
|
59166
|
+
console.log("fetching reverse config for ", symbol, reverse_action.kind);
|
|
59167
|
+
reverse_config = await exchange_account.getPositionConfig({
|
|
59168
|
+
symbol,
|
|
59169
|
+
kind: reverse_action.kind
|
|
59170
|
+
});
|
|
59171
|
+
}
|
|
59172
|
+
if (reverse_position.quantity > 0 && reverse_config?.id) {
|
|
59173
|
+
console.log("Checking if reverse position has quantity for ", symbol, reverse_action.kind);
|
|
59174
|
+
const max_size = app_config.max_size * 0.98;
|
|
59175
|
+
if (reverse_config.threshold_qty !== max_size) {
|
|
59176
|
+
await this.app_db.updateScheduledTrade(reverse_config.id, {
|
|
59177
|
+
follow: true,
|
|
59178
|
+
threshold_qty: max_size
|
|
59179
|
+
});
|
|
59180
|
+
}
|
|
59181
|
+
console.log("Updating follow and threshold for ", symbol, reverse_action.kind);
|
|
59182
|
+
} else {
|
|
59183
|
+
await this.app_db.updateScheduledTrade(reverse_config.id, {
|
|
59184
|
+
follow: false
|
|
59185
|
+
});
|
|
59186
|
+
}
|
|
59187
|
+
}
|
|
59188
|
+
return {
|
|
59189
|
+
reverse_config,
|
|
59190
|
+
reverse_action,
|
|
59191
|
+
reverse_orders_to_buy,
|
|
59192
|
+
positions: {
|
|
59193
|
+
long: long_position,
|
|
59194
|
+
short: short_position
|
|
59195
|
+
},
|
|
59196
|
+
orders_to_place,
|
|
59197
|
+
config_details: {
|
|
59198
|
+
app_config,
|
|
59199
|
+
last_value,
|
|
59200
|
+
config: config2,
|
|
59201
|
+
pnl
|
|
59202
|
+
}
|
|
59203
|
+
};
|
|
59204
|
+
}
|
|
59069
59205
|
}
|
|
59070
59206
|
async function initApp(payload) {
|
|
59071
59207
|
const pb = await initPocketBaseClient(payload.db);
|
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;
|
|
@@ -1735,16 +1737,6 @@ declare class App {
|
|
|
1735
1737
|
message?: undefined;
|
|
1736
1738
|
exchange_result?: undefined;
|
|
1737
1739
|
}>;
|
|
1738
|
-
updateReduceRatio(payload: {
|
|
1739
|
-
account: ExchangeType;
|
|
1740
|
-
symbol: string;
|
|
1741
|
-
}): Promise<{
|
|
1742
|
-
long_position: any;
|
|
1743
|
-
short_position: any;
|
|
1744
|
-
long_db_position: any;
|
|
1745
|
-
short_db_position: any;
|
|
1746
|
-
balance: any;
|
|
1747
|
-
}>;
|
|
1748
1740
|
getWindingDownMarkets(): Promise<WindingDownMarket[]>;
|
|
1749
1741
|
updateSymbolConfigs(payload: {
|
|
1750
1742
|
configs: {
|
|
@@ -1791,6 +1783,102 @@ declare class App {
|
|
|
1791
1783
|
cancel?: boolean;
|
|
1792
1784
|
raw?: boolean;
|
|
1793
1785
|
}): Promise<any>;
|
|
1786
|
+
profitWithinGapStrategy(payload: {
|
|
1787
|
+
account: ExchangeType;
|
|
1788
|
+
symbol: string;
|
|
1789
|
+
kind: "long" | "short";
|
|
1790
|
+
risk: number;
|
|
1791
|
+
resistance: number;
|
|
1792
|
+
support: number;
|
|
1793
|
+
reward_factor?: number;
|
|
1794
|
+
}): Promise<{
|
|
1795
|
+
reverse_config: any;
|
|
1796
|
+
reverse_action: {
|
|
1797
|
+
avg: {
|
|
1798
|
+
entry: number;
|
|
1799
|
+
price: number;
|
|
1800
|
+
quantity: number;
|
|
1801
|
+
};
|
|
1802
|
+
loss: number;
|
|
1803
|
+
profit_percent: number;
|
|
1804
|
+
fee: number;
|
|
1805
|
+
risk_per_trade: number;
|
|
1806
|
+
risk_reward: number;
|
|
1807
|
+
symbol?: string;
|
|
1808
|
+
focus: number;
|
|
1809
|
+
budget: number;
|
|
1810
|
+
support: number;
|
|
1811
|
+
resistance: number;
|
|
1812
|
+
percent_change: number;
|
|
1813
|
+
tradeSplit?: number;
|
|
1814
|
+
take_profit?: number;
|
|
1815
|
+
kind: "long" | "short";
|
|
1816
|
+
entry: number;
|
|
1817
|
+
stop: number;
|
|
1818
|
+
min_size: number;
|
|
1819
|
+
price_places?: string;
|
|
1820
|
+
strategy?: "quantity" | "entry";
|
|
1821
|
+
as_array?: boolean;
|
|
1822
|
+
decimal_places?: string;
|
|
1823
|
+
min_profit?: number;
|
|
1824
|
+
raw?: boolean;
|
|
1825
|
+
gap?: number;
|
|
1826
|
+
rr?: number;
|
|
1827
|
+
max_size?: number;
|
|
1828
|
+
};
|
|
1829
|
+
reverse_orders_to_buy: any;
|
|
1830
|
+
positions: {
|
|
1831
|
+
long: PositionsView;
|
|
1832
|
+
short: PositionsView;
|
|
1833
|
+
};
|
|
1834
|
+
orders_to_place: any;
|
|
1835
|
+
config_details: {
|
|
1836
|
+
app_config: {
|
|
1837
|
+
fee: number;
|
|
1838
|
+
risk_per_trade: number;
|
|
1839
|
+
risk_reward: number;
|
|
1840
|
+
symbol?: string;
|
|
1841
|
+
focus: number;
|
|
1842
|
+
budget: number;
|
|
1843
|
+
support: number;
|
|
1844
|
+
resistance: number;
|
|
1845
|
+
percent_change: number;
|
|
1846
|
+
tradeSplit?: number;
|
|
1847
|
+
take_profit?: number;
|
|
1848
|
+
kind: "long" | "short";
|
|
1849
|
+
entry: number;
|
|
1850
|
+
stop: number;
|
|
1851
|
+
min_size: number;
|
|
1852
|
+
price_places?: string;
|
|
1853
|
+
strategy?: "quantity" | "entry";
|
|
1854
|
+
as_array?: boolean;
|
|
1855
|
+
decimal_places?: string;
|
|
1856
|
+
min_profit?: number;
|
|
1857
|
+
raw?: boolean;
|
|
1858
|
+
gap?: number;
|
|
1859
|
+
rr?: number;
|
|
1860
|
+
max_size?: number;
|
|
1861
|
+
};
|
|
1862
|
+
last_value: any;
|
|
1863
|
+
config: {
|
|
1864
|
+
entry: number;
|
|
1865
|
+
stop: number;
|
|
1866
|
+
risk: number;
|
|
1867
|
+
risk_reward: number | {
|
|
1868
|
+
result: any[];
|
|
1869
|
+
value: number;
|
|
1870
|
+
total: number;
|
|
1871
|
+
risk_per_trade: number;
|
|
1872
|
+
max: number;
|
|
1873
|
+
min: number;
|
|
1874
|
+
neg_pnl: any;
|
|
1875
|
+
entry: any;
|
|
1876
|
+
};
|
|
1877
|
+
profit_percent: number;
|
|
1878
|
+
};
|
|
1879
|
+
pnl: number;
|
|
1880
|
+
};
|
|
1881
|
+
}>;
|
|
1794
1882
|
}
|
|
1795
1883
|
export declare function initApp(payload: {
|
|
1796
1884
|
db: {
|