@gbozee/ultimate 0.0.2-157 → 0.0.2-159
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 +16 -0
- package/dist/frontend-index.js +2 -1
- package/dist/index.cjs +75 -35
- package/dist/index.d.ts +18 -5
- package/dist/index.js +75 -35
- package/dist/mcp-server.cjs +75 -35
- package/dist/mcp-server.js +75 -35
- package/package.json +1 -1
package/dist/frontend-index.d.ts
CHANGED
|
@@ -277,6 +277,7 @@ export type GlobalConfig = {
|
|
|
277
277
|
risk_reward: number;
|
|
278
278
|
reverse_factor: number;
|
|
279
279
|
leverage?: number;
|
|
280
|
+
max_quantity?: number;
|
|
280
281
|
};
|
|
281
282
|
export interface BaseSystemFields {
|
|
282
283
|
id: string;
|
|
@@ -327,6 +328,20 @@ export interface ScheduledTrade extends BaseSystemFields {
|
|
|
327
328
|
kelly_prediction_model?: "exponential" | "normal" | "uniform";
|
|
328
329
|
};
|
|
329
330
|
}
|
|
331
|
+
export interface AccountStrategy extends BaseSystemFields {
|
|
332
|
+
account: string;
|
|
333
|
+
symbol: string;
|
|
334
|
+
risk?: number;
|
|
335
|
+
reward_factor?: number;
|
|
336
|
+
kind?: "long" | "short";
|
|
337
|
+
support?: number;
|
|
338
|
+
resistance?: number;
|
|
339
|
+
running?: boolean;
|
|
340
|
+
max_reward_factor?: number;
|
|
341
|
+
follow?: boolean;
|
|
342
|
+
risk_reward?: number;
|
|
343
|
+
dynamic?: boolean;
|
|
344
|
+
}
|
|
330
345
|
interface Proxy$1 extends BaseSystemFields {
|
|
331
346
|
ip_address?: string;
|
|
332
347
|
type?: "http" | "socks5";
|
|
@@ -370,6 +385,7 @@ export interface PositionsView {
|
|
|
370
385
|
p_account?: ExchangeAccount;
|
|
371
386
|
b_config?: ScheduledTrade;
|
|
372
387
|
proxy?: Proxy$1;
|
|
388
|
+
account_strategy?: AccountStrategy;
|
|
373
389
|
};
|
|
374
390
|
}
|
|
375
391
|
export type AppConfig = {
|
package/dist/frontend-index.js
CHANGED
|
@@ -1539,7 +1539,8 @@ function get_app_config_and_max_size(config, payload) {
|
|
|
1539
1539
|
price_places: config.price_places,
|
|
1540
1540
|
decimal_places: config.decimal_places,
|
|
1541
1541
|
min_profit: config.profit_percent * config.profit / 100,
|
|
1542
|
-
symbol: config.symbol
|
|
1542
|
+
symbol: config.symbol,
|
|
1543
|
+
max_quantity: config.max_quantity
|
|
1543
1544
|
};
|
|
1544
1545
|
const initialResult = sortedBuildConfig(app_config, {
|
|
1545
1546
|
entry: app_config.entry,
|
package/dist/index.cjs
CHANGED
|
@@ -55167,9 +55167,9 @@ class AppDatabase {
|
|
|
55167
55167
|
}
|
|
55168
55168
|
return null;
|
|
55169
55169
|
}
|
|
55170
|
-
async getRunningAccountStrategies() {
|
|
55170
|
+
async getRunningAccountStrategies(filter = "running=true") {
|
|
55171
55171
|
const result = await this.pb.collection("account_strategies").getFullList({
|
|
55172
|
-
filter
|
|
55172
|
+
filter,
|
|
55173
55173
|
expand: "account"
|
|
55174
55174
|
});
|
|
55175
55175
|
return result;
|
|
@@ -56934,7 +56934,8 @@ function get_app_config_and_max_size(config2, payload) {
|
|
|
56934
56934
|
price_places: config2.price_places,
|
|
56935
56935
|
decimal_places: config2.decimal_places,
|
|
56936
56936
|
min_profit: config2.profit_percent * config2.profit / 100,
|
|
56937
|
-
symbol: config2.symbol
|
|
56937
|
+
symbol: config2.symbol,
|
|
56938
|
+
max_quantity: config2.max_quantity
|
|
56938
56939
|
};
|
|
56939
56940
|
const initialResult = sortedBuildConfig(app_config, {
|
|
56940
56941
|
entry: app_config.entry,
|
|
@@ -60921,7 +60922,14 @@ class ExchangePosition {
|
|
|
60921
60922
|
place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
|
|
60922
60923
|
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
|
|
60923
60924
|
};
|
|
60924
|
-
return await this.app_db.createOrUpdatePositionConfig(
|
|
60925
|
+
return await this.app_db.createOrUpdatePositionConfig({
|
|
60926
|
+
...this.instance,
|
|
60927
|
+
expand: {
|
|
60928
|
+
...this.instance.expand || {},
|
|
60929
|
+
account: this.account
|
|
60930
|
+
},
|
|
60931
|
+
account: this.account.id
|
|
60932
|
+
}, params);
|
|
60925
60933
|
}
|
|
60926
60934
|
}
|
|
60927
60935
|
if (this.instance.expand?.b_config) {
|
|
@@ -61700,8 +61708,8 @@ class ExchangePosition {
|
|
|
61700
61708
|
});
|
|
61701
61709
|
return this.getConfig({
|
|
61702
61710
|
params: {
|
|
61703
|
-
entry:
|
|
61704
|
-
stop:
|
|
61711
|
+
entry: long_c.entry,
|
|
61712
|
+
stop: long_c.stop,
|
|
61705
61713
|
risk_reward: long_c.risk_reward,
|
|
61706
61714
|
risk: long_c.risk
|
|
61707
61715
|
}
|
|
@@ -63165,6 +63173,53 @@ class ExchangeAccount {
|
|
|
63165
63173
|
short_percent
|
|
63166
63174
|
};
|
|
63167
63175
|
}
|
|
63176
|
+
async oppositeGapExists(payload) {
|
|
63177
|
+
const focus_position = await this.getFocusPosition({
|
|
63178
|
+
symbol: payload.symbol,
|
|
63179
|
+
kind: payload.kind
|
|
63180
|
+
});
|
|
63181
|
+
const strategy2 = focus_position.getInstance().expand?.account_strategy;
|
|
63182
|
+
if (!strategy2) {
|
|
63183
|
+
return;
|
|
63184
|
+
}
|
|
63185
|
+
const kind = strategy2.kind;
|
|
63186
|
+
const reward_factor = strategy2.reward_factor;
|
|
63187
|
+
const { symbol } = payload;
|
|
63188
|
+
const reversePosition = await this.getFocusPosition({
|
|
63189
|
+
symbol,
|
|
63190
|
+
kind: kind === "long" ? "short" : "long"
|
|
63191
|
+
});
|
|
63192
|
+
if (focus_position.getInstance().quantity > 0) {
|
|
63193
|
+
const opposite_config = focus_position.getOppositeConfig({
|
|
63194
|
+
ratio: reward_factor
|
|
63195
|
+
});
|
|
63196
|
+
const reverse_config = await reversePosition.getConfig();
|
|
63197
|
+
if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
|
|
63198
|
+
console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
|
|
63199
|
+
await reversePosition.getConfig({
|
|
63200
|
+
params: {
|
|
63201
|
+
entry: opposite_config.entry,
|
|
63202
|
+
stop: opposite_config.stop,
|
|
63203
|
+
risk: opposite_config.risk,
|
|
63204
|
+
risk_reward: opposite_config.risk_reward
|
|
63205
|
+
}
|
|
63206
|
+
});
|
|
63207
|
+
console.log("Placing trade for ", symbol, reversePosition.kind);
|
|
63208
|
+
await reversePosition.placeTrade({
|
|
63209
|
+
ignore_config: true,
|
|
63210
|
+
limit: true,
|
|
63211
|
+
place: true
|
|
63212
|
+
});
|
|
63213
|
+
}
|
|
63214
|
+
console.log("Opposite config for ", symbol, kind, opposite_config);
|
|
63215
|
+
} else {
|
|
63216
|
+
if (focus_position.getInstance().avg_qty > 0 && strategy2.running === false) {
|
|
63217
|
+
await focus_position.cancelOrders({
|
|
63218
|
+
limit: true
|
|
63219
|
+
});
|
|
63220
|
+
}
|
|
63221
|
+
}
|
|
63222
|
+
}
|
|
63168
63223
|
async profitWithinGapStrategy(payload) {
|
|
63169
63224
|
const { symbol } = payload;
|
|
63170
63225
|
console.log("Fetching positions for ", symbol);
|
|
@@ -63181,7 +63236,6 @@ class ExchangeAccount {
|
|
|
63181
63236
|
return;
|
|
63182
63237
|
}
|
|
63183
63238
|
const kind = strategy2.kind;
|
|
63184
|
-
const reward_factor = strategy2.reward_factor;
|
|
63185
63239
|
const { entries, last_value, ...app_config } = await this.tradeConfig({
|
|
63186
63240
|
symbol,
|
|
63187
63241
|
kind
|
|
@@ -63209,34 +63263,10 @@ class ExchangeAccount {
|
|
|
63209
63263
|
});
|
|
63210
63264
|
}
|
|
63211
63265
|
console.log("Checking if focus position has quantity for ", symbol, kind);
|
|
63212
|
-
|
|
63266
|
+
await this.oppositeGapExists({
|
|
63213
63267
|
symbol,
|
|
63214
|
-
kind
|
|
63268
|
+
kind
|
|
63215
63269
|
});
|
|
63216
|
-
if (focusPosition.getInstance().quantity > 0) {
|
|
63217
|
-
const opposite_config = focusPosition.getOppositeConfig({
|
|
63218
|
-
ratio: reward_factor
|
|
63219
|
-
});
|
|
63220
|
-
const reverse_config = await reversePosition.getConfig();
|
|
63221
|
-
if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focusPosition.getInstance().quantity > 0) {
|
|
63222
|
-
console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
|
|
63223
|
-
await reversePosition.getConfig({
|
|
63224
|
-
params: {
|
|
63225
|
-
entry: opposite_config.entry,
|
|
63226
|
-
stop: opposite_config.stop,
|
|
63227
|
-
risk: opposite_config.risk,
|
|
63228
|
-
risk_reward: opposite_config.risk_reward
|
|
63229
|
-
}
|
|
63230
|
-
});
|
|
63231
|
-
console.log("Placing trade for ", symbol, reversePosition.kind);
|
|
63232
|
-
await reversePosition.placeTrade({
|
|
63233
|
-
ignore_config: true,
|
|
63234
|
-
limit: true,
|
|
63235
|
-
place: true
|
|
63236
|
-
});
|
|
63237
|
-
}
|
|
63238
|
-
console.log("Opposite config for ", symbol, kind, opposite_config);
|
|
63239
|
-
}
|
|
63240
63270
|
return {
|
|
63241
63271
|
config_details: {
|
|
63242
63272
|
app_config,
|
|
@@ -63701,15 +63731,25 @@ class App {
|
|
|
63701
63731
|
});
|
|
63702
63732
|
return result;
|
|
63703
63733
|
}
|
|
63704
|
-
async runDbStrategyAccounts(
|
|
63734
|
+
async runDbStrategyAccounts(payload) {
|
|
63735
|
+
const { runningCallback, notRunningCallback } = payload;
|
|
63705
63736
|
const strategies = await this.app_db.getRunningAccountStrategies();
|
|
63706
63737
|
for (const strategy2 of strategies) {
|
|
63707
63738
|
console.log("Running strategy for ", strategy2.symbol, "for account", strategy2.expand.account.owner, strategy2.expand.account.exchange);
|
|
63708
|
-
await
|
|
63739
|
+
await runningCallback({
|
|
63709
63740
|
symbol: strategy2.symbol,
|
|
63710
63741
|
account: strategy2.expand.account
|
|
63711
63742
|
});
|
|
63712
63743
|
}
|
|
63744
|
+
const not_running_strategies = await this.app_db.getRunningAccountStrategies("running=false");
|
|
63745
|
+
for (const strategy2 of not_running_strategies) {
|
|
63746
|
+
console.log("Not running strategy for ", strategy2.symbol);
|
|
63747
|
+
await notRunningCallback({
|
|
63748
|
+
symbol: strategy2.symbol,
|
|
63749
|
+
account: strategy2.expand.account,
|
|
63750
|
+
kind: strategy2.kind
|
|
63751
|
+
});
|
|
63752
|
+
}
|
|
63713
63753
|
}
|
|
63714
63754
|
async profitWithinGapStrategy(payload) {
|
|
63715
63755
|
const { account, symbol } = payload;
|
package/dist/index.d.ts
CHANGED
|
@@ -141,6 +141,7 @@ export interface PositionsView {
|
|
|
141
141
|
p_account?: ExchangeAccount;
|
|
142
142
|
b_config?: ScheduledTrade;
|
|
143
143
|
proxy?: Proxy$1;
|
|
144
|
+
account_strategy?: AccountStrategy;
|
|
144
145
|
};
|
|
145
146
|
}
|
|
146
147
|
export interface BullishMarket extends RecordModel {
|
|
@@ -240,6 +241,7 @@ export type GlobalConfig = {
|
|
|
240
241
|
risk_reward: number;
|
|
241
242
|
reverse_factor: number;
|
|
242
243
|
leverage?: number;
|
|
244
|
+
max_quantity?: number;
|
|
243
245
|
};
|
|
244
246
|
interface Position$1 {
|
|
245
247
|
id: number;
|
|
@@ -738,7 +740,7 @@ export declare class AppDatabase {
|
|
|
738
740
|
kind: "long" | "short";
|
|
739
741
|
account: ExchangeType;
|
|
740
742
|
}): Promise<ScheduledTrade | null>;
|
|
741
|
-
getRunningAccountStrategies(): Promise<(AccountStrategy & {
|
|
743
|
+
getRunningAccountStrategies(filter?: string): Promise<(AccountStrategy & {
|
|
742
744
|
expand?: {
|
|
743
745
|
account: ExchangeAccount;
|
|
744
746
|
};
|
|
@@ -2569,6 +2571,10 @@ declare class ExchangeAccount$1 {
|
|
|
2569
2571
|
long_percent: number;
|
|
2570
2572
|
short_percent: number;
|
|
2571
2573
|
}>;
|
|
2574
|
+
oppositeGapExists(payload: {
|
|
2575
|
+
symbol: string;
|
|
2576
|
+
kind: "long" | "short";
|
|
2577
|
+
}): Promise<void>;
|
|
2572
2578
|
profitWithinGapStrategy(payload: {
|
|
2573
2579
|
symbol: string;
|
|
2574
2580
|
}): Promise<{
|
|
@@ -2816,10 +2822,17 @@ declare class App {
|
|
|
2816
2822
|
cancel?: boolean;
|
|
2817
2823
|
raw?: boolean;
|
|
2818
2824
|
}): Promise<any>;
|
|
2819
|
-
runDbStrategyAccounts(
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2825
|
+
runDbStrategyAccounts(payload: {
|
|
2826
|
+
runningCallback: (params: {
|
|
2827
|
+
symbol: string;
|
|
2828
|
+
account: ExchangeType;
|
|
2829
|
+
}) => Promise<any>;
|
|
2830
|
+
notRunningCallback: (params: {
|
|
2831
|
+
symbol: string;
|
|
2832
|
+
account: ExchangeType;
|
|
2833
|
+
kind: "long" | "short";
|
|
2834
|
+
}) => Promise<any>;
|
|
2835
|
+
}): Promise<void>;
|
|
2823
2836
|
profitWithinGapStrategy(payload: {
|
|
2824
2837
|
account: ExchangeType;
|
|
2825
2838
|
symbol: string;
|
package/dist/index.js
CHANGED
|
@@ -55113,9 +55113,9 @@ class AppDatabase {
|
|
|
55113
55113
|
}
|
|
55114
55114
|
return null;
|
|
55115
55115
|
}
|
|
55116
|
-
async getRunningAccountStrategies() {
|
|
55116
|
+
async getRunningAccountStrategies(filter = "running=true") {
|
|
55117
55117
|
const result = await this.pb.collection("account_strategies").getFullList({
|
|
55118
|
-
filter
|
|
55118
|
+
filter,
|
|
55119
55119
|
expand: "account"
|
|
55120
55120
|
});
|
|
55121
55121
|
return result;
|
|
@@ -56880,7 +56880,8 @@ function get_app_config_and_max_size(config2, payload) {
|
|
|
56880
56880
|
price_places: config2.price_places,
|
|
56881
56881
|
decimal_places: config2.decimal_places,
|
|
56882
56882
|
min_profit: config2.profit_percent * config2.profit / 100,
|
|
56883
|
-
symbol: config2.symbol
|
|
56883
|
+
symbol: config2.symbol,
|
|
56884
|
+
max_quantity: config2.max_quantity
|
|
56884
56885
|
};
|
|
56885
56886
|
const initialResult = sortedBuildConfig(app_config, {
|
|
56886
56887
|
entry: app_config.entry,
|
|
@@ -60867,7 +60868,14 @@ class ExchangePosition {
|
|
|
60867
60868
|
place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
|
|
60868
60869
|
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
|
|
60869
60870
|
};
|
|
60870
|
-
return await this.app_db.createOrUpdatePositionConfig(
|
|
60871
|
+
return await this.app_db.createOrUpdatePositionConfig({
|
|
60872
|
+
...this.instance,
|
|
60873
|
+
expand: {
|
|
60874
|
+
...this.instance.expand || {},
|
|
60875
|
+
account: this.account
|
|
60876
|
+
},
|
|
60877
|
+
account: this.account.id
|
|
60878
|
+
}, params);
|
|
60871
60879
|
}
|
|
60872
60880
|
}
|
|
60873
60881
|
if (this.instance.expand?.b_config) {
|
|
@@ -61646,8 +61654,8 @@ class ExchangePosition {
|
|
|
61646
61654
|
});
|
|
61647
61655
|
return this.getConfig({
|
|
61648
61656
|
params: {
|
|
61649
|
-
entry:
|
|
61650
|
-
stop:
|
|
61657
|
+
entry: long_c.entry,
|
|
61658
|
+
stop: long_c.stop,
|
|
61651
61659
|
risk_reward: long_c.risk_reward,
|
|
61652
61660
|
risk: long_c.risk
|
|
61653
61661
|
}
|
|
@@ -63111,6 +63119,53 @@ class ExchangeAccount {
|
|
|
63111
63119
|
short_percent
|
|
63112
63120
|
};
|
|
63113
63121
|
}
|
|
63122
|
+
async oppositeGapExists(payload) {
|
|
63123
|
+
const focus_position = await this.getFocusPosition({
|
|
63124
|
+
symbol: payload.symbol,
|
|
63125
|
+
kind: payload.kind
|
|
63126
|
+
});
|
|
63127
|
+
const strategy2 = focus_position.getInstance().expand?.account_strategy;
|
|
63128
|
+
if (!strategy2) {
|
|
63129
|
+
return;
|
|
63130
|
+
}
|
|
63131
|
+
const kind = strategy2.kind;
|
|
63132
|
+
const reward_factor = strategy2.reward_factor;
|
|
63133
|
+
const { symbol } = payload;
|
|
63134
|
+
const reversePosition = await this.getFocusPosition({
|
|
63135
|
+
symbol,
|
|
63136
|
+
kind: kind === "long" ? "short" : "long"
|
|
63137
|
+
});
|
|
63138
|
+
if (focus_position.getInstance().quantity > 0) {
|
|
63139
|
+
const opposite_config = focus_position.getOppositeConfig({
|
|
63140
|
+
ratio: reward_factor
|
|
63141
|
+
});
|
|
63142
|
+
const reverse_config = await reversePosition.getConfig();
|
|
63143
|
+
if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
|
|
63144
|
+
console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
|
|
63145
|
+
await reversePosition.getConfig({
|
|
63146
|
+
params: {
|
|
63147
|
+
entry: opposite_config.entry,
|
|
63148
|
+
stop: opposite_config.stop,
|
|
63149
|
+
risk: opposite_config.risk,
|
|
63150
|
+
risk_reward: opposite_config.risk_reward
|
|
63151
|
+
}
|
|
63152
|
+
});
|
|
63153
|
+
console.log("Placing trade for ", symbol, reversePosition.kind);
|
|
63154
|
+
await reversePosition.placeTrade({
|
|
63155
|
+
ignore_config: true,
|
|
63156
|
+
limit: true,
|
|
63157
|
+
place: true
|
|
63158
|
+
});
|
|
63159
|
+
}
|
|
63160
|
+
console.log("Opposite config for ", symbol, kind, opposite_config);
|
|
63161
|
+
} else {
|
|
63162
|
+
if (focus_position.getInstance().avg_qty > 0 && strategy2.running === false) {
|
|
63163
|
+
await focus_position.cancelOrders({
|
|
63164
|
+
limit: true
|
|
63165
|
+
});
|
|
63166
|
+
}
|
|
63167
|
+
}
|
|
63168
|
+
}
|
|
63114
63169
|
async profitWithinGapStrategy(payload) {
|
|
63115
63170
|
const { symbol } = payload;
|
|
63116
63171
|
console.log("Fetching positions for ", symbol);
|
|
@@ -63127,7 +63182,6 @@ class ExchangeAccount {
|
|
|
63127
63182
|
return;
|
|
63128
63183
|
}
|
|
63129
63184
|
const kind = strategy2.kind;
|
|
63130
|
-
const reward_factor = strategy2.reward_factor;
|
|
63131
63185
|
const { entries, last_value, ...app_config } = await this.tradeConfig({
|
|
63132
63186
|
symbol,
|
|
63133
63187
|
kind
|
|
@@ -63155,34 +63209,10 @@ class ExchangeAccount {
|
|
|
63155
63209
|
});
|
|
63156
63210
|
}
|
|
63157
63211
|
console.log("Checking if focus position has quantity for ", symbol, kind);
|
|
63158
|
-
|
|
63212
|
+
await this.oppositeGapExists({
|
|
63159
63213
|
symbol,
|
|
63160
|
-
kind
|
|
63214
|
+
kind
|
|
63161
63215
|
});
|
|
63162
|
-
if (focusPosition.getInstance().quantity > 0) {
|
|
63163
|
-
const opposite_config = focusPosition.getOppositeConfig({
|
|
63164
|
-
ratio: reward_factor
|
|
63165
|
-
});
|
|
63166
|
-
const reverse_config = await reversePosition.getConfig();
|
|
63167
|
-
if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focusPosition.getInstance().quantity > 0) {
|
|
63168
|
-
console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
|
|
63169
|
-
await reversePosition.getConfig({
|
|
63170
|
-
params: {
|
|
63171
|
-
entry: opposite_config.entry,
|
|
63172
|
-
stop: opposite_config.stop,
|
|
63173
|
-
risk: opposite_config.risk,
|
|
63174
|
-
risk_reward: opposite_config.risk_reward
|
|
63175
|
-
}
|
|
63176
|
-
});
|
|
63177
|
-
console.log("Placing trade for ", symbol, reversePosition.kind);
|
|
63178
|
-
await reversePosition.placeTrade({
|
|
63179
|
-
ignore_config: true,
|
|
63180
|
-
limit: true,
|
|
63181
|
-
place: true
|
|
63182
|
-
});
|
|
63183
|
-
}
|
|
63184
|
-
console.log("Opposite config for ", symbol, kind, opposite_config);
|
|
63185
|
-
}
|
|
63186
63216
|
return {
|
|
63187
63217
|
config_details: {
|
|
63188
63218
|
app_config,
|
|
@@ -63647,15 +63677,25 @@ class App {
|
|
|
63647
63677
|
});
|
|
63648
63678
|
return result;
|
|
63649
63679
|
}
|
|
63650
|
-
async runDbStrategyAccounts(
|
|
63680
|
+
async runDbStrategyAccounts(payload) {
|
|
63681
|
+
const { runningCallback, notRunningCallback } = payload;
|
|
63651
63682
|
const strategies = await this.app_db.getRunningAccountStrategies();
|
|
63652
63683
|
for (const strategy2 of strategies) {
|
|
63653
63684
|
console.log("Running strategy for ", strategy2.symbol, "for account", strategy2.expand.account.owner, strategy2.expand.account.exchange);
|
|
63654
|
-
await
|
|
63685
|
+
await runningCallback({
|
|
63655
63686
|
symbol: strategy2.symbol,
|
|
63656
63687
|
account: strategy2.expand.account
|
|
63657
63688
|
});
|
|
63658
63689
|
}
|
|
63690
|
+
const not_running_strategies = await this.app_db.getRunningAccountStrategies("running=false");
|
|
63691
|
+
for (const strategy2 of not_running_strategies) {
|
|
63692
|
+
console.log("Not running strategy for ", strategy2.symbol);
|
|
63693
|
+
await notRunningCallback({
|
|
63694
|
+
symbol: strategy2.symbol,
|
|
63695
|
+
account: strategy2.expand.account,
|
|
63696
|
+
kind: strategy2.kind
|
|
63697
|
+
});
|
|
63698
|
+
}
|
|
63659
63699
|
}
|
|
63660
63700
|
async profitWithinGapStrategy(payload) {
|
|
63661
63701
|
const { account, symbol } = payload;
|
package/dist/mcp-server.cjs
CHANGED
|
@@ -61867,9 +61867,9 @@ class AppDatabase {
|
|
|
61867
61867
|
}
|
|
61868
61868
|
return null;
|
|
61869
61869
|
}
|
|
61870
|
-
async getRunningAccountStrategies() {
|
|
61870
|
+
async getRunningAccountStrategies(filter = "running=true") {
|
|
61871
61871
|
const result = await this.pb.collection("account_strategies").getFullList({
|
|
61872
|
-
filter
|
|
61872
|
+
filter,
|
|
61873
61873
|
expand: "account"
|
|
61874
61874
|
});
|
|
61875
61875
|
return result;
|
|
@@ -63614,7 +63614,8 @@ function get_app_config_and_max_size(config2, payload) {
|
|
|
63614
63614
|
price_places: config2.price_places,
|
|
63615
63615
|
decimal_places: config2.decimal_places,
|
|
63616
63616
|
min_profit: config2.profit_percent * config2.profit / 100,
|
|
63617
|
-
symbol: config2.symbol
|
|
63617
|
+
symbol: config2.symbol,
|
|
63618
|
+
max_quantity: config2.max_quantity
|
|
63618
63619
|
};
|
|
63619
63620
|
const initialResult = sortedBuildConfig(app_config, {
|
|
63620
63621
|
entry: app_config.entry,
|
|
@@ -67595,7 +67596,14 @@ class ExchangePosition {
|
|
|
67595
67596
|
place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
|
|
67596
67597
|
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
|
|
67597
67598
|
};
|
|
67598
|
-
return await this.app_db.createOrUpdatePositionConfig(
|
|
67599
|
+
return await this.app_db.createOrUpdatePositionConfig({
|
|
67600
|
+
...this.instance,
|
|
67601
|
+
expand: {
|
|
67602
|
+
...this.instance.expand || {},
|
|
67603
|
+
account: this.account
|
|
67604
|
+
},
|
|
67605
|
+
account: this.account.id
|
|
67606
|
+
}, params);
|
|
67599
67607
|
}
|
|
67600
67608
|
}
|
|
67601
67609
|
if (this.instance.expand?.b_config) {
|
|
@@ -68374,8 +68382,8 @@ class ExchangePosition {
|
|
|
68374
68382
|
});
|
|
68375
68383
|
return this.getConfig({
|
|
68376
68384
|
params: {
|
|
68377
|
-
entry:
|
|
68378
|
-
stop:
|
|
68385
|
+
entry: long_c.entry,
|
|
68386
|
+
stop: long_c.stop,
|
|
68379
68387
|
risk_reward: long_c.risk_reward,
|
|
68380
68388
|
risk: long_c.risk
|
|
68381
68389
|
}
|
|
@@ -69839,6 +69847,53 @@ class ExchangeAccount {
|
|
|
69839
69847
|
short_percent
|
|
69840
69848
|
};
|
|
69841
69849
|
}
|
|
69850
|
+
async oppositeGapExists(payload) {
|
|
69851
|
+
const focus_position = await this.getFocusPosition({
|
|
69852
|
+
symbol: payload.symbol,
|
|
69853
|
+
kind: payload.kind
|
|
69854
|
+
});
|
|
69855
|
+
const strategy2 = focus_position.getInstance().expand?.account_strategy;
|
|
69856
|
+
if (!strategy2) {
|
|
69857
|
+
return;
|
|
69858
|
+
}
|
|
69859
|
+
const kind = strategy2.kind;
|
|
69860
|
+
const reward_factor = strategy2.reward_factor;
|
|
69861
|
+
const { symbol } = payload;
|
|
69862
|
+
const reversePosition = await this.getFocusPosition({
|
|
69863
|
+
symbol,
|
|
69864
|
+
kind: kind === "long" ? "short" : "long"
|
|
69865
|
+
});
|
|
69866
|
+
if (focus_position.getInstance().quantity > 0) {
|
|
69867
|
+
const opposite_config = focus_position.getOppositeConfig({
|
|
69868
|
+
ratio: reward_factor
|
|
69869
|
+
});
|
|
69870
|
+
const reverse_config = await reversePosition.getConfig();
|
|
69871
|
+
if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
|
|
69872
|
+
console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
|
|
69873
|
+
await reversePosition.getConfig({
|
|
69874
|
+
params: {
|
|
69875
|
+
entry: opposite_config.entry,
|
|
69876
|
+
stop: opposite_config.stop,
|
|
69877
|
+
risk: opposite_config.risk,
|
|
69878
|
+
risk_reward: opposite_config.risk_reward
|
|
69879
|
+
}
|
|
69880
|
+
});
|
|
69881
|
+
console.log("Placing trade for ", symbol, reversePosition.kind);
|
|
69882
|
+
await reversePosition.placeTrade({
|
|
69883
|
+
ignore_config: true,
|
|
69884
|
+
limit: true,
|
|
69885
|
+
place: true
|
|
69886
|
+
});
|
|
69887
|
+
}
|
|
69888
|
+
console.log("Opposite config for ", symbol, kind, opposite_config);
|
|
69889
|
+
} else {
|
|
69890
|
+
if (focus_position.getInstance().avg_qty > 0 && strategy2.running === false) {
|
|
69891
|
+
await focus_position.cancelOrders({
|
|
69892
|
+
limit: true
|
|
69893
|
+
});
|
|
69894
|
+
}
|
|
69895
|
+
}
|
|
69896
|
+
}
|
|
69842
69897
|
async profitWithinGapStrategy(payload) {
|
|
69843
69898
|
const { symbol } = payload;
|
|
69844
69899
|
console.log("Fetching positions for ", symbol);
|
|
@@ -69855,7 +69910,6 @@ class ExchangeAccount {
|
|
|
69855
69910
|
return;
|
|
69856
69911
|
}
|
|
69857
69912
|
const kind = strategy2.kind;
|
|
69858
|
-
const reward_factor = strategy2.reward_factor;
|
|
69859
69913
|
const { entries, last_value, ...app_config } = await this.tradeConfig({
|
|
69860
69914
|
symbol,
|
|
69861
69915
|
kind
|
|
@@ -69883,34 +69937,10 @@ class ExchangeAccount {
|
|
|
69883
69937
|
});
|
|
69884
69938
|
}
|
|
69885
69939
|
console.log("Checking if focus position has quantity for ", symbol, kind);
|
|
69886
|
-
|
|
69940
|
+
await this.oppositeGapExists({
|
|
69887
69941
|
symbol,
|
|
69888
|
-
kind
|
|
69942
|
+
kind
|
|
69889
69943
|
});
|
|
69890
|
-
if (focusPosition.getInstance().quantity > 0) {
|
|
69891
|
-
const opposite_config = focusPosition.getOppositeConfig({
|
|
69892
|
-
ratio: reward_factor
|
|
69893
|
-
});
|
|
69894
|
-
const reverse_config = await reversePosition.getConfig();
|
|
69895
|
-
if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focusPosition.getInstance().quantity > 0) {
|
|
69896
|
-
console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
|
|
69897
|
-
await reversePosition.getConfig({
|
|
69898
|
-
params: {
|
|
69899
|
-
entry: opposite_config.entry,
|
|
69900
|
-
stop: opposite_config.stop,
|
|
69901
|
-
risk: opposite_config.risk,
|
|
69902
|
-
risk_reward: opposite_config.risk_reward
|
|
69903
|
-
}
|
|
69904
|
-
});
|
|
69905
|
-
console.log("Placing trade for ", symbol, reversePosition.kind);
|
|
69906
|
-
await reversePosition.placeTrade({
|
|
69907
|
-
ignore_config: true,
|
|
69908
|
-
limit: true,
|
|
69909
|
-
place: true
|
|
69910
|
-
});
|
|
69911
|
-
}
|
|
69912
|
-
console.log("Opposite config for ", symbol, kind, opposite_config);
|
|
69913
|
-
}
|
|
69914
69944
|
return {
|
|
69915
69945
|
config_details: {
|
|
69916
69946
|
app_config,
|
|
@@ -70375,15 +70405,25 @@ class App {
|
|
|
70375
70405
|
});
|
|
70376
70406
|
return result;
|
|
70377
70407
|
}
|
|
70378
|
-
async runDbStrategyAccounts(
|
|
70408
|
+
async runDbStrategyAccounts(payload) {
|
|
70409
|
+
const { runningCallback, notRunningCallback } = payload;
|
|
70379
70410
|
const strategies = await this.app_db.getRunningAccountStrategies();
|
|
70380
70411
|
for (const strategy2 of strategies) {
|
|
70381
70412
|
console.log("Running strategy for ", strategy2.symbol, "for account", strategy2.expand.account.owner, strategy2.expand.account.exchange);
|
|
70382
|
-
await
|
|
70413
|
+
await runningCallback({
|
|
70383
70414
|
symbol: strategy2.symbol,
|
|
70384
70415
|
account: strategy2.expand.account
|
|
70385
70416
|
});
|
|
70386
70417
|
}
|
|
70418
|
+
const not_running_strategies = await this.app_db.getRunningAccountStrategies("running=false");
|
|
70419
|
+
for (const strategy2 of not_running_strategies) {
|
|
70420
|
+
console.log("Not running strategy for ", strategy2.symbol);
|
|
70421
|
+
await notRunningCallback({
|
|
70422
|
+
symbol: strategy2.symbol,
|
|
70423
|
+
account: strategy2.expand.account,
|
|
70424
|
+
kind: strategy2.kind
|
|
70425
|
+
});
|
|
70426
|
+
}
|
|
70387
70427
|
}
|
|
70388
70428
|
async profitWithinGapStrategy(payload) {
|
|
70389
70429
|
const { account, symbol } = payload;
|
package/dist/mcp-server.js
CHANGED
|
@@ -61844,9 +61844,9 @@ class AppDatabase {
|
|
|
61844
61844
|
}
|
|
61845
61845
|
return null;
|
|
61846
61846
|
}
|
|
61847
|
-
async getRunningAccountStrategies() {
|
|
61847
|
+
async getRunningAccountStrategies(filter = "running=true") {
|
|
61848
61848
|
const result = await this.pb.collection("account_strategies").getFullList({
|
|
61849
|
-
filter
|
|
61849
|
+
filter,
|
|
61850
61850
|
expand: "account"
|
|
61851
61851
|
});
|
|
61852
61852
|
return result;
|
|
@@ -63591,7 +63591,8 @@ function get_app_config_and_max_size(config2, payload) {
|
|
|
63591
63591
|
price_places: config2.price_places,
|
|
63592
63592
|
decimal_places: config2.decimal_places,
|
|
63593
63593
|
min_profit: config2.profit_percent * config2.profit / 100,
|
|
63594
|
-
symbol: config2.symbol
|
|
63594
|
+
symbol: config2.symbol,
|
|
63595
|
+
max_quantity: config2.max_quantity
|
|
63595
63596
|
};
|
|
63596
63597
|
const initialResult = sortedBuildConfig(app_config, {
|
|
63597
63598
|
entry: app_config.entry,
|
|
@@ -67572,7 +67573,14 @@ class ExchangePosition {
|
|
|
67572
67573
|
place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
|
|
67573
67574
|
profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
|
|
67574
67575
|
};
|
|
67575
|
-
return await this.app_db.createOrUpdatePositionConfig(
|
|
67576
|
+
return await this.app_db.createOrUpdatePositionConfig({
|
|
67577
|
+
...this.instance,
|
|
67578
|
+
expand: {
|
|
67579
|
+
...this.instance.expand || {},
|
|
67580
|
+
account: this.account
|
|
67581
|
+
},
|
|
67582
|
+
account: this.account.id
|
|
67583
|
+
}, params);
|
|
67576
67584
|
}
|
|
67577
67585
|
}
|
|
67578
67586
|
if (this.instance.expand?.b_config) {
|
|
@@ -68351,8 +68359,8 @@ class ExchangePosition {
|
|
|
68351
68359
|
});
|
|
68352
68360
|
return this.getConfig({
|
|
68353
68361
|
params: {
|
|
68354
|
-
entry:
|
|
68355
|
-
stop:
|
|
68362
|
+
entry: long_c.entry,
|
|
68363
|
+
stop: long_c.stop,
|
|
68356
68364
|
risk_reward: long_c.risk_reward,
|
|
68357
68365
|
risk: long_c.risk
|
|
68358
68366
|
}
|
|
@@ -69816,6 +69824,53 @@ class ExchangeAccount {
|
|
|
69816
69824
|
short_percent
|
|
69817
69825
|
};
|
|
69818
69826
|
}
|
|
69827
|
+
async oppositeGapExists(payload) {
|
|
69828
|
+
const focus_position = await this.getFocusPosition({
|
|
69829
|
+
symbol: payload.symbol,
|
|
69830
|
+
kind: payload.kind
|
|
69831
|
+
});
|
|
69832
|
+
const strategy2 = focus_position.getInstance().expand?.account_strategy;
|
|
69833
|
+
if (!strategy2) {
|
|
69834
|
+
return;
|
|
69835
|
+
}
|
|
69836
|
+
const kind = strategy2.kind;
|
|
69837
|
+
const reward_factor = strategy2.reward_factor;
|
|
69838
|
+
const { symbol } = payload;
|
|
69839
|
+
const reversePosition = await this.getFocusPosition({
|
|
69840
|
+
symbol,
|
|
69841
|
+
kind: kind === "long" ? "short" : "long"
|
|
69842
|
+
});
|
|
69843
|
+
if (focus_position.getInstance().quantity > 0) {
|
|
69844
|
+
const opposite_config = focus_position.getOppositeConfig({
|
|
69845
|
+
ratio: reward_factor
|
|
69846
|
+
});
|
|
69847
|
+
const reverse_config = await reversePosition.getConfig();
|
|
69848
|
+
if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
|
|
69849
|
+
console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
|
|
69850
|
+
await reversePosition.getConfig({
|
|
69851
|
+
params: {
|
|
69852
|
+
entry: opposite_config.entry,
|
|
69853
|
+
stop: opposite_config.stop,
|
|
69854
|
+
risk: opposite_config.risk,
|
|
69855
|
+
risk_reward: opposite_config.risk_reward
|
|
69856
|
+
}
|
|
69857
|
+
});
|
|
69858
|
+
console.log("Placing trade for ", symbol, reversePosition.kind);
|
|
69859
|
+
await reversePosition.placeTrade({
|
|
69860
|
+
ignore_config: true,
|
|
69861
|
+
limit: true,
|
|
69862
|
+
place: true
|
|
69863
|
+
});
|
|
69864
|
+
}
|
|
69865
|
+
console.log("Opposite config for ", symbol, kind, opposite_config);
|
|
69866
|
+
} else {
|
|
69867
|
+
if (focus_position.getInstance().avg_qty > 0 && strategy2.running === false) {
|
|
69868
|
+
await focus_position.cancelOrders({
|
|
69869
|
+
limit: true
|
|
69870
|
+
});
|
|
69871
|
+
}
|
|
69872
|
+
}
|
|
69873
|
+
}
|
|
69819
69874
|
async profitWithinGapStrategy(payload) {
|
|
69820
69875
|
const { symbol } = payload;
|
|
69821
69876
|
console.log("Fetching positions for ", symbol);
|
|
@@ -69832,7 +69887,6 @@ class ExchangeAccount {
|
|
|
69832
69887
|
return;
|
|
69833
69888
|
}
|
|
69834
69889
|
const kind = strategy2.kind;
|
|
69835
|
-
const reward_factor = strategy2.reward_factor;
|
|
69836
69890
|
const { entries, last_value, ...app_config } = await this.tradeConfig({
|
|
69837
69891
|
symbol,
|
|
69838
69892
|
kind
|
|
@@ -69860,34 +69914,10 @@ class ExchangeAccount {
|
|
|
69860
69914
|
});
|
|
69861
69915
|
}
|
|
69862
69916
|
console.log("Checking if focus position has quantity for ", symbol, kind);
|
|
69863
|
-
|
|
69917
|
+
await this.oppositeGapExists({
|
|
69864
69918
|
symbol,
|
|
69865
|
-
kind
|
|
69919
|
+
kind
|
|
69866
69920
|
});
|
|
69867
|
-
if (focusPosition.getInstance().quantity > 0) {
|
|
69868
|
-
const opposite_config = focusPosition.getOppositeConfig({
|
|
69869
|
-
ratio: reward_factor
|
|
69870
|
-
});
|
|
69871
|
-
const reverse_config = await reversePosition.getConfig();
|
|
69872
|
-
if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focusPosition.getInstance().quantity > 0) {
|
|
69873
|
-
console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
|
|
69874
|
-
await reversePosition.getConfig({
|
|
69875
|
-
params: {
|
|
69876
|
-
entry: opposite_config.entry,
|
|
69877
|
-
stop: opposite_config.stop,
|
|
69878
|
-
risk: opposite_config.risk,
|
|
69879
|
-
risk_reward: opposite_config.risk_reward
|
|
69880
|
-
}
|
|
69881
|
-
});
|
|
69882
|
-
console.log("Placing trade for ", symbol, reversePosition.kind);
|
|
69883
|
-
await reversePosition.placeTrade({
|
|
69884
|
-
ignore_config: true,
|
|
69885
|
-
limit: true,
|
|
69886
|
-
place: true
|
|
69887
|
-
});
|
|
69888
|
-
}
|
|
69889
|
-
console.log("Opposite config for ", symbol, kind, opposite_config);
|
|
69890
|
-
}
|
|
69891
69921
|
return {
|
|
69892
69922
|
config_details: {
|
|
69893
69923
|
app_config,
|
|
@@ -70352,15 +70382,25 @@ class App {
|
|
|
70352
70382
|
});
|
|
70353
70383
|
return result;
|
|
70354
70384
|
}
|
|
70355
|
-
async runDbStrategyAccounts(
|
|
70385
|
+
async runDbStrategyAccounts(payload) {
|
|
70386
|
+
const { runningCallback, notRunningCallback } = payload;
|
|
70356
70387
|
const strategies = await this.app_db.getRunningAccountStrategies();
|
|
70357
70388
|
for (const strategy2 of strategies) {
|
|
70358
70389
|
console.log("Running strategy for ", strategy2.symbol, "for account", strategy2.expand.account.owner, strategy2.expand.account.exchange);
|
|
70359
|
-
await
|
|
70390
|
+
await runningCallback({
|
|
70360
70391
|
symbol: strategy2.symbol,
|
|
70361
70392
|
account: strategy2.expand.account
|
|
70362
70393
|
});
|
|
70363
70394
|
}
|
|
70395
|
+
const not_running_strategies = await this.app_db.getRunningAccountStrategies("running=false");
|
|
70396
|
+
for (const strategy2 of not_running_strategies) {
|
|
70397
|
+
console.log("Not running strategy for ", strategy2.symbol);
|
|
70398
|
+
await notRunningCallback({
|
|
70399
|
+
symbol: strategy2.symbol,
|
|
70400
|
+
account: strategy2.expand.account,
|
|
70401
|
+
kind: strategy2.kind
|
|
70402
|
+
});
|
|
70403
|
+
}
|
|
70364
70404
|
}
|
|
70365
70405
|
async profitWithinGapStrategy(payload) {
|
|
70366
70406
|
const { account, symbol } = payload;
|