GMX v2 - Trading (#7)

* Move PrivateKeys.cs

* Update gitignore

* Update gitignore

* updt

* Extract GmxServiceTests.cs

* Refact

* update todo

* Update code

* Fix hashdata

* Replace static token hashed datas

* Set allowance

* Add get orders

* Add get orders tests

* Add ignore

* add close orders

* revert

* Add get gas limit

* Start increasePosition. Todo: Finish GetExecutionFee and estimateGas

* little refact

* Update gitignore

* Fix namespaces and clean repo

* Add tests samples

* Add execution fee

* Add increase position

* Handle backtest on the frontend

* Add tests

* Update increase

* Test increase

* fix increase

* Fix size

* Start get position

* Update get positions

* Fix get position

* Update rpc and trade mappers

* Finish close position

* Fix leverage
This commit is contained in:
Oda
2025-01-30 23:06:22 +07:00
committed by GitHub
parent ecaa89c67b
commit 65bdb8e34f
156 changed files with 11253 additions and 4073 deletions

View File

@@ -1,6 +1,7 @@
using Discord;
using Discord.Commands;
using Managing.Application.Abstractions;
using Managing.Application.Abstractions.Services;
using Managing.Application.Trading.Commands;
using Managing.Common;
using Managing.Core;
@@ -19,8 +20,8 @@ namespace Managing.Infrastructure.Messengers.Discord
private readonly ICommandHandler<OpenPositionRequest, Position> _openTradeCommandHandler;
public DiscordCommands(DiscordSettings settings,
IBacktester backtester,
ICommandHandler<OpenPositionRequest, Position> openTradeCommandHandler)
IBacktester backtester,
ICommandHandler<OpenPositionRequest, Position> openTradeCommandHandler)
{
_settings = settings;
_backtester = backtester;
@@ -43,7 +44,8 @@ namespace Managing.Infrastructure.Messengers.Discord
var builder = new ComponentBuilder().WithButton("Open Position",
$"{Constants.DiscordButtonAction.OpenPosition}-{exchange}-{ticker}-{direction}-{timeframe}-{expirationDate}");
await Context.Channel.SendMessageAsync(_messagePrefix + $"you can now click on this button to open a position on {ticker}"
await Context.Channel.SendMessageAsync(
_messagePrefix + $"you can now click on this button to open a position on {ticker}"
, components: builder.Build());
}
@@ -69,11 +71,12 @@ namespace Managing.Infrastructure.Messengers.Discord
BalanceAtRisk = 5,
StopLoss = stopLoss.GetValueOrDefault(),
TakeProfit = takeProfit.GetValueOrDefault(),
};
var tradeCommand = new OpenPositionRequest(accountName, moneymanagement, direction, ticker, PositionInitiator.User, DateTime.UtcNow);
var tradeCommand = new OpenPositionRequest(accountName, moneymanagement, direction, ticker,
PositionInitiator.User, DateTime.UtcNow);
var result = await _openTradeCommandHandler.Handle(tradeCommand);
var builder = new ComponentBuilder().WithButton("Close Position", $"{Constants.DiscordButtonAction.ClosePosition}|{result.Open.ExchangeOrderId}");
var builder = new ComponentBuilder().WithButton("Close Position",
$"{Constants.DiscordButtonAction.ClosePosition}|{result.Open.ExchangeOrderId}");
await Context.Channel.SendMessageAsync(MessengerHelpers.GetPositionMessage(result),
components: builder.Build());
}
@@ -81,7 +84,6 @@ namespace Managing.Infrastructure.Messengers.Discord
{
await Context.Channel.SendMessageAsync($"Something weird happen bro, {ex.Message}");
}
}
[Command("bot")]
@@ -93,12 +95,14 @@ namespace Managing.Infrastructure.Messengers.Discord
{
_settings.BotEnabled = true;
}
if (string.Equals(rest, "disable", StringComparison.OrdinalIgnoreCase))
{
_settings.BotEnabled = false;
}
await Context.Channel.SendMessageAsync("Bot is "
+ (_settings.BotEnabled ? "enabled" : "disabled"));
+ (_settings.BotEnabled ? "enabled" : "disabled"));
}
//[Command("backtest")]
@@ -144,7 +148,7 @@ namespace Managing.Infrastructure.Messengers.Discord
var result = "down";
message += $"I tried to start the bot called {botName}, his status is now {result}. ";
if (result == "Up")
{
await Context.Message.AddReactionAsync(new Emoji("👌"));
@@ -166,7 +170,7 @@ namespace Managing.Infrastructure.Messengers.Discord
var parameters = rest.Split(_separator, StringSplitOptions.None);
var botType = MiscExtensions.ParseEnum<BotType>(parameters[0]);
var botName = parameters[1];
var result = "down";
var result = "down";
//var result = await _mediator.Send(new StopBotCommand(botType, botName));
await Context.Channel.SendMessageAsync(_messagePrefix + $"the {botType} called {botName} is now {result}");
@@ -188,10 +192,12 @@ namespace Managing.Infrastructure.Messengers.Discord
switch (rest)
{
case "backtest":
message += "to run a backtest you should use this pattern : !trader backtest ticker exchange timeframe startFromDays";
message +=
"to run a backtest you should use this pattern : !trader backtest ticker exchange timeframe startFromDays";
break;
case "run":
message += "to run a bot you should use this pattern : !trader run botType botName ticker timeframe";
message +=
"to run a bot you should use this pattern : !trader run botType botName ticker timeframe";
break;
case "stop":
message += "to stop a bot you should use this pattern : !trader stop botType botName";
@@ -201,11 +207,11 @@ namespace Managing.Infrastructure.Messengers.Discord
break;
case "timeframe":
message += $"the bot can currently handle only those timeframes : " +
$"{Timeframe.FifteenMinutes}, {Timeframe.ThirtyMinutes}, {Timeframe.OneDay}";
$"{Timeframe.FifteenMinutes}, {Timeframe.ThirtyMinutes}, {Timeframe.OneDay}";
break;
case "risklevel":
message += $"the bot can currently handle only those riskLevel : " +
$"{RiskLevel.High}";
$"{RiskLevel.High}";
break;
default:
message += "I don't no the command";