Add funding rate watcher (#2)

* Add FundingRate interfaces and worker

* Add build on PR

* Remove zip

* Specify the solution path

* Add build for worker too

* Set up StatisticService.cs for funding rate

* Add Fundingrate alerts

* Send alert when big funding rate change + add SlashCommands.cs for fundingrate

* Remove fixtures

* Refact names

* Renames
This commit is contained in:
Oda
2024-07-19 08:31:09 +07:00
committed by GitHub
parent 545c9d8e4a
commit 029ba5f40e
41 changed files with 914 additions and 304 deletions

View File

@@ -0,0 +1,15 @@
using Managing.Common;
using Managing.Infrastructure.Databases.MongoDb.Attributes;
using Managing.Infrastructure.Databases.MongoDb.Configurations;
namespace Managing.Infrastructure.Databases.MongoDb.Collections;
[BsonCollection("FundingRates")]
public class FundingRateDto : Document
{
public Enums.Ticker Ticker { get; set; }
public decimal Rate { get; set; }
public Enums.TradingExchanges Exchange { get; set; }
public DateTime Date { get; set; }
public Enums.TradeDirection Direction { get; set; }
}

View File

@@ -16,7 +16,8 @@ namespace Managing.Infrastructure.Databases.MongoDb;
public static class MongoMappers
{
#region Statistics
#region Statistics
internal static TopVolumeTickerDto Map(TopVolumeTicker topVolumeTicker)
{
return new TopVolumeTickerDto
@@ -44,6 +45,7 @@ public static class MongoMappers
#endregion
#region Accounts
internal static AccountDto Map(Account request)
{
return new AccountDto
@@ -84,9 +86,11 @@ public static class MongoMappers
return a;
}
#endregion
#region Workers
internal static WorkerDto Map(Worker worker)
{
return new WorkerDto
@@ -118,6 +122,7 @@ public static class MongoMappers
#endregion
#region Backtests
internal static Backtest Map(BacktestDto b)
{
return new Backtest(
@@ -165,7 +170,8 @@ public static class MongoMappers
#endregion
#region Candles
#region Candles
public static Candle Map(CandleDto candle)
{
if (candle == null)
@@ -213,10 +219,10 @@ public static class MongoMappers
return candles.ConvertAll(candle => Map(candle));
}
#endregion
#region Positions
public static PositionDto Map(Position position)
{
var p = new PositionDto
@@ -267,9 +273,13 @@ public static class MongoMappers
public static Position Map(PositionDto dto)
{
var position = new Position(dto.AccountName, originDirection: dto.OriginDirection, dto.Ticker, Map(dto.MoneyManagement), dto.Initiator, dto.Date)
var position = new Position(dto.AccountName, originDirection: dto.OriginDirection, dto.Ticker,
Map(dto.MoneyManagement), dto.Initiator, dto.Date)
{
Open = new Trade(date: dto.Open.Date, direction: dto.Open.Direction, status: dto.Open.Status, tradeType: dto.Open.TradeType, ticker: dto.Open.Ticker, quantity: dto.Open.Quantity, price: dto.Open.Price, leverage: dto.Open.Leverage, exchangeOrderId: dto.Open.ExchangeOrderId, message: dto.Open.Message),
Open = new Trade(date: dto.Open.Date, direction: dto.Open.Direction, status: dto.Open.Status,
tradeType: dto.Open.TradeType, ticker: dto.Open.Ticker, quantity: dto.Open.Quantity,
price: dto.Open.Price, leverage: dto.Open.Leverage, exchangeOrderId: dto.Open.ExchangeOrderId,
message: dto.Open.Message),
ProfitAndLoss = new ProfitAndLoss { Realized = dto.ProfitAndLoss },
Status = dto.Status,
SignalIdentifier = dto.SignalIdentifier,
@@ -278,17 +288,26 @@ public static class MongoMappers
if (dto.StopLoss != null)
{
position.StopLoss = new Trade(date: dto.StopLoss.Date, direction: dto.StopLoss.Direction, status: dto.StopLoss.Status, tradeType: dto.StopLoss.TradeType, ticker: dto.StopLoss.Ticker, quantity: dto.StopLoss.Quantity, price: dto.StopLoss.Price, leverage: dto.StopLoss.Leverage, exchangeOrderId: dto.StopLoss.ExchangeOrderId, message: dto.StopLoss.Message);
position.StopLoss = new Trade(date: dto.StopLoss.Date, direction: dto.StopLoss.Direction,
status: dto.StopLoss.Status, tradeType: dto.StopLoss.TradeType, ticker: dto.StopLoss.Ticker,
quantity: dto.StopLoss.Quantity, price: dto.StopLoss.Price, leverage: dto.StopLoss.Leverage,
exchangeOrderId: dto.StopLoss.ExchangeOrderId, message: dto.StopLoss.Message);
}
if (dto.TakeProfit1 != null)
{
position.TakeProfit1 = new Trade(date: dto.TakeProfit1.Date, direction: dto.TakeProfit1.Direction, status: dto.TakeProfit1.Status, tradeType: dto.TakeProfit1.TradeType, ticker: dto.TakeProfit1.Ticker, quantity: dto.TakeProfit1.Quantity, price: dto.TakeProfit1.Price, leverage: dto.TakeProfit1.Leverage, exchangeOrderId: dto.TakeProfit1.ExchangeOrderId, message: dto.TakeProfit1.Message);
position.TakeProfit1 = new Trade(date: dto.TakeProfit1.Date, direction: dto.TakeProfit1.Direction,
status: dto.TakeProfit1.Status, tradeType: dto.TakeProfit1.TradeType, ticker: dto.TakeProfit1.Ticker,
quantity: dto.TakeProfit1.Quantity, price: dto.TakeProfit1.Price, leverage: dto.TakeProfit1.Leverage,
exchangeOrderId: dto.TakeProfit1.ExchangeOrderId, message: dto.TakeProfit1.Message);
}
if (dto.TakeProfit2 != null)
{
position.TakeProfit2 = new Trade(date: dto.TakeProfit2.Date, direction: dto.TakeProfit2.Direction, status: dto.TakeProfit2.Status, tradeType: dto.TakeProfit2.TradeType, ticker: dto.TakeProfit2.Ticker, quantity: dto.TakeProfit2.Quantity, price: dto.TakeProfit2.Price, leverage: dto.TakeProfit2.Leverage, exchangeOrderId: dto.TakeProfit2.ExchangeOrderId, message: dto.TakeProfit2.Message);
position.TakeProfit2 = new Trade(date: dto.TakeProfit2.Date, direction: dto.TakeProfit2.Direction,
status: dto.TakeProfit2.Status, tradeType: dto.TakeProfit2.TradeType, ticker: dto.TakeProfit2.Ticker,
quantity: dto.TakeProfit2.Quantity, price: dto.TakeProfit2.Price, leverage: dto.TakeProfit2.Leverage,
exchangeOrderId: dto.TakeProfit2.ExchangeOrderId, message: dto.TakeProfit2.Message);
}
return position;
@@ -302,6 +321,7 @@ public static class MongoMappers
#endregion
#region Signals
public static SignalDto Map(Signal signal)
{
return new SignalDto
@@ -330,7 +350,8 @@ public static class MongoMappers
#endregion
#region Scenarios
#region Scenarios
public static ScenarioDto Map(Scenario scenario)
{
return new ScenarioDto()
@@ -373,6 +394,7 @@ public static class MongoMappers
CyclePeriods = strategyDto.CyclePeriods
};
}
internal static StrategyDto Map(Strategy strategy)
{
var dto = new StrategyDto
@@ -430,6 +452,7 @@ public static class MongoMappers
#endregion
#region Money Management
public static MoneyManagementDto Map(MoneyManagement request)
{
if (request == null) return null;
@@ -497,16 +520,25 @@ public static class MongoMappers
Scenario = new ScenarioDto
{
Name = spotlight.Scenario.Name,
Strategies = spotlight.Scenario.Strategies.ConvertAll(spotlightScenarioStrategy => Map(spotlightScenarioStrategy))
Strategies =
spotlight.Scenario.Strategies.ConvertAll(
spotlightScenarioStrategy => Map(spotlightScenarioStrategy))
},
TickerSignals = spotlight.TickerSignals.ConvertAll(spotlightTickerSignal => new TickerSignalDto
{
Ticker = spotlightTickerSignal.Ticker,
FiveMinutes = spotlightTickerSignal.FiveMinutes?.ConvertAll(spotlightTickerSignalFiveMinute => Map(spotlightTickerSignalFiveMinute)) ?? new List<SignalDto>(),
FifteenMinutes = spotlightTickerSignal.FifteenMinutes?.ConvertAll(spotlightTickerSignalFifteenMinute => Map(spotlightTickerSignalFifteenMinute)) ?? new List<SignalDto>(),
OneHour = spotlightTickerSignal.OneHour?.ConvertAll(spotlightTickerSignalOneHour => Map(spotlightTickerSignalOneHour)) ?? new List<SignalDto>(),
FourHour = spotlightTickerSignal.FourHour?.ConvertAll(spotlightTickerSignalFourHour => Map(spotlightTickerSignalFourHour)) ?? new List<SignalDto>(),
OneDay = spotlightTickerSignal.OneDay?.ConvertAll(spotlightTickerSignalOneDay => Map(spotlightTickerSignalOneDay)) ?? new List<SignalDto>()
FiveMinutes =
spotlightTickerSignal.FiveMinutes?.ConvertAll(spotlightTickerSignalFiveMinute =>
Map(spotlightTickerSignalFiveMinute)) ?? new List<SignalDto>(),
FifteenMinutes =
spotlightTickerSignal.FifteenMinutes?.ConvertAll(spotlightTickerSignalFifteenMinute =>
Map(spotlightTickerSignalFifteenMinute)) ?? new List<SignalDto>(),
OneHour = spotlightTickerSignal.OneHour?.ConvertAll(spotlightTickerSignalOneHour =>
Map(spotlightTickerSignalOneHour)) ?? new List<SignalDto>(),
FourHour = spotlightTickerSignal.FourHour?.ConvertAll(spotlightTickerSignalFourHour =>
Map(spotlightTickerSignalFourHour)) ?? new List<SignalDto>(),
OneDay = spotlightTickerSignal.OneDay?.ConvertAll(spotlightTickerSignalOneDay =>
Map(spotlightTickerSignalOneDay)) ?? new List<SignalDto>()
})
});
}
@@ -528,16 +560,23 @@ public static class MongoMappers
{
Scenario = new Scenario(name: spotlight.Scenario.Name)
{
Strategies = spotlight.Scenario.Strategies.ConvertAll(spotlightScenarioStrategy => Map(spotlightScenarioStrategy))
Strategies =
spotlight.Scenario.Strategies.ConvertAll(
spotlightScenarioStrategy => Map(spotlightScenarioStrategy))
},
TickerSignals = spotlight.TickerSignals.ConvertAll(spotlightTickerSignal => new TickerSignal
{
Ticker = spotlightTickerSignal.Ticker,
FiveMinutes = spotlightTickerSignal.FiveMinutes.ConvertAll(spotlightTickerSignalFiveMinute => Map(spotlightTickerSignalFiveMinute)),
FifteenMinutes = spotlightTickerSignal.FifteenMinutes.ConvertAll(spotlightTickerSignalFifteenMinute => Map(spotlightTickerSignalFifteenMinute)),
OneHour = spotlightTickerSignal.OneHour.ConvertAll(spotlightTickerSignalOneHour => Map(spotlightTickerSignalOneHour)),
FourHour = spotlightTickerSignal.FourHour.ConvertAll(spotlightTickerSignalFourHour => Map(spotlightTickerSignalFourHour)),
OneDay = spotlightTickerSignal.OneDay.ConvertAll(spotlightTickerSignalOneDay => Map(spotlightTickerSignalOneDay))
FiveMinutes = spotlightTickerSignal.FiveMinutes.ConvertAll(spotlightTickerSignalFiveMinute =>
Map(spotlightTickerSignalFiveMinute)),
FifteenMinutes = spotlightTickerSignal.FifteenMinutes.ConvertAll(spotlightTickerSignalFifteenMinute =>
Map(spotlightTickerSignalFifteenMinute)),
OneHour = spotlightTickerSignal.OneHour.ConvertAll(spotlightTickerSignalOneHour =>
Map(spotlightTickerSignalOneHour)),
FourHour = spotlightTickerSignal.FourHour.ConvertAll(spotlightTickerSignalFourHour =>
Map(spotlightTickerSignalFourHour)),
OneDay = spotlightTickerSignal.OneDay.ConvertAll(spotlightTickerSignalOneDay =>
Map(spotlightTickerSignalOneDay))
})
});
}
@@ -675,4 +714,31 @@ public static class MongoMappers
}
#endregion
}
public static FundingRate Map(FundingRateDto fundingRate)
{
if (fundingRate == null)
return null;
return new FundingRate
{
Exchange = fundingRate.Exchange,
Rate = fundingRate.Rate,
Ticker = fundingRate.Ticker,
Date = fundingRate.Date,
Direction = fundingRate.Direction
};
}
public static FundingRateDto Map(FundingRate fundingRate)
{
return new FundingRateDto
{
Exchange = fundingRate.Exchange,
Rate = fundingRate.Rate,
Ticker = fundingRate.Ticker,
Date = fundingRate.Date,
Direction = fundingRate.Direction
};
}
}