@gbozee/ultimate 0.0.2-200 → 0.0.2-201

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.
@@ -62809,7 +62809,6 @@ class Signal {
62809
62809
  let potentials = new_result.filter((x) => condition(x["entry"], i2["risk_sell"])).map((x) => x["entry"]);
62810
62810
  if (potentials.length && max_index) {
62811
62811
  if (kind === "long") {
62812
- console.log("slice: ", potentials.slice(0, max_index));
62813
62812
  i2["risk_sell"] = Math.max(...potentials.slice(0, max_index));
62814
62813
  } else {
62815
62814
  i2["risk_sell"] = Math.min(...potentials.slice(0, max_index));
@@ -62873,7 +62872,6 @@ class Signal {
62873
62872
  }) {
62874
62873
  const margin_zones = [this.support, this.resistance];
62875
62874
  const distribution = this.distribution ? this.distribution[kind] : "geometric";
62876
- console.log("margin_zones", { margin_zones, distribution });
62877
62875
  let _kind = distribution === "inverse-exponential" ? kind === "long" ? "short" : "long" : kind;
62878
62876
  const entries = distributions_default({
62879
62877
  margin_range: margin_zones,
@@ -63092,7 +63090,6 @@ class Signal {
63092
63090
  }
63093
63091
  });
63094
63092
  risk_to_use = theoretical_kelly * risk_per_trade / this.kelly_minimum_risk;
63095
- console.log({ risk_per_trade, theoretical_kelly });
63096
63093
  }
63097
63094
  const y = this.build_trade_dict({
63098
63095
  entry: x,
@@ -63592,7 +63589,6 @@ function buildConfig(app_config, {
63592
63589
  }
63593
63590
  const condition = (kind === "long" ? entry > app_config.support : entry >= app_config.support) && stop >= app_config.support * 0.999;
63594
63591
  if (kind === "short") {}
63595
- console.log({ entry, stop, condition, working_risk, config: config2 });
63596
63592
  const result = entry === stop ? [] : condition ? instance.build_entry({
63597
63593
  current_price: entry,
63598
63594
  stop_loss: stop,
@@ -65170,6 +65166,419 @@ class Strategy {
65170
65166
  };
65171
65167
  }
65172
65168
  }
65169
+ // src/helpers/compound.ts
65170
+ function buildTrades(payload) {
65171
+ const { appConfig, settings, kind } = payload;
65172
+ const kelly_config = settings.kelly;
65173
+ const current_app_config = { ...appConfig[kind] };
65174
+ const entryNum = parseFloat(settings.entry);
65175
+ const stopNum = parseFloat(settings.stop);
65176
+ current_app_config.entry = entryNum;
65177
+ current_app_config.stop = stopNum;
65178
+ current_app_config.risk_per_trade = parseFloat(settings.risk);
65179
+ current_app_config.risk_reward = parseFloat(settings.risk_reward);
65180
+ current_app_config.kind = kind;
65181
+ current_app_config.kelly = kelly_config;
65182
+ const options = {
65183
+ take_profit: null,
65184
+ entry: current_app_config.entry,
65185
+ stop: current_app_config.stop,
65186
+ raw_instance: null,
65187
+ risk: current_app_config.risk_per_trade,
65188
+ no_of_trades: undefined,
65189
+ risk_reward: current_app_config.risk_reward,
65190
+ kind: current_app_config.kind,
65191
+ increase: true,
65192
+ gap: current_app_config.gap,
65193
+ rr: current_app_config.rr,
65194
+ price_places: current_app_config.price_places,
65195
+ decimal_places: current_app_config.decimal_places,
65196
+ use_kelly: kelly_config?.use_kelly,
65197
+ kelly_confidence_factor: kelly_config?.kelly_confidence_factor,
65198
+ kelly_minimum_risk: kelly_config?.kelly_minimum_risk,
65199
+ kelly_prediction_model: kelly_config?.kelly_prediction_model,
65200
+ kelly_func: kelly_config?.kelly_func,
65201
+ distribution: settings.distribution
65202
+ };
65203
+ if (kind === "long" && entryNum <= stopNum) {
65204
+ return [];
65205
+ }
65206
+ if (kind === "short" && entryNum >= stopNum) {
65207
+ return [];
65208
+ }
65209
+ try {
65210
+ const generatedTrades = sortedBuildConfig(current_app_config, options);
65211
+ return generatedTrades ?? [];
65212
+ } catch (error) {
65213
+ console.error("Error generating orders:", error);
65214
+ return [];
65215
+ }
65216
+ }
65217
+ function generateSummary({
65218
+ trades,
65219
+ fee_percent = 0.05,
65220
+ anchor
65221
+ }) {
65222
+ const avg_entry = trades[0].avg_entry;
65223
+ const avg_size = trades[0].avg_size;
65224
+ const expected_fee = avg_entry * avg_size * fee_percent / 100;
65225
+ return {
65226
+ first_entry: trades.at(-1).entry,
65227
+ last_entry: trades[0].entry,
65228
+ quantity: avg_size,
65229
+ entry: avg_entry,
65230
+ loss: trades[0].neg_pnl,
65231
+ number_of_trades: trades.length,
65232
+ fee: to_f(expected_fee, "%.2f"),
65233
+ anchor_pnl: anchor?.target_pnl
65234
+ };
65235
+ }
65236
+ function helperFuncToBuildTrades({
65237
+ custom_b_config,
65238
+ symbol_config,
65239
+ app_config_kind,
65240
+ appConfig,
65241
+ force_exact_risk = true
65242
+ }) {
65243
+ const risk = custom_b_config.risk * (custom_b_config.risk_factor || 1);
65244
+ let result = getRiskReward({
65245
+ entry: custom_b_config.entry,
65246
+ stop: custom_b_config.stop,
65247
+ risk,
65248
+ global_config: symbol_config,
65249
+ force_exact_risk,
65250
+ target_loss: custom_b_config.risk * (custom_b_config.risk_factor || 1),
65251
+ distribution: custom_b_config.distribution
65252
+ });
65253
+ if (!force_exact_risk) {
65254
+ result = {
65255
+ risk_reward: result,
65256
+ risk
65257
+ };
65258
+ }
65259
+ const trades = result.risk_reward ? buildTrades({
65260
+ appConfig: { [app_config_kind]: appConfig },
65261
+ kind: app_config_kind,
65262
+ settings: {
65263
+ entry: custom_b_config.entry,
65264
+ stop: custom_b_config.stop,
65265
+ risk: result.risk || custom_b_config.risk,
65266
+ risk_reward: result.risk_reward,
65267
+ distribution: custom_b_config.distribution
65268
+ }
65269
+ }) : [];
65270
+ const summary = trades.length > 0 ? generateSummary({ trades }) : {};
65271
+ return { trades, result, summary };
65272
+ }
65273
+ function constructAppConfig2({
65274
+ config: config2,
65275
+ global_config
65276
+ }) {
65277
+ const options = {
65278
+ entry: config2?.entry,
65279
+ stop: config2?.stop,
65280
+ risk_reward: config2?.risk_reward,
65281
+ risk: config2?.risk,
65282
+ symbol: config2.symbol
65283
+ };
65284
+ const { entries: _entries, ...appConfig } = buildAppConfig(global_config, options);
65285
+ return appConfig;
65286
+ }
65287
+ function buildWithOptimumReward({
65288
+ config: config2,
65289
+ settings,
65290
+ global_config
65291
+ }) {
65292
+ const kind = config2.entry > config2.stop ? "long" : "short";
65293
+ let stop = settings.stop;
65294
+ let entry = settings.entry;
65295
+ const risk = settings.risk;
65296
+ const stop_ratio = settings.stop_ratio || 1;
65297
+ const distribution = settings.distribution || config2?.distribution;
65298
+ const custom_b_config = {
65299
+ entry,
65300
+ stop,
65301
+ risk,
65302
+ distribution
65303
+ };
65304
+ const appConfig = constructAppConfig2({
65305
+ config: config2,
65306
+ global_config
65307
+ });
65308
+ const { trades, summary, result } = helperFuncToBuildTrades({
65309
+ custom_b_config,
65310
+ app_config_kind: kind,
65311
+ appConfig,
65312
+ symbol_config: global_config
65313
+ });
65314
+ const adjusted_size = summary.quantity;
65315
+ const symbol_config = global_config;
65316
+ const entryDetails = {
65317
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
65318
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
65319
+ risk: to_f(result.risk, "%.2f"),
65320
+ risk_reward: result.risk_reward,
65321
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
65322
+ avg_size: to_f(adjusted_size, symbol_config.decimal_places),
65323
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
65324
+ pnl: to_f(custom_b_config.risk, "%.2f"),
65325
+ fee: to_f(summary.fee, "%.2f"),
65326
+ loss: to_f(summary.loss, "%.2f"),
65327
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
65328
+ margin: to_f(summary.entry * adjusted_size / symbol_config.leverage, "%.2f")
65329
+ };
65330
+ return {
65331
+ trades,
65332
+ summary: entryDetails,
65333
+ config: {
65334
+ ...custom_b_config,
65335
+ ...result,
65336
+ stop_ratio
65337
+ },
65338
+ stop_order: {
65339
+ quantity: entryDetails.avg_size * stop_ratio,
65340
+ price: entryDetails.stop
65341
+ },
65342
+ kind
65343
+ };
65344
+ }
65345
+ function generateOppositeOptimum({
65346
+ config: config2,
65347
+ global_config,
65348
+ settings,
65349
+ ratio = 1,
65350
+ distribution,
65351
+ risk_factor = 1
65352
+ }) {
65353
+ const configKind = config2.entry > config2.stop ? "long" : "short";
65354
+ if (configKind === "long" && config2.entry > config2.stop) {
65355
+ if (settings.stop <= settings.entry) {
65356
+ throw new Error("Invalid input: For long config positions, opposite settings must have stop > entry");
65357
+ }
65358
+ } else if (configKind === "short" && config2.entry < config2.stop) {
65359
+ if (settings.stop >= settings.entry) {
65360
+ throw new Error("Invalid input: For short config positions, opposite settings must have stop < entry");
65361
+ }
65362
+ }
65363
+ const kind = config2.entry > config2.stop ? "long" : "short";
65364
+ const app_config_kind = kind === "long" ? "short" : "long";
65365
+ let risk = settings.risk;
65366
+ const custom_b_config = {
65367
+ entry: settings.entry,
65368
+ stop: settings.stop,
65369
+ risk: risk * ratio,
65370
+ distribution: distribution || "inverse-exponential",
65371
+ risk_factor
65372
+ };
65373
+ const appConfig = constructAppConfig2({
65374
+ config: {
65375
+ ...config2,
65376
+ ...custom_b_config
65377
+ },
65378
+ global_config
65379
+ });
65380
+ const { result, trades, summary } = helperFuncToBuildTrades({
65381
+ custom_b_config,
65382
+ symbol_config: global_config,
65383
+ app_config_kind,
65384
+ appConfig
65385
+ });
65386
+ if (Object.keys(summary).length === 0) {
65387
+ return {
65388
+ trades,
65389
+ summary,
65390
+ config: custom_b_config,
65391
+ kind: app_config_kind
65392
+ };
65393
+ }
65394
+ const symbol_config = global_config;
65395
+ const entryDetails = {
65396
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
65397
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
65398
+ risk: to_f(result.risk, "%.2f"),
65399
+ risk_reward: result.risk_reward,
65400
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
65401
+ avg_size: to_f(summary.quantity, symbol_config.decimal_places),
65402
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
65403
+ pnl: to_f(custom_b_config.risk, "%.2f"),
65404
+ fee: to_f(summary.fee, "%.2f"),
65405
+ loss: to_f(summary.loss, "%.2f"),
65406
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
65407
+ defaultEntry: settings.entry ? to_f(settings.entry, symbol_config.price_places) : null
65408
+ };
65409
+ return {
65410
+ trades,
65411
+ summary: entryDetails,
65412
+ config: {
65413
+ ...custom_b_config,
65414
+ ...result
65415
+ },
65416
+ kind: app_config_kind
65417
+ };
65418
+ }
65419
+ function defaultTradeFromCurrentState({
65420
+ config: config2,
65421
+ global_config
65422
+ }) {
65423
+ const kind = config2.entry > config2.stop ? "long" : "short";
65424
+ const settings = {
65425
+ entry: config2?.entry,
65426
+ stop: config2?.stop,
65427
+ risk: config2?.risk,
65428
+ distribution: config2?.distribution,
65429
+ risk_reward: config2?.risk_reward
65430
+ };
65431
+ const appConfig = constructAppConfig2({
65432
+ config: config2,
65433
+ global_config
65434
+ });
65435
+ const trades = buildTrades({
65436
+ appConfig: { [kind]: appConfig },
65437
+ kind,
65438
+ settings
65439
+ });
65440
+ return {
65441
+ trades,
65442
+ summary: generateSummary({
65443
+ trades,
65444
+ fee_percent: global_config.fee_percent
65445
+ })
65446
+ };
65447
+ }
65448
+ function increaseTradeHelper({
65449
+ increase_qty,
65450
+ stop,
65451
+ config: config2,
65452
+ global_config,
65453
+ style,
65454
+ entry,
65455
+ position: position2,
65456
+ stop_ratio = 1,
65457
+ distribution: default_distribution
65458
+ }) {
65459
+ const symbol_config = global_config;
65460
+ const kind = config2.entry > config2.stop ? "long" : "short";
65461
+ const distribution = default_distribution || config2.distribution || "inverse-exponential";
65462
+ const appConfig = constructAppConfig2({
65463
+ config: config2,
65464
+ global_config
65465
+ });
65466
+ const currentState = defaultTradeFromCurrentState({
65467
+ config: config2,
65468
+ global_config
65469
+ });
65470
+ const { optimal_risk, neg_pnl } = getOptimumStopAndRisk(appConfig, {
65471
+ max_size: increase_qty,
65472
+ target_stop: stop,
65473
+ distribution
65474
+ });
65475
+ if (neg_pnl === 0) {
65476
+ return {
65477
+ trades: [],
65478
+ summary: {},
65479
+ config: {},
65480
+ kind,
65481
+ current: currentState
65482
+ };
65483
+ }
65484
+ const custom_b_config = {
65485
+ entry,
65486
+ stop,
65487
+ risk: style === "minimum" ? Math.abs(neg_pnl) : optimal_risk,
65488
+ distribution
65489
+ };
65490
+ const { result, trades, summary } = helperFuncToBuildTrades({
65491
+ custom_b_config,
65492
+ symbol_config,
65493
+ appConfig,
65494
+ app_config_kind: kind
65495
+ });
65496
+ if (Object.keys(summary).length === 0) {
65497
+ return {
65498
+ trades,
65499
+ summary,
65500
+ config: {
65501
+ ...custom_b_config,
65502
+ ...result
65503
+ },
65504
+ kind,
65505
+ current: currentState
65506
+ };
65507
+ }
65508
+ const new_avg_values = determine_average_entry_and_size([
65509
+ {
65510
+ price: position2.entry,
65511
+ quantity: position2.quantity
65512
+ },
65513
+ {
65514
+ price: summary?.entry,
65515
+ quantity: summary?.quantity
65516
+ }
65517
+ ], symbol_config.decimal_places, symbol_config.price_places);
65518
+ summary.entry = new_avg_values.entry;
65519
+ summary.quantity = new_avg_values.quantity;
65520
+ const loss = Math.abs(summary.entry - custom_b_config.stop) * summary.quantity;
65521
+ const entryDetails = {
65522
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
65523
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
65524
+ risk: to_f(result.risk, symbol_config.price_places),
65525
+ risk_reward: result.risk_reward,
65526
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
65527
+ avg_size: to_f(summary.quantity, symbol_config.decimal_places),
65528
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
65529
+ pnl: to_f(custom_b_config.risk, "%.2f"),
65530
+ fee: to_f(summary.fee, "%.2f"),
65531
+ loss: to_f(loss, "%.2f"),
65532
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
65533
+ margin: to_f(summary.entry * summary.quantity / global_config.leverage, "%.2f")
65534
+ };
65535
+ return {
65536
+ trades,
65537
+ summary: entryDetails,
65538
+ stop_order: {
65539
+ quantity: entryDetails.avg_size * stop_ratio,
65540
+ price: entryDetails.stop
65541
+ },
65542
+ config: {
65543
+ ...custom_b_config,
65544
+ ...result
65545
+ },
65546
+ kind,
65547
+ current: currentState
65548
+ };
65549
+ }
65550
+ function generatePositionIncreaseTrade({
65551
+ account,
65552
+ zoneAccount,
65553
+ ratio = 0.1,
65554
+ config: config2,
65555
+ global_config,
65556
+ style = "minimum",
65557
+ distribution = "inverse-exponential"
65558
+ }) {
65559
+ const kind = config2.entry > config2.stop ? "long" : "short";
65560
+ const target_max_quantity = kind === "long" ? account.short.quantity : account.long.quantity;
65561
+ const increase_qty = target_max_quantity * ratio;
65562
+ const entry = zoneAccount.entry;
65563
+ const stop = zoneAccount.stop;
65564
+ return increaseTradeHelper({
65565
+ config: config2,
65566
+ position: account[kind],
65567
+ global_config,
65568
+ entry,
65569
+ stop,
65570
+ style,
65571
+ increase_qty,
65572
+ distribution
65573
+ });
65574
+ }
65575
+ var compoundAPI = {
65576
+ buildWithOptimumReward,
65577
+ constructAppConfig: constructAppConfig2,
65578
+ generateOppositeOptimum,
65579
+ increaseTradeHelper,
65580
+ generatePositionIncreaseTrade
65581
+ };
65173
65582
  // src/types/index.ts
65174
65583
  class BaseExchange {
65175
65584
  client;
@@ -71539,6 +71948,324 @@ server.tool("fetch_exchange_details", "Fetch exchange details for a symbol with
71539
71948
  };
71540
71949
  }
71541
71950
  });
71951
+ server.tool("buildWithOptimumReward", "Create trades with optimal risk/reward ratios. Calculates the best entry, stop, and take profit levels based on market conditions and risk parameters, including margin calculations.", {
71952
+ config: z.object({
71953
+ entry: z.number().optional().describe("Entry price"),
71954
+ stop: z.number().optional().describe("Stop loss price"),
71955
+ risk_reward: z.number().optional().describe("Risk to reward ratio"),
71956
+ risk: z.number().optional().describe("Risk amount"),
71957
+ symbol: z.string().optional().describe("Trading symbol"),
71958
+ distribution: z.enum(["arithmetic", "geometric", "normal", "exponential", "inverse-exponential"]).optional().describe("Distribution type")
71959
+ }).optional().describe("Base trading configuration"),
71960
+ global_config: z.object({
71961
+ profit_percent: z.number().optional().describe("Profit percentage target"),
71962
+ symbol: z.string().optional().describe("Trading symbol"),
71963
+ profit: z.number().optional().describe("Target profit amount"),
71964
+ risk: z.number().optional().describe("Risk amount"),
71965
+ stop_percent: z.number().optional().describe("Stop loss percentage"),
71966
+ kind: z.enum(["long", "short"]).optional().describe("Position direction"),
71967
+ reduce_percent: z.number().optional().describe("Position reduction percentage"),
71968
+ support: z.number().optional().describe("Support price level"),
71969
+ resistance: z.number().optional().describe("Resistance price level"),
71970
+ price_places: z.string().optional().describe("Price decimal format"),
71971
+ decimal_places: z.string().optional().describe("Quantity decimal format"),
71972
+ min_size: z.number().optional().describe("Minimum trade size"),
71973
+ accounts: z.array(z.object({
71974
+ owner: z.string().optional().describe("Account owner"),
71975
+ exchange: z.string().optional().describe("Exchange name")
71976
+ })).optional().describe("Trading accounts"),
71977
+ risk_reward: z.number().optional().describe("Risk to reward ratio"),
71978
+ reverse_factor: z.number().optional().describe("Reverse factor for calculations"),
71979
+ leverage: z.number().optional().describe("Leverage multiplier"),
71980
+ max_quantity: z.number().optional().describe("Maximum quantity"),
71981
+ fee_percent: z.number().optional().describe("Trading fee percentage")
71982
+ }).optional().describe("Global configuration parameters"),
71983
+ settings: z.object({
71984
+ entry: z.number().optional().describe("Override entry price"),
71985
+ stop: z.number().optional().describe("Override stop price"),
71986
+ risk: z.number().optional().describe("Risk amount for this trade"),
71987
+ stop_ratio: z.number().optional().describe("Stop order quantity ratio"),
71988
+ risk_reward: z.number().optional().describe("Override risk/reward ratio"),
71989
+ distribution: z.enum(["arithmetic", "geometric", "normal", "exponential", "inverse-exponential"]).optional().describe("Distribution type")
71990
+ }).optional().describe("Trade-specific settings")
71991
+ }, async (args) => {
71992
+ try {
71993
+ const result = compoundAPI.buildWithOptimumReward(args);
71994
+ return {
71995
+ content: [
71996
+ {
71997
+ type: "text",
71998
+ text: `Optimum reward trade generated: ${JSON.stringify(result, null, 2)}`
71999
+ }
72000
+ ]
72001
+ };
72002
+ } catch (error) {
72003
+ return {
72004
+ content: [
72005
+ {
72006
+ type: "text",
72007
+ text: `Failed to build optimum reward trade: ${error.message}`
72008
+ }
72009
+ ],
72010
+ isError: true
72011
+ };
72012
+ }
72013
+ });
72014
+ server.tool("constructAppConfig", "Build application configuration from trade parameters. Converts basic trade configuration into a comprehensive app config object with all necessary trading parameters.", {
72015
+ config: z.object({
72016
+ entry: z.number().optional().describe("Entry price"),
72017
+ stop: z.number().optional().describe("Stop loss price"),
72018
+ risk_reward: z.number().optional().describe("Risk to reward ratio"),
72019
+ risk: z.number().optional().describe("Risk amount"),
72020
+ symbol: z.string().optional().describe("Trading symbol"),
72021
+ distribution: z.enum(["arithmetic", "geometric", "normal", "exponential", "inverse-exponential"]).optional().describe("Distribution type")
72022
+ }).optional().describe("Basic trade configuration"),
72023
+ global_config: z.object({
72024
+ profit_percent: z.number().optional().describe("Profit percentage target"),
72025
+ symbol: z.string().optional().describe("Trading symbol"),
72026
+ profit: z.number().optional().describe("Target profit amount"),
72027
+ risk: z.number().optional().describe("Risk amount"),
72028
+ stop_percent: z.number().optional().describe("Stop loss percentage"),
72029
+ kind: z.enum(["long", "short"]).optional().describe("Position direction"),
72030
+ reduce_percent: z.number().optional().describe("Position reduction percentage"),
72031
+ support: z.number().optional().describe("Support price level"),
72032
+ resistance: z.number().optional().describe("Resistance price level"),
72033
+ price_places: z.string().optional().describe("Price decimal format"),
72034
+ decimal_places: z.string().optional().describe("Quantity decimal format"),
72035
+ min_size: z.number().optional().describe("Minimum trade size"),
72036
+ accounts: z.array(z.object({
72037
+ owner: z.string().optional().describe("Account owner"),
72038
+ exchange: z.string().optional().describe("Exchange name")
72039
+ })).optional().describe("Trading accounts"),
72040
+ risk_reward: z.number().optional().describe("Risk to reward ratio"),
72041
+ reverse_factor: z.number().optional().describe("Reverse factor for calculations"),
72042
+ leverage: z.number().optional().describe("Leverage multiplier"),
72043
+ max_quantity: z.number().optional().describe("Maximum quantity"),
72044
+ fee_percent: z.number().optional().describe("Trading fee percentage")
72045
+ }).optional().describe("Global configuration parameters")
72046
+ }, async (args) => {
72047
+ try {
72048
+ const result = compoundAPI.constructAppConfig(args);
72049
+ return {
72050
+ content: [
72051
+ {
72052
+ type: "text",
72053
+ text: `App configuration constructed: ${JSON.stringify(result, null, 2)}`
72054
+ }
72055
+ ]
72056
+ };
72057
+ } catch (error) {
72058
+ return {
72059
+ content: [
72060
+ {
72061
+ type: "text",
72062
+ text: `Failed to construct app config: ${error.message}`
72063
+ }
72064
+ ],
72065
+ isError: true
72066
+ };
72067
+ }
72068
+ });
72069
+ server.tool("generateOppositeOptimum", "Create opposite position trades for hedging strategies. Generates optimal trades in the opposite direction to hedge existing positions, with configurable ratio and risk factors.", {
72070
+ settings: z.object({
72071
+ entry: z.number().optional().describe("Entry price for opposite position"),
72072
+ stop: z.number().optional().describe("Stop loss price"),
72073
+ take_profit: z.number().optional().describe("Take profit price"),
72074
+ risk: z.number().optional().describe("Risk amount")
72075
+ }).optional().describe("Opposite position settings"),
72076
+ config: z.object({
72077
+ entry: z.number().optional().describe("Original position entry price"),
72078
+ stop: z.number().optional().describe("Original position stop price"),
72079
+ risk_reward: z.number().optional().describe("Risk to reward ratio"),
72080
+ risk: z.number().optional().describe("Original position risk"),
72081
+ symbol: z.string().optional().describe("Trading symbol")
72082
+ }).optional().describe("Original position configuration"),
72083
+ global_config: z.object({
72084
+ profit_percent: z.number().optional().describe("Profit percentage target"),
72085
+ symbol: z.string().optional().describe("Trading symbol"),
72086
+ profit: z.number().optional().describe("Target profit amount"),
72087
+ risk: z.number().optional().describe("Risk amount"),
72088
+ stop_percent: z.number().optional().describe("Stop loss percentage"),
72089
+ kind: z.enum(["long", "short"]).optional().describe("Position direction"),
72090
+ reduce_percent: z.number().optional().describe("Position reduction percentage"),
72091
+ support: z.number().optional().describe("Support price level"),
72092
+ resistance: z.number().optional().describe("Resistance price level"),
72093
+ price_places: z.string().optional().describe("Price decimal format"),
72094
+ decimal_places: z.string().optional().describe("Quantity decimal format"),
72095
+ min_size: z.number().optional().describe("Minimum trade size"),
72096
+ accounts: z.array(z.object({
72097
+ owner: z.string().optional().describe("Account owner"),
72098
+ exchange: z.string().optional().describe("Exchange name")
72099
+ })).optional().describe("Trading accounts"),
72100
+ risk_reward: z.number().optional().describe("Risk to reward ratio"),
72101
+ reverse_factor: z.number().optional().describe("Reverse factor for calculations"),
72102
+ leverage: z.number().optional().describe("Leverage multiplier"),
72103
+ max_quantity: z.number().optional().describe("Maximum quantity"),
72104
+ fee_percent: z.number().optional().describe("Trading fee percentage")
72105
+ }).optional().describe("Global configuration parameters"),
72106
+ entryToUse: z.number().optional().describe("Optimal entry price to use"),
72107
+ stopToUse: z.number().optional().describe("Stop price to use"),
72108
+ ratio: z.number().default(1).describe("Risk ratio multiplier (default 1)"),
72109
+ distribution: z.enum(["arithmetic", "geometric", "normal", "exponential", "inverse-exponential"]).default("inverse-exponential").describe("Distribution type"),
72110
+ risk_factor: z.number().default(1).describe("Risk factor multiplier")
72111
+ }, async (args) => {
72112
+ try {
72113
+ const result = compoundAPI.generateOppositeOptimum(args);
72114
+ return {
72115
+ content: [
72116
+ {
72117
+ type: "text",
72118
+ text: `Opposite optimum position generated: ${JSON.stringify(result, null, 2)}`
72119
+ }
72120
+ ]
72121
+ };
72122
+ } catch (error) {
72123
+ return {
72124
+ content: [
72125
+ {
72126
+ type: "text",
72127
+ text: `Failed to generate opposite optimum: ${error.message}`
72128
+ }
72129
+ ],
72130
+ isError: true
72131
+ };
72132
+ }
72133
+ });
72134
+ server.tool("increaseTradeHelper", "Help increase existing positions incrementally. Calculates optimal trades to scale up existing positions based on current market conditions and available capital.", {
72135
+ position: z.object({
72136
+ entry: z.number().optional().describe("Current position entry price"),
72137
+ quantity: z.number().optional().describe("Current position quantity")
72138
+ }).optional().describe("Existing position details"),
72139
+ entry: z.number().optional().describe("New entry price for scaling"),
72140
+ stop: z.number().optional().describe("Stop loss price for scaled position"),
72141
+ config: z.object({
72142
+ entry: z.number().optional().describe("Original entry price"),
72143
+ stop: z.number().optional().describe("Original stop price"),
72144
+ risk_reward: z.number().optional().describe("Risk to reward ratio"),
72145
+ risk: z.number().optional().describe("Risk amount"),
72146
+ symbol: z.string().optional().describe("Trading symbol")
72147
+ }).optional().describe("Base trading configuration"),
72148
+ global_config: z.object({
72149
+ profit_percent: z.number().optional().describe("Profit percentage target"),
72150
+ symbol: z.string().optional().describe("Trading symbol"),
72151
+ profit: z.number().optional().describe("Target profit amount"),
72152
+ risk: z.number().optional().describe("Risk amount"),
72153
+ stop_percent: z.number().optional().describe("Stop loss percentage"),
72154
+ kind: z.enum(["long", "short"]).optional().describe("Position direction"),
72155
+ reduce_percent: z.number().optional().describe("Position reduction percentage"),
72156
+ support: z.number().optional().describe("Support price level"),
72157
+ resistance: z.number().optional().describe("Resistance price level"),
72158
+ price_places: z.string().optional().describe("Price decimal format"),
72159
+ decimal_places: z.string().optional().describe("Quantity decimal format"),
72160
+ min_size: z.number().optional().describe("Minimum trade size"),
72161
+ accounts: z.array(z.object({
72162
+ owner: z.string().optional().describe("Account owner"),
72163
+ exchange: z.string().optional().describe("Exchange name")
72164
+ })).optional().describe("Trading accounts"),
72165
+ risk_reward: z.number().optional().describe("Risk to reward ratio"),
72166
+ reverse_factor: z.number().optional().describe("Reverse factor for calculations"),
72167
+ leverage: z.number().optional().describe("Leverage multiplier"),
72168
+ max_quantity: z.number().optional().describe("Maximum quantity"),
72169
+ fee_percent: z.number().optional().describe("Trading fee percentage")
72170
+ }).optional().describe("Global configuration parameters"),
72171
+ increase_qty: z.number().optional().describe("Maximum quantity to add to position"),
72172
+ style: z.enum(["minimum", "optimum"]).optional().describe("Calculation style - minimum or optimum risk"),
72173
+ stop_ratio: z.number().default(1).describe("Stop order quantity ratio"),
72174
+ distribution: z.enum(["arithmetic", "geometric", "normal", "exponential", "inverse-exponential"]).optional().describe("Distribution type")
72175
+ }, async (args) => {
72176
+ try {
72177
+ const result = compoundAPI.increaseTradeHelper(args);
72178
+ return {
72179
+ content: [
72180
+ {
72181
+ type: "text",
72182
+ text: `Position increase trade calculated: ${JSON.stringify(result, null, 2)}`
72183
+ }
72184
+ ]
72185
+ };
72186
+ } catch (error) {
72187
+ return {
72188
+ content: [
72189
+ {
72190
+ type: "text",
72191
+ text: `Failed to calculate increase trade: ${error.message}`
72192
+ }
72193
+ ],
72194
+ isError: true
72195
+ };
72196
+ }
72197
+ });
72198
+ server.tool("generatePositionIncreaseTrade", "Generate trades to increase positions based on trading zones. Analyzes account positions and zone parameters to determine optimal position scaling strategies.", {
72199
+ account: z.object({
72200
+ long: z.object({
72201
+ entry: z.number().optional().describe("Long position entry price"),
72202
+ quantity: z.number().optional().describe("Long position quantity")
72203
+ }).optional().describe("Long position details"),
72204
+ short: z.object({
72205
+ entry: z.number().optional().describe("Short position entry price"),
72206
+ quantity: z.number().optional().describe("Short position quantity")
72207
+ }).optional().describe("Short position details")
72208
+ }).optional().describe("Account position details"),
72209
+ zoneAccount: z.object({
72210
+ entry: z.number().optional().describe("Zone entry price"),
72211
+ stop: z.number().optional().describe("Zone stop price")
72212
+ }).optional().describe("Trading zone parameters"),
72213
+ config: z.object({
72214
+ entry: z.number().optional().describe("Base entry price"),
72215
+ stop: z.number().optional().describe("Base stop price"),
72216
+ risk_reward: z.number().optional().describe("Risk to reward ratio"),
72217
+ risk: z.number().optional().describe("Risk amount"),
72218
+ symbol: z.string().optional().describe("Trading symbol")
72219
+ }).optional().describe("Base trading configuration"),
72220
+ global_config: z.object({
72221
+ profit_percent: z.number().optional().describe("Profit percentage target"),
72222
+ symbol: z.string().optional().describe("Trading symbol"),
72223
+ profit: z.number().optional().describe("Target profit amount"),
72224
+ risk: z.number().optional().describe("Risk amount"),
72225
+ stop_percent: z.number().optional().describe("Stop loss percentage"),
72226
+ kind: z.enum(["long", "short"]).optional().describe("Position direction"),
72227
+ reduce_percent: z.number().optional().describe("Position reduction percentage"),
72228
+ support: z.number().optional().describe("Support price level"),
72229
+ resistance: z.number().optional().describe("Resistance price level"),
72230
+ price_places: z.string().optional().describe("Price decimal format"),
72231
+ decimal_places: z.string().optional().describe("Quantity decimal format"),
72232
+ min_size: z.number().optional().describe("Minimum trade size"),
72233
+ accounts: z.array(z.object({
72234
+ owner: z.string().optional().describe("Account owner"),
72235
+ exchange: z.string().optional().describe("Exchange name")
72236
+ })).optional().describe("Trading accounts"),
72237
+ risk_reward: z.number().optional().describe("Risk to reward ratio"),
72238
+ reverse_factor: z.number().optional().describe("Reverse factor for calculations"),
72239
+ leverage: z.number().optional().describe("Leverage multiplier"),
72240
+ max_quantity: z.number().optional().describe("Maximum quantity"),
72241
+ fee_percent: z.number().optional().describe("Trading fee percentage")
72242
+ }).optional().describe("Global configuration parameters"),
72243
+ ratio: z.number().default(0.1).describe("Position increase ratio (default 0.1)"),
72244
+ style: z.enum(["optimum", "minimum"]).default("minimum").describe("Calculation style"),
72245
+ distribution: z.enum(["arithmetic", "geometric", "normal", "exponential", "inverse-exponential"]).default("inverse-exponential").describe("Distribution type")
72246
+ }, async (args) => {
72247
+ try {
72248
+ const result = compoundAPI.generatePositionIncreaseTrade(args);
72249
+ return {
72250
+ content: [
72251
+ {
72252
+ type: "text",
72253
+ text: `Zone-based position increase trade: ${JSON.stringify(result, null, 2)}`
72254
+ }
72255
+ ]
72256
+ };
72257
+ } catch (error) {
72258
+ return {
72259
+ content: [
72260
+ {
72261
+ type: "text",
72262
+ text: `Failed to generate position increase trade: ${error.message}`
72263
+ }
72264
+ ],
72265
+ isError: true
72266
+ };
72267
+ }
72268
+ });
71542
72269
  async function main() {
71543
72270
  const transport = new StdioServerTransport;
71544
72271
  await server.connect(transport);