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:
@@ -90,6 +90,63 @@ public class StatisticService : IStatisticService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateFundingRates()
|
||||
{
|
||||
// Get fundingRate from database
|
||||
var previousFundingRate = await GetFundingRates();
|
||||
// var fundingRates = await .GetFundingRates();
|
||||
|
||||
var newFundingRates = await _tradaoService.GetFundingRates();
|
||||
var topRates = newFundingRates
|
||||
.OrderByDescending(fr => fr.Rate)
|
||||
.Take(3)
|
||||
.ToList();
|
||||
|
||||
// Old position not in the new top
|
||||
foreach (var oldRate in previousFundingRate)
|
||||
{
|
||||
if (topRates.All(tr => !SameFundingRate(tr, oldRate)))
|
||||
{
|
||||
// Close position
|
||||
await _messengerService.SendDowngradedFundingRate(oldRate);
|
||||
await _statisticRepository.RemoveFundingRate(oldRate);
|
||||
}
|
||||
}
|
||||
|
||||
// New position not in the old top
|
||||
foreach (var newRate in topRates)
|
||||
{
|
||||
if (previousFundingRate.All(tr => !SameFundingRate(tr, newRate)))
|
||||
{
|
||||
// Open position
|
||||
await _messengerService.SendNewTopFundingRate(newRate);
|
||||
await _statisticRepository.InsertFundingRate(newRate);
|
||||
}
|
||||
else if (previousFundingRate.Any(tr => SameFundingRate(tr, newRate)))
|
||||
{
|
||||
var oldRate = previousFundingRate.FirstOrDefault(tr => SameFundingRate(tr, newRate));
|
||||
if (oldRate != null && Math.Abs(oldRate.Rate - newRate.Rate) > 1m)
|
||||
{
|
||||
await _messengerService.SendFundingRateUpdate(oldRate, newRate);
|
||||
_statisticRepository.UpdateFundingRate(oldRate, newRate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool SameFundingRate(FundingRate oldRate, FundingRate newRate)
|
||||
{
|
||||
return oldRate.Ticker == newRate.Ticker &&
|
||||
oldRate.Exchange == newRate.Exchange &&
|
||||
oldRate.Direction == newRate.Direction;
|
||||
}
|
||||
|
||||
public Task<List<FundingRate>> GetFundingRates()
|
||||
{
|
||||
var previousFundingRate = _statisticRepository.GetFundingRates();
|
||||
return Task.FromResult(previousFundingRate);
|
||||
}
|
||||
|
||||
public IList<TopVolumeTicker> GetLastTopVolumeTicker()
|
||||
{
|
||||
var from = DateTime.UtcNow.AddDays(-1);
|
||||
@@ -113,16 +170,17 @@ public class StatisticService : IStatisticService
|
||||
|
||||
if (overview != null)
|
||||
{
|
||||
if(overview.Spotlights.Count < overview.ScenarioCount)
|
||||
if (overview.Spotlights.Count < overview.ScenarioCount)
|
||||
{
|
||||
_logger.LogInformation($"Spotlights not up to date. {overview.Spotlights.Count}/{overview.ScenarioCount}");
|
||||
_logger.LogInformation(
|
||||
$"Spotlights not up to date. {overview.Spotlights.Count}/{overview.ScenarioCount}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("No need to update spotlights");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
overview = new SpotlightOverview
|
||||
@@ -188,14 +246,14 @@ public class StatisticService : IStatisticService
|
||||
};
|
||||
|
||||
var backtest = _backtester.RunScalpingBotBacktest(
|
||||
account,
|
||||
moneyManagement,
|
||||
ticker,
|
||||
scenario,
|
||||
timeframe,
|
||||
CandleExtensions.GetMinimalDays(timeframe),
|
||||
1000,
|
||||
isForWatchingOnly: true);
|
||||
account,
|
||||
moneyManagement,
|
||||
ticker,
|
||||
scenario,
|
||||
timeframe,
|
||||
CandleExtensions.GetMinimalDays(timeframe),
|
||||
1000,
|
||||
isForWatchingOnly: true);
|
||||
|
||||
return backtest.Signals;
|
||||
}
|
||||
@@ -301,4 +359,4 @@ public class StatisticService : IStatisticService
|
||||
|
||||
await _messengerService.SendBadTraders(lastBadTrader);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user