@gbozee/ultimate 0.0.2-200 → 0.0.2-202

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