@gbozee/ultimate 0.0.2-164 → 0.0.2-166
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/frontend-index.d.ts +4 -1
- package/dist/frontend-index.js +8 -3
- package/dist/index.cjs +57 -8
- package/dist/index.d.ts +14 -2
- package/dist/index.js +57 -8
- package/dist/mcp-server.cjs +56 -8
- package/dist/mcp-server.js +56 -8
- package/package.json +1 -1
package/dist/frontend-index.d.ts
CHANGED
|
@@ -119,6 +119,7 @@ export declare function determineTPSl(payload: {
|
|
|
119
119
|
expected_loss: number;
|
|
120
120
|
};
|
|
121
121
|
export type SignalConfigType = {
|
|
122
|
+
symbol?: string;
|
|
122
123
|
focus: number;
|
|
123
124
|
budget: number;
|
|
124
125
|
percent_change?: number;
|
|
@@ -171,7 +172,8 @@ declare class Signal {
|
|
|
171
172
|
kelly_confidence_factor: number;
|
|
172
173
|
kelly_minimum_risk: number;
|
|
173
174
|
kelly_func: "theoretical" | "position_based" | "theoretical_fixed";
|
|
174
|
-
|
|
175
|
+
symbol?: string;
|
|
176
|
+
constructor({ focus, symbol, budget, percent_change, price_places, decimal_places, zone_risk, fee, support, risk_reward, resistance, risk_per_trade, increase_size, additional_increase, minimum_pnl, take_profit, increase_position, minimum_size, first_order_size, gap, max_size, use_kelly, kelly_prediction_model, kelly_confidence_factor, kelly_minimum_risk, kelly_func, }: SignalConfigType);
|
|
175
177
|
build_entry({ current_price, stop_loss, pnl, stop_percent, kind, risk, no_of_trades, take_profit, }: {
|
|
176
178
|
take_profit?: number;
|
|
177
179
|
no_of_trades?: number;
|
|
@@ -387,6 +389,7 @@ export interface PositionsView {
|
|
|
387
389
|
proxy?: Proxy$1;
|
|
388
390
|
account_strategy?: AccountStrategy;
|
|
389
391
|
};
|
|
392
|
+
pnl?: number;
|
|
390
393
|
}
|
|
391
394
|
export type AppConfig = {
|
|
392
395
|
fee: number;
|
package/dist/frontend-index.js
CHANGED
|
@@ -266,8 +266,10 @@ class Signal {
|
|
|
266
266
|
kelly_confidence_factor = 0.6;
|
|
267
267
|
kelly_minimum_risk = 0.2;
|
|
268
268
|
kelly_func = "theoretical";
|
|
269
|
+
symbol;
|
|
269
270
|
constructor({
|
|
270
271
|
focus,
|
|
272
|
+
symbol,
|
|
271
273
|
budget,
|
|
272
274
|
percent_change = 0.02,
|
|
273
275
|
price_places = "%.5f",
|
|
@@ -293,6 +295,7 @@ class Signal {
|
|
|
293
295
|
kelly_minimum_risk = 0.2,
|
|
294
296
|
kelly_func = "theoretical"
|
|
295
297
|
}) {
|
|
298
|
+
this.symbol = symbol;
|
|
296
299
|
this.minimum_size = minimum_size;
|
|
297
300
|
this.first_order_size = first_order_size;
|
|
298
301
|
this.focus = focus;
|
|
@@ -789,7 +792,7 @@ class Signal {
|
|
|
789
792
|
return y !== null ? y : undefined;
|
|
790
793
|
}) || []).filter((y) => y !== undefined).filter((y) => {
|
|
791
794
|
const min_options = [0.001, 0.002, 0.003];
|
|
792
|
-
if (min_options.includes(this.minimum_size)) {
|
|
795
|
+
if (min_options.includes(this.minimum_size) && this.symbol.toUpperCase().startsWith("BTC")) {
|
|
793
796
|
return y.quantity <= 0.03;
|
|
794
797
|
}
|
|
795
798
|
return true;
|
|
@@ -1471,7 +1474,8 @@ function buildConfig(app_config, {
|
|
|
1471
1474
|
kelly_confidence_factor: kelly_confidence_factor || app_config.kelly?.kelly_confidence_factor,
|
|
1472
1475
|
kelly_minimum_risk: kelly_minimum_risk || app_config.kelly?.kelly_minimum_risk,
|
|
1473
1476
|
kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model,
|
|
1474
|
-
kelly_func: kelly_func || app_config.kelly?.kelly_func
|
|
1477
|
+
kelly_func: kelly_func || app_config.kelly?.kelly_func,
|
|
1478
|
+
symbol: app_config.symbol
|
|
1475
1479
|
};
|
|
1476
1480
|
const instance = new Signal(config);
|
|
1477
1481
|
if (raw_instance) {
|
|
@@ -1585,7 +1589,7 @@ function buildAppConfig(config, payload) {
|
|
|
1585
1589
|
reverse_factor: 1,
|
|
1586
1590
|
profit_percent: 0,
|
|
1587
1591
|
kind: payload.entry > payload.stop ? "long" : "short",
|
|
1588
|
-
symbol: payload.symbol
|
|
1592
|
+
symbol: payload.symbol || config.symbol
|
|
1589
1593
|
}, {
|
|
1590
1594
|
entry: payload.entry,
|
|
1591
1595
|
stop: payload.stop,
|
|
@@ -2121,6 +2125,7 @@ function computeRiskReward(payload) {
|
|
|
2121
2125
|
app_config.stop = stop;
|
|
2122
2126
|
app_config.risk_per_trade = risk_per_trade;
|
|
2123
2127
|
const result = determineOptimumReward({ app_config, target_loss });
|
|
2128
|
+
console.log("result", result, "target_loss", target_loss);
|
|
2124
2129
|
return result;
|
|
2125
2130
|
}
|
|
2126
2131
|
function getRiskReward(payload) {
|
package/dist/index.cjs
CHANGED
|
@@ -44969,6 +44969,7 @@ __export(exports_src, {
|
|
|
44969
44969
|
buildAppConfig: () => buildAppConfig,
|
|
44970
44970
|
app: () => exports_app,
|
|
44971
44971
|
Strategy: () => Strategy,
|
|
44972
|
+
ExchangePosition: () => ExchangePosition,
|
|
44972
44973
|
ExchangeAccount: () => ExchangeAccount,
|
|
44973
44974
|
AppDatabase: () => AppDatabase
|
|
44974
44975
|
});
|
|
@@ -55101,7 +55102,8 @@ class AppDatabase {
|
|
|
55101
55102
|
entry: payload.entry,
|
|
55102
55103
|
stop: payload.stop,
|
|
55103
55104
|
risk_reward: payload.risk_reward,
|
|
55104
|
-
risk: payload.risk
|
|
55105
|
+
risk: payload.risk,
|
|
55106
|
+
reduce_ratio: payload.reduce_ratio
|
|
55105
55107
|
};
|
|
55106
55108
|
if (payload.profit_percent !== undefined) {
|
|
55107
55109
|
obj.profit_percent = payload.profit_percent;
|
|
@@ -55128,7 +55130,8 @@ class AppDatabase {
|
|
|
55128
55130
|
risk: payload.risk,
|
|
55129
55131
|
profit_percent: payload.profit_percent,
|
|
55130
55132
|
place_tp: payload.place_tp !== undefined ? payload.place_tp : true,
|
|
55131
|
-
profit: payload.profit !== undefined ? payload.profit : config2.profit
|
|
55133
|
+
profit: payload.profit !== undefined ? payload.profit : config2.profit,
|
|
55134
|
+
reduce_ratio: payload.reduce_ratio
|
|
55132
55135
|
});
|
|
55133
55136
|
await this.update_db_position(db_position, {
|
|
55134
55137
|
config: null
|
|
@@ -55149,7 +55152,8 @@ class AppDatabase {
|
|
|
55149
55152
|
risk_reward: payload.risk_reward,
|
|
55150
55153
|
risk: payload.risk,
|
|
55151
55154
|
profit_percent: payload.profit_percent,
|
|
55152
|
-
place_tp: payload.place_tp !== undefined ? payload.place_tp : true
|
|
55155
|
+
place_tp: payload.place_tp !== undefined ? payload.place_tp : true,
|
|
55156
|
+
reduce_ratio: payload.reduce_ratio
|
|
55153
55157
|
});
|
|
55154
55158
|
}
|
|
55155
55159
|
await this.pb.collection("positions").update(db_position.id, {
|
|
@@ -55874,8 +55878,10 @@ class Signal {
|
|
|
55874
55878
|
kelly_confidence_factor = 0.6;
|
|
55875
55879
|
kelly_minimum_risk = 0.2;
|
|
55876
55880
|
kelly_func = "theoretical";
|
|
55881
|
+
symbol;
|
|
55877
55882
|
constructor({
|
|
55878
55883
|
focus,
|
|
55884
|
+
symbol,
|
|
55879
55885
|
budget,
|
|
55880
55886
|
percent_change = 0.02,
|
|
55881
55887
|
price_places = "%.5f",
|
|
@@ -55901,6 +55907,7 @@ class Signal {
|
|
|
55901
55907
|
kelly_minimum_risk = 0.2,
|
|
55902
55908
|
kelly_func = "theoretical"
|
|
55903
55909
|
}) {
|
|
55910
|
+
this.symbol = symbol;
|
|
55904
55911
|
this.minimum_size = minimum_size;
|
|
55905
55912
|
this.first_order_size = first_order_size;
|
|
55906
55913
|
this.focus = focus;
|
|
@@ -56397,7 +56404,7 @@ class Signal {
|
|
|
56397
56404
|
return y !== null ? y : undefined;
|
|
56398
56405
|
}) || []).filter((y) => y !== undefined).filter((y) => {
|
|
56399
56406
|
const min_options = [0.001, 0.002, 0.003];
|
|
56400
|
-
if (min_options.includes(this.minimum_size)) {
|
|
56407
|
+
if (min_options.includes(this.minimum_size) && this.symbol.toUpperCase().startsWith("BTC")) {
|
|
56401
56408
|
return y.quantity <= 0.03;
|
|
56402
56409
|
}
|
|
56403
56410
|
return true;
|
|
@@ -56866,7 +56873,8 @@ function buildConfig(app_config, {
|
|
|
56866
56873
|
kelly_confidence_factor: kelly_confidence_factor || app_config.kelly?.kelly_confidence_factor,
|
|
56867
56874
|
kelly_minimum_risk: kelly_minimum_risk || app_config.kelly?.kelly_minimum_risk,
|
|
56868
56875
|
kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model,
|
|
56869
|
-
kelly_func: kelly_func || app_config.kelly?.kelly_func
|
|
56876
|
+
kelly_func: kelly_func || app_config.kelly?.kelly_func,
|
|
56877
|
+
symbol: app_config.symbol
|
|
56870
56878
|
};
|
|
56871
56879
|
const instance = new Signal(config2);
|
|
56872
56880
|
if (raw_instance) {
|
|
@@ -56980,7 +56988,7 @@ function buildAppConfig(config2, payload) {
|
|
|
56980
56988
|
reverse_factor: 1,
|
|
56981
56989
|
profit_percent: 0,
|
|
56982
56990
|
kind: payload.entry > payload.stop ? "long" : "short",
|
|
56983
|
-
symbol: payload.symbol
|
|
56991
|
+
symbol: payload.symbol || config2.symbol
|
|
56984
56992
|
}, {
|
|
56985
56993
|
entry: payload.entry,
|
|
56986
56994
|
stop: payload.stop,
|
|
@@ -57516,6 +57524,7 @@ function computeRiskReward(payload) {
|
|
|
57516
57524
|
app_config.stop = stop;
|
|
57517
57525
|
app_config.risk_per_trade = risk_per_trade;
|
|
57518
57526
|
const result = determineOptimumReward({ app_config, target_loss });
|
|
57527
|
+
console.log("result", result, "target_loss", target_loss);
|
|
57519
57528
|
return result;
|
|
57520
57529
|
}
|
|
57521
57530
|
function getRiskReward(payload) {
|
|
@@ -60924,7 +60933,8 @@ class ExchangePosition {
|
|
|
60924
60933
|
risk: payload.params.risk !== undefined ? payload.params.risk : config2?.risk,
|
|
60925
60934
|
profit_percent: payload.params.profit_percent !== undefined ? payload.params.profit_percent : config2?.profit_percent,
|
|
60926
60935
|
place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
|
|
60927
|
-
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
|
|
60936
|
+
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit,
|
|
60937
|
+
reduce_ratio: payload.params.reduce_ratio !== undefined ? payload.params.reduce_ratio : config2?.reduce_ratio
|
|
60928
60938
|
};
|
|
60929
60939
|
return await this.app_db.createOrUpdatePositionConfig({
|
|
60930
60940
|
...this.instance,
|
|
@@ -61277,6 +61287,17 @@ class ExchangePosition {
|
|
|
61277
61287
|
});
|
|
61278
61288
|
}
|
|
61279
61289
|
if (limit) {
|
|
61290
|
+
if (this.instance.quantity > 0) {
|
|
61291
|
+
const avg_qty = this.instance.avg_qty;
|
|
61292
|
+
const max_size = this.appConfig.max_size;
|
|
61293
|
+
const diff = Math.abs(avg_qty - max_size);
|
|
61294
|
+
const ratio = diff / avg_qty;
|
|
61295
|
+
if (avg_qty > max_size && ratio > 0.01) {
|
|
61296
|
+
await this.cancelOrders({
|
|
61297
|
+
limit: true
|
|
61298
|
+
});
|
|
61299
|
+
}
|
|
61300
|
+
}
|
|
61280
61301
|
return await this.triggerTradeFromConfig({
|
|
61281
61302
|
raw: _raw,
|
|
61282
61303
|
stop,
|
|
@@ -61727,11 +61748,13 @@ class ExchangePosition {
|
|
|
61727
61748
|
return config2;
|
|
61728
61749
|
}
|
|
61729
61750
|
getOppositeConfig(payload) {
|
|
61751
|
+
const profit_percent = this.instance.expand?.b_config?.profit_percent || this.instance.target_pnl;
|
|
61752
|
+
const target_pnl = profit_percent * this.instance.entry * this.instance.quantity / 100;
|
|
61730
61753
|
return generateOppositeTradeConfig({
|
|
61731
61754
|
kind: this.kind,
|
|
61732
61755
|
entry: this.instance.entry,
|
|
61733
61756
|
quantity: this.instance.quantity,
|
|
61734
|
-
target_pnl
|
|
61757
|
+
target_pnl,
|
|
61735
61758
|
global_config: this.symbol_config,
|
|
61736
61759
|
ratio: payload.ratio
|
|
61737
61760
|
});
|
|
@@ -61755,6 +61778,29 @@ class ExchangePosition {
|
|
|
61755
61778
|
kelly_config: {}
|
|
61756
61779
|
});
|
|
61757
61780
|
}
|
|
61781
|
+
async updateProfitPercentWithRisk(payload) {
|
|
61782
|
+
const { focus_position } = payload;
|
|
61783
|
+
const config2 = await this.getConfig();
|
|
61784
|
+
const profit_percent = to_f(config2.risk * 100 / (this.instance.entry * this.instance.quantity), "%.2f");
|
|
61785
|
+
if (profit_percent !== config2.profit_percent && this.instance.quantity > 0) {
|
|
61786
|
+
await this.getConfig({
|
|
61787
|
+
params: {
|
|
61788
|
+
profit_percent
|
|
61789
|
+
}
|
|
61790
|
+
});
|
|
61791
|
+
}
|
|
61792
|
+
const last_order = focus_position.instance.last_order;
|
|
61793
|
+
const take_profit = this.instance.take_profit;
|
|
61794
|
+
if (this.kind === "short" && last_order && take_profit) {
|
|
61795
|
+
const reduce_ratio = take_profit < last_order ? 1 : 0;
|
|
61796
|
+
await this.getConfig({
|
|
61797
|
+
params: {
|
|
61798
|
+
reduce_ratio
|
|
61799
|
+
}
|
|
61800
|
+
});
|
|
61801
|
+
}
|
|
61802
|
+
return { profit_percent, take_profit, last_order };
|
|
61803
|
+
}
|
|
61758
61804
|
}
|
|
61759
61805
|
|
|
61760
61806
|
// src/exchange-account.ts
|
|
@@ -63214,6 +63260,9 @@ class ExchangeAccount {
|
|
|
63214
63260
|
symbol,
|
|
63215
63261
|
kind: kind === "long" ? "short" : "long"
|
|
63216
63262
|
});
|
|
63263
|
+
await reversePosition.updateProfitPercentWithRisk({
|
|
63264
|
+
focus_position
|
|
63265
|
+
});
|
|
63217
63266
|
if (focus_position.getInstance().quantity > 0) {
|
|
63218
63267
|
const opposite_config = focus_position.getOppositeConfig({
|
|
63219
63268
|
ratio: reward_factor
|
package/dist/index.d.ts
CHANGED
|
@@ -143,6 +143,7 @@ export interface PositionsView {
|
|
|
143
143
|
proxy?: Proxy$1;
|
|
144
144
|
account_strategy?: AccountStrategy;
|
|
145
145
|
};
|
|
146
|
+
pnl?: number;
|
|
146
147
|
}
|
|
147
148
|
export interface BullishMarket extends RecordModel {
|
|
148
149
|
id: string;
|
|
@@ -735,6 +736,7 @@ export declare class AppDatabase {
|
|
|
735
736
|
profit_percent?: number;
|
|
736
737
|
place_tp?: boolean;
|
|
737
738
|
profit?: number;
|
|
739
|
+
reduce_ratio?: number;
|
|
738
740
|
}): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
|
|
739
741
|
getPositionConfig(payload: {
|
|
740
742
|
symbol: string;
|
|
@@ -1142,6 +1144,7 @@ export declare function determine_average_entry_and_size(orders: Array<{
|
|
|
1142
1144
|
};
|
|
1143
1145
|
export declare const createArray: (start: number, stop: number, step: number) => number[];
|
|
1144
1146
|
export type SignalConfigType = {
|
|
1147
|
+
symbol?: string;
|
|
1145
1148
|
focus: number;
|
|
1146
1149
|
budget: number;
|
|
1147
1150
|
percent_change?: number;
|
|
@@ -1194,7 +1197,8 @@ declare class Signal {
|
|
|
1194
1197
|
kelly_confidence_factor: number;
|
|
1195
1198
|
kelly_minimum_risk: number;
|
|
1196
1199
|
kelly_func: "theoretical" | "position_based" | "theoretical_fixed";
|
|
1197
|
-
|
|
1200
|
+
symbol?: string;
|
|
1201
|
+
constructor({ focus, symbol, budget, percent_change, price_places, decimal_places, zone_risk, fee, support, risk_reward, resistance, risk_per_trade, increase_size, additional_increase, minimum_pnl, take_profit, increase_position, minimum_size, first_order_size, gap, max_size, use_kelly, kelly_prediction_model, kelly_confidence_factor, kelly_minimum_risk, kelly_func, }: SignalConfigType);
|
|
1198
1202
|
build_entry({ current_price, stop_loss, pnl, stop_percent, kind, risk, no_of_trades, take_profit, }: {
|
|
1199
1203
|
take_profit?: number;
|
|
1200
1204
|
no_of_trades?: number;
|
|
@@ -1702,7 +1706,7 @@ export declare function constructAppConfig(payload: {
|
|
|
1702
1706
|
kelly_prediction_model: string;
|
|
1703
1707
|
};
|
|
1704
1708
|
}): AppConfig;
|
|
1705
|
-
declare class ExchangePosition {
|
|
1709
|
+
export declare class ExchangePosition {
|
|
1706
1710
|
exchange: BaseExchange;
|
|
1707
1711
|
symbol_config: SymbolConfig;
|
|
1708
1712
|
exchange_account: ExchangeAccount$1;
|
|
@@ -1751,6 +1755,7 @@ declare class ExchangePosition {
|
|
|
1751
1755
|
profit_percent?: number;
|
|
1752
1756
|
place_tp?: boolean;
|
|
1753
1757
|
profit?: number;
|
|
1758
|
+
reduce_ratio?: number;
|
|
1754
1759
|
};
|
|
1755
1760
|
}): Promise<import("pocketbase").RecordModel | ScheduledTrade>;
|
|
1756
1761
|
updateTargetPnl(): Promise<any>;
|
|
@@ -2020,6 +2025,13 @@ declare class ExchangePosition {
|
|
|
2020
2025
|
entry: any;
|
|
2021
2026
|
}>;
|
|
2022
2027
|
get appConfig(): AppConfig;
|
|
2028
|
+
updateProfitPercentWithRisk(payload: {
|
|
2029
|
+
focus_position: ExchangePosition;
|
|
2030
|
+
}): Promise<{
|
|
2031
|
+
profit_percent: number;
|
|
2032
|
+
take_profit: any;
|
|
2033
|
+
last_order: number;
|
|
2034
|
+
}>;
|
|
2023
2035
|
}
|
|
2024
2036
|
declare class ExchangeAccount$1 {
|
|
2025
2037
|
instance: {
|
package/dist/index.js
CHANGED
|
@@ -55047,7 +55047,8 @@ class AppDatabase {
|
|
|
55047
55047
|
entry: payload.entry,
|
|
55048
55048
|
stop: payload.stop,
|
|
55049
55049
|
risk_reward: payload.risk_reward,
|
|
55050
|
-
risk: payload.risk
|
|
55050
|
+
risk: payload.risk,
|
|
55051
|
+
reduce_ratio: payload.reduce_ratio
|
|
55051
55052
|
};
|
|
55052
55053
|
if (payload.profit_percent !== undefined) {
|
|
55053
55054
|
obj.profit_percent = payload.profit_percent;
|
|
@@ -55074,7 +55075,8 @@ class AppDatabase {
|
|
|
55074
55075
|
risk: payload.risk,
|
|
55075
55076
|
profit_percent: payload.profit_percent,
|
|
55076
55077
|
place_tp: payload.place_tp !== undefined ? payload.place_tp : true,
|
|
55077
|
-
profit: payload.profit !== undefined ? payload.profit : config2.profit
|
|
55078
|
+
profit: payload.profit !== undefined ? payload.profit : config2.profit,
|
|
55079
|
+
reduce_ratio: payload.reduce_ratio
|
|
55078
55080
|
});
|
|
55079
55081
|
await this.update_db_position(db_position, {
|
|
55080
55082
|
config: null
|
|
@@ -55095,7 +55097,8 @@ class AppDatabase {
|
|
|
55095
55097
|
risk_reward: payload.risk_reward,
|
|
55096
55098
|
risk: payload.risk,
|
|
55097
55099
|
profit_percent: payload.profit_percent,
|
|
55098
|
-
place_tp: payload.place_tp !== undefined ? payload.place_tp : true
|
|
55100
|
+
place_tp: payload.place_tp !== undefined ? payload.place_tp : true,
|
|
55101
|
+
reduce_ratio: payload.reduce_ratio
|
|
55099
55102
|
});
|
|
55100
55103
|
}
|
|
55101
55104
|
await this.pb.collection("positions").update(db_position.id, {
|
|
@@ -55820,8 +55823,10 @@ class Signal {
|
|
|
55820
55823
|
kelly_confidence_factor = 0.6;
|
|
55821
55824
|
kelly_minimum_risk = 0.2;
|
|
55822
55825
|
kelly_func = "theoretical";
|
|
55826
|
+
symbol;
|
|
55823
55827
|
constructor({
|
|
55824
55828
|
focus,
|
|
55829
|
+
symbol,
|
|
55825
55830
|
budget,
|
|
55826
55831
|
percent_change = 0.02,
|
|
55827
55832
|
price_places = "%.5f",
|
|
@@ -55847,6 +55852,7 @@ class Signal {
|
|
|
55847
55852
|
kelly_minimum_risk = 0.2,
|
|
55848
55853
|
kelly_func = "theoretical"
|
|
55849
55854
|
}) {
|
|
55855
|
+
this.symbol = symbol;
|
|
55850
55856
|
this.minimum_size = minimum_size;
|
|
55851
55857
|
this.first_order_size = first_order_size;
|
|
55852
55858
|
this.focus = focus;
|
|
@@ -56343,7 +56349,7 @@ class Signal {
|
|
|
56343
56349
|
return y !== null ? y : undefined;
|
|
56344
56350
|
}) || []).filter((y) => y !== undefined).filter((y) => {
|
|
56345
56351
|
const min_options = [0.001, 0.002, 0.003];
|
|
56346
|
-
if (min_options.includes(this.minimum_size)) {
|
|
56352
|
+
if (min_options.includes(this.minimum_size) && this.symbol.toUpperCase().startsWith("BTC")) {
|
|
56347
56353
|
return y.quantity <= 0.03;
|
|
56348
56354
|
}
|
|
56349
56355
|
return true;
|
|
@@ -56812,7 +56818,8 @@ function buildConfig(app_config, {
|
|
|
56812
56818
|
kelly_confidence_factor: kelly_confidence_factor || app_config.kelly?.kelly_confidence_factor,
|
|
56813
56819
|
kelly_minimum_risk: kelly_minimum_risk || app_config.kelly?.kelly_minimum_risk,
|
|
56814
56820
|
kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model,
|
|
56815
|
-
kelly_func: kelly_func || app_config.kelly?.kelly_func
|
|
56821
|
+
kelly_func: kelly_func || app_config.kelly?.kelly_func,
|
|
56822
|
+
symbol: app_config.symbol
|
|
56816
56823
|
};
|
|
56817
56824
|
const instance = new Signal(config2);
|
|
56818
56825
|
if (raw_instance) {
|
|
@@ -56926,7 +56933,7 @@ function buildAppConfig(config2, payload) {
|
|
|
56926
56933
|
reverse_factor: 1,
|
|
56927
56934
|
profit_percent: 0,
|
|
56928
56935
|
kind: payload.entry > payload.stop ? "long" : "short",
|
|
56929
|
-
symbol: payload.symbol
|
|
56936
|
+
symbol: payload.symbol || config2.symbol
|
|
56930
56937
|
}, {
|
|
56931
56938
|
entry: payload.entry,
|
|
56932
56939
|
stop: payload.stop,
|
|
@@ -57462,6 +57469,7 @@ function computeRiskReward(payload) {
|
|
|
57462
57469
|
app_config.stop = stop;
|
|
57463
57470
|
app_config.risk_per_trade = risk_per_trade;
|
|
57464
57471
|
const result = determineOptimumReward({ app_config, target_loss });
|
|
57472
|
+
console.log("result", result, "target_loss", target_loss);
|
|
57465
57473
|
return result;
|
|
57466
57474
|
}
|
|
57467
57475
|
function getRiskReward(payload) {
|
|
@@ -60870,7 +60878,8 @@ class ExchangePosition {
|
|
|
60870
60878
|
risk: payload.params.risk !== undefined ? payload.params.risk : config2?.risk,
|
|
60871
60879
|
profit_percent: payload.params.profit_percent !== undefined ? payload.params.profit_percent : config2?.profit_percent,
|
|
60872
60880
|
place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
|
|
60873
|
-
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
|
|
60881
|
+
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit,
|
|
60882
|
+
reduce_ratio: payload.params.reduce_ratio !== undefined ? payload.params.reduce_ratio : config2?.reduce_ratio
|
|
60874
60883
|
};
|
|
60875
60884
|
return await this.app_db.createOrUpdatePositionConfig({
|
|
60876
60885
|
...this.instance,
|
|
@@ -61223,6 +61232,17 @@ class ExchangePosition {
|
|
|
61223
61232
|
});
|
|
61224
61233
|
}
|
|
61225
61234
|
if (limit) {
|
|
61235
|
+
if (this.instance.quantity > 0) {
|
|
61236
|
+
const avg_qty = this.instance.avg_qty;
|
|
61237
|
+
const max_size = this.appConfig.max_size;
|
|
61238
|
+
const diff = Math.abs(avg_qty - max_size);
|
|
61239
|
+
const ratio = diff / avg_qty;
|
|
61240
|
+
if (avg_qty > max_size && ratio > 0.01) {
|
|
61241
|
+
await this.cancelOrders({
|
|
61242
|
+
limit: true
|
|
61243
|
+
});
|
|
61244
|
+
}
|
|
61245
|
+
}
|
|
61226
61246
|
return await this.triggerTradeFromConfig({
|
|
61227
61247
|
raw: _raw,
|
|
61228
61248
|
stop,
|
|
@@ -61673,11 +61693,13 @@ class ExchangePosition {
|
|
|
61673
61693
|
return config2;
|
|
61674
61694
|
}
|
|
61675
61695
|
getOppositeConfig(payload) {
|
|
61696
|
+
const profit_percent = this.instance.expand?.b_config?.profit_percent || this.instance.target_pnl;
|
|
61697
|
+
const target_pnl = profit_percent * this.instance.entry * this.instance.quantity / 100;
|
|
61676
61698
|
return generateOppositeTradeConfig({
|
|
61677
61699
|
kind: this.kind,
|
|
61678
61700
|
entry: this.instance.entry,
|
|
61679
61701
|
quantity: this.instance.quantity,
|
|
61680
|
-
target_pnl
|
|
61702
|
+
target_pnl,
|
|
61681
61703
|
global_config: this.symbol_config,
|
|
61682
61704
|
ratio: payload.ratio
|
|
61683
61705
|
});
|
|
@@ -61701,6 +61723,29 @@ class ExchangePosition {
|
|
|
61701
61723
|
kelly_config: {}
|
|
61702
61724
|
});
|
|
61703
61725
|
}
|
|
61726
|
+
async updateProfitPercentWithRisk(payload) {
|
|
61727
|
+
const { focus_position } = payload;
|
|
61728
|
+
const config2 = await this.getConfig();
|
|
61729
|
+
const profit_percent = to_f(config2.risk * 100 / (this.instance.entry * this.instance.quantity), "%.2f");
|
|
61730
|
+
if (profit_percent !== config2.profit_percent && this.instance.quantity > 0) {
|
|
61731
|
+
await this.getConfig({
|
|
61732
|
+
params: {
|
|
61733
|
+
profit_percent
|
|
61734
|
+
}
|
|
61735
|
+
});
|
|
61736
|
+
}
|
|
61737
|
+
const last_order = focus_position.instance.last_order;
|
|
61738
|
+
const take_profit = this.instance.take_profit;
|
|
61739
|
+
if (this.kind === "short" && last_order && take_profit) {
|
|
61740
|
+
const reduce_ratio = take_profit < last_order ? 1 : 0;
|
|
61741
|
+
await this.getConfig({
|
|
61742
|
+
params: {
|
|
61743
|
+
reduce_ratio
|
|
61744
|
+
}
|
|
61745
|
+
});
|
|
61746
|
+
}
|
|
61747
|
+
return { profit_percent, take_profit, last_order };
|
|
61748
|
+
}
|
|
61704
61749
|
}
|
|
61705
61750
|
|
|
61706
61751
|
// src/exchange-account.ts
|
|
@@ -63160,6 +63205,9 @@ class ExchangeAccount {
|
|
|
63160
63205
|
symbol,
|
|
63161
63206
|
kind: kind === "long" ? "short" : "long"
|
|
63162
63207
|
});
|
|
63208
|
+
await reversePosition.updateProfitPercentWithRisk({
|
|
63209
|
+
focus_position
|
|
63210
|
+
});
|
|
63163
63211
|
if (focus_position.getInstance().quantity > 0) {
|
|
63164
63212
|
const opposite_config = focus_position.getOppositeConfig({
|
|
63165
63213
|
ratio: reward_factor
|
|
@@ -63930,6 +63978,7 @@ export {
|
|
|
63930
63978
|
buildAppConfig,
|
|
63931
63979
|
exports_app as app,
|
|
63932
63980
|
Strategy,
|
|
63981
|
+
ExchangePosition,
|
|
63933
63982
|
ExchangeAccount,
|
|
63934
63983
|
AppDatabase
|
|
63935
63984
|
};
|
package/dist/mcp-server.cjs
CHANGED
|
@@ -61801,7 +61801,8 @@ class AppDatabase {
|
|
|
61801
61801
|
entry: payload.entry,
|
|
61802
61802
|
stop: payload.stop,
|
|
61803
61803
|
risk_reward: payload.risk_reward,
|
|
61804
|
-
risk: payload.risk
|
|
61804
|
+
risk: payload.risk,
|
|
61805
|
+
reduce_ratio: payload.reduce_ratio
|
|
61805
61806
|
};
|
|
61806
61807
|
if (payload.profit_percent !== undefined) {
|
|
61807
61808
|
obj.profit_percent = payload.profit_percent;
|
|
@@ -61828,7 +61829,8 @@ class AppDatabase {
|
|
|
61828
61829
|
risk: payload.risk,
|
|
61829
61830
|
profit_percent: payload.profit_percent,
|
|
61830
61831
|
place_tp: payload.place_tp !== undefined ? payload.place_tp : true,
|
|
61831
|
-
profit: payload.profit !== undefined ? payload.profit : config2.profit
|
|
61832
|
+
profit: payload.profit !== undefined ? payload.profit : config2.profit,
|
|
61833
|
+
reduce_ratio: payload.reduce_ratio
|
|
61832
61834
|
});
|
|
61833
61835
|
await this.update_db_position(db_position, {
|
|
61834
61836
|
config: null
|
|
@@ -61849,7 +61851,8 @@ class AppDatabase {
|
|
|
61849
61851
|
risk_reward: payload.risk_reward,
|
|
61850
61852
|
risk: payload.risk,
|
|
61851
61853
|
profit_percent: payload.profit_percent,
|
|
61852
|
-
place_tp: payload.place_tp !== undefined ? payload.place_tp : true
|
|
61854
|
+
place_tp: payload.place_tp !== undefined ? payload.place_tp : true,
|
|
61855
|
+
reduce_ratio: payload.reduce_ratio
|
|
61853
61856
|
});
|
|
61854
61857
|
}
|
|
61855
61858
|
await this.pb.collection("positions").update(db_position.id, {
|
|
@@ -62567,8 +62570,10 @@ class Signal {
|
|
|
62567
62570
|
kelly_confidence_factor = 0.6;
|
|
62568
62571
|
kelly_minimum_risk = 0.2;
|
|
62569
62572
|
kelly_func = "theoretical";
|
|
62573
|
+
symbol;
|
|
62570
62574
|
constructor({
|
|
62571
62575
|
focus,
|
|
62576
|
+
symbol,
|
|
62572
62577
|
budget,
|
|
62573
62578
|
percent_change = 0.02,
|
|
62574
62579
|
price_places = "%.5f",
|
|
@@ -62594,6 +62599,7 @@ class Signal {
|
|
|
62594
62599
|
kelly_minimum_risk = 0.2,
|
|
62595
62600
|
kelly_func = "theoretical"
|
|
62596
62601
|
}) {
|
|
62602
|
+
this.symbol = symbol;
|
|
62597
62603
|
this.minimum_size = minimum_size;
|
|
62598
62604
|
this.first_order_size = first_order_size;
|
|
62599
62605
|
this.focus = focus;
|
|
@@ -63090,7 +63096,7 @@ class Signal {
|
|
|
63090
63096
|
return y !== null ? y : undefined;
|
|
63091
63097
|
}) || []).filter((y) => y !== undefined).filter((y) => {
|
|
63092
63098
|
const min_options = [0.001, 0.002, 0.003];
|
|
63093
|
-
if (min_options.includes(this.minimum_size)) {
|
|
63099
|
+
if (min_options.includes(this.minimum_size) && this.symbol.toUpperCase().startsWith("BTC")) {
|
|
63094
63100
|
return y.quantity <= 0.03;
|
|
63095
63101
|
}
|
|
63096
63102
|
return true;
|
|
@@ -63559,7 +63565,8 @@ function buildConfig(app_config, {
|
|
|
63559
63565
|
kelly_confidence_factor: kelly_confidence_factor || app_config.kelly?.kelly_confidence_factor,
|
|
63560
63566
|
kelly_minimum_risk: kelly_minimum_risk || app_config.kelly?.kelly_minimum_risk,
|
|
63561
63567
|
kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model,
|
|
63562
|
-
kelly_func: kelly_func || app_config.kelly?.kelly_func
|
|
63568
|
+
kelly_func: kelly_func || app_config.kelly?.kelly_func,
|
|
63569
|
+
symbol: app_config.symbol
|
|
63563
63570
|
};
|
|
63564
63571
|
const instance = new Signal(config2);
|
|
63565
63572
|
if (raw_instance) {
|
|
@@ -63660,7 +63667,7 @@ function buildAppConfig(config2, payload) {
|
|
|
63660
63667
|
reverse_factor: 1,
|
|
63661
63668
|
profit_percent: 0,
|
|
63662
63669
|
kind: payload.entry > payload.stop ? "long" : "short",
|
|
63663
|
-
symbol: payload.symbol
|
|
63670
|
+
symbol: payload.symbol || config2.symbol
|
|
63664
63671
|
}, {
|
|
63665
63672
|
entry: payload.entry,
|
|
63666
63673
|
stop: payload.stop,
|
|
@@ -64196,6 +64203,7 @@ function computeRiskReward(payload) {
|
|
|
64196
64203
|
app_config.stop = stop;
|
|
64197
64204
|
app_config.risk_per_trade = risk_per_trade;
|
|
64198
64205
|
const result = determineOptimumReward({ app_config, target_loss });
|
|
64206
|
+
console.log("result", result, "target_loss", target_loss);
|
|
64199
64207
|
return result;
|
|
64200
64208
|
}
|
|
64201
64209
|
function getRiskReward(payload) {
|
|
@@ -67598,7 +67606,8 @@ class ExchangePosition {
|
|
|
67598
67606
|
risk: payload.params.risk !== undefined ? payload.params.risk : config2?.risk,
|
|
67599
67607
|
profit_percent: payload.params.profit_percent !== undefined ? payload.params.profit_percent : config2?.profit_percent,
|
|
67600
67608
|
place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
|
|
67601
|
-
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
|
|
67609
|
+
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit,
|
|
67610
|
+
reduce_ratio: payload.params.reduce_ratio !== undefined ? payload.params.reduce_ratio : config2?.reduce_ratio
|
|
67602
67611
|
};
|
|
67603
67612
|
return await this.app_db.createOrUpdatePositionConfig({
|
|
67604
67613
|
...this.instance,
|
|
@@ -67951,6 +67960,17 @@ class ExchangePosition {
|
|
|
67951
67960
|
});
|
|
67952
67961
|
}
|
|
67953
67962
|
if (limit) {
|
|
67963
|
+
if (this.instance.quantity > 0) {
|
|
67964
|
+
const avg_qty = this.instance.avg_qty;
|
|
67965
|
+
const max_size = this.appConfig.max_size;
|
|
67966
|
+
const diff = Math.abs(avg_qty - max_size);
|
|
67967
|
+
const ratio = diff / avg_qty;
|
|
67968
|
+
if (avg_qty > max_size && ratio > 0.01) {
|
|
67969
|
+
await this.cancelOrders({
|
|
67970
|
+
limit: true
|
|
67971
|
+
});
|
|
67972
|
+
}
|
|
67973
|
+
}
|
|
67954
67974
|
return await this.triggerTradeFromConfig({
|
|
67955
67975
|
raw: _raw,
|
|
67956
67976
|
stop,
|
|
@@ -68401,11 +68421,13 @@ class ExchangePosition {
|
|
|
68401
68421
|
return config2;
|
|
68402
68422
|
}
|
|
68403
68423
|
getOppositeConfig(payload) {
|
|
68424
|
+
const profit_percent = this.instance.expand?.b_config?.profit_percent || this.instance.target_pnl;
|
|
68425
|
+
const target_pnl = profit_percent * this.instance.entry * this.instance.quantity / 100;
|
|
68404
68426
|
return generateOppositeTradeConfig({
|
|
68405
68427
|
kind: this.kind,
|
|
68406
68428
|
entry: this.instance.entry,
|
|
68407
68429
|
quantity: this.instance.quantity,
|
|
68408
|
-
target_pnl
|
|
68430
|
+
target_pnl,
|
|
68409
68431
|
global_config: this.symbol_config,
|
|
68410
68432
|
ratio: payload.ratio
|
|
68411
68433
|
});
|
|
@@ -68429,6 +68451,29 @@ class ExchangePosition {
|
|
|
68429
68451
|
kelly_config: {}
|
|
68430
68452
|
});
|
|
68431
68453
|
}
|
|
68454
|
+
async updateProfitPercentWithRisk(payload) {
|
|
68455
|
+
const { focus_position } = payload;
|
|
68456
|
+
const config2 = await this.getConfig();
|
|
68457
|
+
const profit_percent = to_f(config2.risk * 100 / (this.instance.entry * this.instance.quantity), "%.2f");
|
|
68458
|
+
if (profit_percent !== config2.profit_percent && this.instance.quantity > 0) {
|
|
68459
|
+
await this.getConfig({
|
|
68460
|
+
params: {
|
|
68461
|
+
profit_percent
|
|
68462
|
+
}
|
|
68463
|
+
});
|
|
68464
|
+
}
|
|
68465
|
+
const last_order = focus_position.instance.last_order;
|
|
68466
|
+
const take_profit = this.instance.take_profit;
|
|
68467
|
+
if (this.kind === "short" && last_order && take_profit) {
|
|
68468
|
+
const reduce_ratio = take_profit < last_order ? 1 : 0;
|
|
68469
|
+
await this.getConfig({
|
|
68470
|
+
params: {
|
|
68471
|
+
reduce_ratio
|
|
68472
|
+
}
|
|
68473
|
+
});
|
|
68474
|
+
}
|
|
68475
|
+
return { profit_percent, take_profit, last_order };
|
|
68476
|
+
}
|
|
68432
68477
|
}
|
|
68433
68478
|
|
|
68434
68479
|
// src/exchange-account.ts
|
|
@@ -69888,6 +69933,9 @@ class ExchangeAccount {
|
|
|
69888
69933
|
symbol,
|
|
69889
69934
|
kind: kind === "long" ? "short" : "long"
|
|
69890
69935
|
});
|
|
69936
|
+
await reversePosition.updateProfitPercentWithRisk({
|
|
69937
|
+
focus_position
|
|
69938
|
+
});
|
|
69891
69939
|
if (focus_position.getInstance().quantity > 0) {
|
|
69892
69940
|
const opposite_config = focus_position.getOppositeConfig({
|
|
69893
69941
|
ratio: reward_factor
|
package/dist/mcp-server.js
CHANGED
|
@@ -61778,7 +61778,8 @@ class AppDatabase {
|
|
|
61778
61778
|
entry: payload.entry,
|
|
61779
61779
|
stop: payload.stop,
|
|
61780
61780
|
risk_reward: payload.risk_reward,
|
|
61781
|
-
risk: payload.risk
|
|
61781
|
+
risk: payload.risk,
|
|
61782
|
+
reduce_ratio: payload.reduce_ratio
|
|
61782
61783
|
};
|
|
61783
61784
|
if (payload.profit_percent !== undefined) {
|
|
61784
61785
|
obj.profit_percent = payload.profit_percent;
|
|
@@ -61805,7 +61806,8 @@ class AppDatabase {
|
|
|
61805
61806
|
risk: payload.risk,
|
|
61806
61807
|
profit_percent: payload.profit_percent,
|
|
61807
61808
|
place_tp: payload.place_tp !== undefined ? payload.place_tp : true,
|
|
61808
|
-
profit: payload.profit !== undefined ? payload.profit : config2.profit
|
|
61809
|
+
profit: payload.profit !== undefined ? payload.profit : config2.profit,
|
|
61810
|
+
reduce_ratio: payload.reduce_ratio
|
|
61809
61811
|
});
|
|
61810
61812
|
await this.update_db_position(db_position, {
|
|
61811
61813
|
config: null
|
|
@@ -61826,7 +61828,8 @@ class AppDatabase {
|
|
|
61826
61828
|
risk_reward: payload.risk_reward,
|
|
61827
61829
|
risk: payload.risk,
|
|
61828
61830
|
profit_percent: payload.profit_percent,
|
|
61829
|
-
place_tp: payload.place_tp !== undefined ? payload.place_tp : true
|
|
61831
|
+
place_tp: payload.place_tp !== undefined ? payload.place_tp : true,
|
|
61832
|
+
reduce_ratio: payload.reduce_ratio
|
|
61830
61833
|
});
|
|
61831
61834
|
}
|
|
61832
61835
|
await this.pb.collection("positions").update(db_position.id, {
|
|
@@ -62544,8 +62547,10 @@ class Signal {
|
|
|
62544
62547
|
kelly_confidence_factor = 0.6;
|
|
62545
62548
|
kelly_minimum_risk = 0.2;
|
|
62546
62549
|
kelly_func = "theoretical";
|
|
62550
|
+
symbol;
|
|
62547
62551
|
constructor({
|
|
62548
62552
|
focus,
|
|
62553
|
+
symbol,
|
|
62549
62554
|
budget,
|
|
62550
62555
|
percent_change = 0.02,
|
|
62551
62556
|
price_places = "%.5f",
|
|
@@ -62571,6 +62576,7 @@ class Signal {
|
|
|
62571
62576
|
kelly_minimum_risk = 0.2,
|
|
62572
62577
|
kelly_func = "theoretical"
|
|
62573
62578
|
}) {
|
|
62579
|
+
this.symbol = symbol;
|
|
62574
62580
|
this.minimum_size = minimum_size;
|
|
62575
62581
|
this.first_order_size = first_order_size;
|
|
62576
62582
|
this.focus = focus;
|
|
@@ -63067,7 +63073,7 @@ class Signal {
|
|
|
63067
63073
|
return y !== null ? y : undefined;
|
|
63068
63074
|
}) || []).filter((y) => y !== undefined).filter((y) => {
|
|
63069
63075
|
const min_options = [0.001, 0.002, 0.003];
|
|
63070
|
-
if (min_options.includes(this.minimum_size)) {
|
|
63076
|
+
if (min_options.includes(this.minimum_size) && this.symbol.toUpperCase().startsWith("BTC")) {
|
|
63071
63077
|
return y.quantity <= 0.03;
|
|
63072
63078
|
}
|
|
63073
63079
|
return true;
|
|
@@ -63536,7 +63542,8 @@ function buildConfig(app_config, {
|
|
|
63536
63542
|
kelly_confidence_factor: kelly_confidence_factor || app_config.kelly?.kelly_confidence_factor,
|
|
63537
63543
|
kelly_minimum_risk: kelly_minimum_risk || app_config.kelly?.kelly_minimum_risk,
|
|
63538
63544
|
kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model,
|
|
63539
|
-
kelly_func: kelly_func || app_config.kelly?.kelly_func
|
|
63545
|
+
kelly_func: kelly_func || app_config.kelly?.kelly_func,
|
|
63546
|
+
symbol: app_config.symbol
|
|
63540
63547
|
};
|
|
63541
63548
|
const instance = new Signal(config2);
|
|
63542
63549
|
if (raw_instance) {
|
|
@@ -63637,7 +63644,7 @@ function buildAppConfig(config2, payload) {
|
|
|
63637
63644
|
reverse_factor: 1,
|
|
63638
63645
|
profit_percent: 0,
|
|
63639
63646
|
kind: payload.entry > payload.stop ? "long" : "short",
|
|
63640
|
-
symbol: payload.symbol
|
|
63647
|
+
symbol: payload.symbol || config2.symbol
|
|
63641
63648
|
}, {
|
|
63642
63649
|
entry: payload.entry,
|
|
63643
63650
|
stop: payload.stop,
|
|
@@ -64173,6 +64180,7 @@ function computeRiskReward(payload) {
|
|
|
64173
64180
|
app_config.stop = stop;
|
|
64174
64181
|
app_config.risk_per_trade = risk_per_trade;
|
|
64175
64182
|
const result = determineOptimumReward({ app_config, target_loss });
|
|
64183
|
+
console.log("result", result, "target_loss", target_loss);
|
|
64176
64184
|
return result;
|
|
64177
64185
|
}
|
|
64178
64186
|
function getRiskReward(payload) {
|
|
@@ -67575,7 +67583,8 @@ class ExchangePosition {
|
|
|
67575
67583
|
risk: payload.params.risk !== undefined ? payload.params.risk : config2?.risk,
|
|
67576
67584
|
profit_percent: payload.params.profit_percent !== undefined ? payload.params.profit_percent : config2?.profit_percent,
|
|
67577
67585
|
place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
|
|
67578
|
-
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
|
|
67586
|
+
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit,
|
|
67587
|
+
reduce_ratio: payload.params.reduce_ratio !== undefined ? payload.params.reduce_ratio : config2?.reduce_ratio
|
|
67579
67588
|
};
|
|
67580
67589
|
return await this.app_db.createOrUpdatePositionConfig({
|
|
67581
67590
|
...this.instance,
|
|
@@ -67928,6 +67937,17 @@ class ExchangePosition {
|
|
|
67928
67937
|
});
|
|
67929
67938
|
}
|
|
67930
67939
|
if (limit) {
|
|
67940
|
+
if (this.instance.quantity > 0) {
|
|
67941
|
+
const avg_qty = this.instance.avg_qty;
|
|
67942
|
+
const max_size = this.appConfig.max_size;
|
|
67943
|
+
const diff = Math.abs(avg_qty - max_size);
|
|
67944
|
+
const ratio = diff / avg_qty;
|
|
67945
|
+
if (avg_qty > max_size && ratio > 0.01) {
|
|
67946
|
+
await this.cancelOrders({
|
|
67947
|
+
limit: true
|
|
67948
|
+
});
|
|
67949
|
+
}
|
|
67950
|
+
}
|
|
67931
67951
|
return await this.triggerTradeFromConfig({
|
|
67932
67952
|
raw: _raw,
|
|
67933
67953
|
stop,
|
|
@@ -68378,11 +68398,13 @@ class ExchangePosition {
|
|
|
68378
68398
|
return config2;
|
|
68379
68399
|
}
|
|
68380
68400
|
getOppositeConfig(payload) {
|
|
68401
|
+
const profit_percent = this.instance.expand?.b_config?.profit_percent || this.instance.target_pnl;
|
|
68402
|
+
const target_pnl = profit_percent * this.instance.entry * this.instance.quantity / 100;
|
|
68381
68403
|
return generateOppositeTradeConfig({
|
|
68382
68404
|
kind: this.kind,
|
|
68383
68405
|
entry: this.instance.entry,
|
|
68384
68406
|
quantity: this.instance.quantity,
|
|
68385
|
-
target_pnl
|
|
68407
|
+
target_pnl,
|
|
68386
68408
|
global_config: this.symbol_config,
|
|
68387
68409
|
ratio: payload.ratio
|
|
68388
68410
|
});
|
|
@@ -68406,6 +68428,29 @@ class ExchangePosition {
|
|
|
68406
68428
|
kelly_config: {}
|
|
68407
68429
|
});
|
|
68408
68430
|
}
|
|
68431
|
+
async updateProfitPercentWithRisk(payload) {
|
|
68432
|
+
const { focus_position } = payload;
|
|
68433
|
+
const config2 = await this.getConfig();
|
|
68434
|
+
const profit_percent = to_f(config2.risk * 100 / (this.instance.entry * this.instance.quantity), "%.2f");
|
|
68435
|
+
if (profit_percent !== config2.profit_percent && this.instance.quantity > 0) {
|
|
68436
|
+
await this.getConfig({
|
|
68437
|
+
params: {
|
|
68438
|
+
profit_percent
|
|
68439
|
+
}
|
|
68440
|
+
});
|
|
68441
|
+
}
|
|
68442
|
+
const last_order = focus_position.instance.last_order;
|
|
68443
|
+
const take_profit = this.instance.take_profit;
|
|
68444
|
+
if (this.kind === "short" && last_order && take_profit) {
|
|
68445
|
+
const reduce_ratio = take_profit < last_order ? 1 : 0;
|
|
68446
|
+
await this.getConfig({
|
|
68447
|
+
params: {
|
|
68448
|
+
reduce_ratio
|
|
68449
|
+
}
|
|
68450
|
+
});
|
|
68451
|
+
}
|
|
68452
|
+
return { profit_percent, take_profit, last_order };
|
|
68453
|
+
}
|
|
68409
68454
|
}
|
|
68410
68455
|
|
|
68411
68456
|
// src/exchange-account.ts
|
|
@@ -69865,6 +69910,9 @@ class ExchangeAccount {
|
|
|
69865
69910
|
symbol,
|
|
69866
69911
|
kind: kind === "long" ? "short" : "long"
|
|
69867
69912
|
});
|
|
69913
|
+
await reversePosition.updateProfitPercentWithRisk({
|
|
69914
|
+
focus_position
|
|
69915
|
+
});
|
|
69868
69916
|
if (focus_position.getInstance().quantity > 0) {
|
|
69869
69917
|
const opposite_config = focus_position.getOppositeConfig({
|
|
69870
69918
|
ratio: reward_factor
|