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