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