Add synthApi (#27)
* Add synthApi * Put confidence for Synth proba * Update the code * Update readme * Fix bootstraping * fix github build * Update the endpoints for scenario * Add scenario and update backtest modal * Update bot modal * Update interfaces for synth * add synth to backtest * Add Kelly criterion and better signal * Update signal confidence * update doc * save leaderboard and prediction * Update nswag to generate ApiClient in the correct path * Unify the trading modal * Save miner and prediction * Update messaging and block new signal until position not close when flipping off * Rename strategies to indicators * Update doc * Update chart + add signal name * Fix signal direction * Update docker webui * remove crypto npm * Clean
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Managing.Domain.Accounts;
|
||||
using System.Text.Json;
|
||||
using Managing.Domain.Accounts;
|
||||
using Managing.Domain.Backtests;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Candles;
|
||||
@@ -6,6 +7,7 @@ using Managing.Domain.MoneyManagements;
|
||||
using Managing.Domain.Scenarios;
|
||||
using Managing.Domain.Statistics;
|
||||
using Managing.Domain.Strategies;
|
||||
using Managing.Domain.Synth.Models;
|
||||
using Managing.Domain.Trades;
|
||||
using Managing.Domain.Users;
|
||||
using Managing.Domain.Workers;
|
||||
@@ -371,7 +373,8 @@ public static class MongoMappers
|
||||
Status = signal.Status,
|
||||
Timeframe = signal.Timeframe,
|
||||
Type = signal.IndicatorType,
|
||||
User = signal.User != null ? Map(signal.User) : null
|
||||
User = signal.User != null ? Map(signal.User) : null,
|
||||
IndicatorName = signal.IndicatorName
|
||||
};
|
||||
}
|
||||
|
||||
@@ -387,6 +390,7 @@ public static class MongoMappers
|
||||
TradingExchanges.Binance, //TODO FIXME When the signal status is modified from controller
|
||||
bSignal.Type,
|
||||
bSignal.SignalType,
|
||||
bSignal.IndicatorName,
|
||||
bSignal.User != null ? Map(bSignal.User) : null)
|
||||
{
|
||||
Status = bSignal.Status
|
||||
@@ -744,7 +748,6 @@ public static class MongoMappers
|
||||
{
|
||||
User = Map(bot.User),
|
||||
Identifier = bot.Identifier,
|
||||
BotType = bot.BotType,
|
||||
Data = bot.Data,
|
||||
LastStatus = bot.LastStatus
|
||||
};
|
||||
@@ -758,7 +761,6 @@ public static class MongoMappers
|
||||
{
|
||||
User = Map(b.User),
|
||||
Identifier = b.Identifier,
|
||||
BotType = b.BotType,
|
||||
Data = b.Data,
|
||||
LastStatus = b.LastStatus
|
||||
};
|
||||
@@ -792,4 +794,143 @@ public static class MongoMappers
|
||||
Direction = fundingRate.Direction
|
||||
};
|
||||
}
|
||||
|
||||
#region Synth
|
||||
|
||||
/// <summary>
|
||||
/// Maps domain SynthMinersLeaderboard to MongoDB DTO
|
||||
/// </summary>
|
||||
internal static SynthMinersLeaderboardDto Map(SynthMinersLeaderboard leaderboard)
|
||||
{
|
||||
if (leaderboard == null) return null;
|
||||
|
||||
return new SynthMinersLeaderboardDto
|
||||
{
|
||||
Asset = leaderboard.Asset,
|
||||
TimeIncrement = leaderboard.TimeIncrement,
|
||||
SignalDate = leaderboard.SignalDate,
|
||||
IsBacktest = leaderboard.IsBacktest,
|
||||
MinersData = JsonSerializer.Serialize(leaderboard.Miners),
|
||||
CacheKey = leaderboard.GetCacheKey()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps MongoDB DTO to domain SynthMinersLeaderboard
|
||||
/// </summary>
|
||||
internal static SynthMinersLeaderboard Map(SynthMinersLeaderboardDto dto)
|
||||
{
|
||||
if (dto == null) return null;
|
||||
|
||||
var miners = string.IsNullOrEmpty(dto.MinersData)
|
||||
? new List<MinerInfo>()
|
||||
: JsonSerializer.Deserialize<List<MinerInfo>>(dto.MinersData) ?? new List<MinerInfo>();
|
||||
|
||||
return new SynthMinersLeaderboard
|
||||
{
|
||||
Id = dto.Id.ToString(),
|
||||
Asset = dto.Asset,
|
||||
TimeIncrement = dto.TimeIncrement,
|
||||
SignalDate = dto.SignalDate,
|
||||
IsBacktest = dto.IsBacktest,
|
||||
Miners = miners,
|
||||
CreatedAt = dto.CreatedAt
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps domain SynthMinersPredictions to MongoDB DTO
|
||||
/// </summary>
|
||||
internal static SynthMinersPredictionsDto Map(SynthMinersPredictions predictions)
|
||||
{
|
||||
if (predictions == null) return null;
|
||||
|
||||
return new SynthMinersPredictionsDto
|
||||
{
|
||||
Asset = predictions.Asset,
|
||||
TimeIncrement = predictions.TimeIncrement,
|
||||
TimeLength = predictions.TimeLength,
|
||||
SignalDate = predictions.SignalDate,
|
||||
IsBacktest = predictions.IsBacktest,
|
||||
MinerUidsData = JsonSerializer.Serialize(predictions.MinerUids),
|
||||
PredictionsData = JsonSerializer.Serialize(predictions.Predictions),
|
||||
CacheKey = predictions.GetCacheKey()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps MongoDB DTO to domain SynthMinersPredictions
|
||||
/// </summary>
|
||||
internal static SynthMinersPredictions Map(SynthMinersPredictionsDto dto)
|
||||
{
|
||||
if (dto == null) return null;
|
||||
|
||||
var minerUids = string.IsNullOrEmpty(dto.MinerUidsData)
|
||||
? new List<int>()
|
||||
: JsonSerializer.Deserialize<List<int>>(dto.MinerUidsData) ?? new List<int>();
|
||||
|
||||
var predictions = string.IsNullOrEmpty(dto.PredictionsData)
|
||||
? new List<MinerPrediction>()
|
||||
: JsonSerializer.Deserialize<List<MinerPrediction>>(dto.PredictionsData) ?? new List<MinerPrediction>();
|
||||
|
||||
return new SynthMinersPredictions
|
||||
{
|
||||
Id = dto.Id.ToString(),
|
||||
Asset = dto.Asset,
|
||||
TimeIncrement = dto.TimeIncrement,
|
||||
TimeLength = dto.TimeLength,
|
||||
SignalDate = dto.SignalDate,
|
||||
IsBacktest = dto.IsBacktest,
|
||||
MinerUids = minerUids,
|
||||
Predictions = predictions,
|
||||
CreatedAt = dto.CreatedAt
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps domain SynthPrediction to MongoDB DTO
|
||||
/// </summary>
|
||||
internal static SynthPredictionDto Map(SynthPrediction prediction)
|
||||
{
|
||||
if (prediction == null) return null;
|
||||
|
||||
return new SynthPredictionDto
|
||||
{
|
||||
Asset = prediction.Asset,
|
||||
MinerUid = prediction.MinerUid,
|
||||
TimeIncrement = prediction.TimeIncrement,
|
||||
TimeLength = prediction.TimeLength,
|
||||
SignalDate = prediction.SignalDate,
|
||||
IsBacktest = prediction.IsBacktest,
|
||||
PredictionData = JsonSerializer.Serialize(prediction.Prediction),
|
||||
CacheKey = prediction.GetCacheKey()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps MongoDB DTO to domain SynthPrediction
|
||||
/// </summary>
|
||||
internal static SynthPrediction Map(SynthPredictionDto dto)
|
||||
{
|
||||
if (dto == null) return null;
|
||||
|
||||
var prediction = string.IsNullOrEmpty(dto.PredictionData)
|
||||
? null
|
||||
: JsonSerializer.Deserialize<MinerPrediction>(dto.PredictionData);
|
||||
|
||||
return new SynthPrediction
|
||||
{
|
||||
Id = dto.Id.ToString(),
|
||||
Asset = dto.Asset,
|
||||
MinerUid = dto.MinerUid,
|
||||
TimeIncrement = dto.TimeIncrement,
|
||||
TimeLength = dto.TimeLength,
|
||||
SignalDate = dto.SignalDate,
|
||||
IsBacktest = dto.IsBacktest,
|
||||
Prediction = prediction,
|
||||
CreatedAt = dto.CreatedAt
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user