Fix backup (#5)
This commit is contained in:
@@ -7,8 +7,8 @@ namespace Managing.Application.Abstractions;
|
||||
|
||||
public interface IBotService
|
||||
{
|
||||
void SaveBotBackup(BotBackup botBackup);
|
||||
void SaveBotBackup(string name, Enums.BotType botType, string data);
|
||||
void SaveOrUpdateBotBackup(BotBackup botBackup);
|
||||
void SaveOrUpdateBotBackup(string name, Enums.BotType botType, string data);
|
||||
void AddSimpleBotToCache(IBot bot);
|
||||
void AddTradingBotToCache(ITradingBot bot);
|
||||
List<ITradingBot> GetActiveBots();
|
||||
@@ -31,4 +31,5 @@ public interface IBotService
|
||||
Task<string> StopBot(string requestName);
|
||||
Task<bool> DeleteBot(string requestName);
|
||||
Task<string> RestartBot(string requestName);
|
||||
void DeleteBotBackup(string backupBotName);
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace Managing.Application.Bots
|
||||
public override void SaveBackup()
|
||||
{
|
||||
var data = JsonConvert.SerializeObject(_workflow);
|
||||
_botService.SaveBotBackup(Name, BotType.SimpleBot, data);
|
||||
_botService.SaveOrUpdateBotBackup(Name, BotType.SimpleBot, data);
|
||||
}
|
||||
|
||||
public override void LoadBackup(BotBackup backup)
|
||||
|
||||
@@ -714,7 +714,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
WalletBalances = WalletBalances,
|
||||
MoneyManagement = MoneyManagement
|
||||
};
|
||||
BotService.SaveBotBackup(Name, BotType, JsonConvert.SerializeObject(data));
|
||||
BotService.SaveOrUpdateBotBackup(Name, BotType, JsonConvert.SerializeObject(data));
|
||||
}
|
||||
|
||||
public override void LoadBackup(BotBackup backup)
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Managing.Application.ManageBot
|
||||
_tradingService = tradingService;
|
||||
}
|
||||
|
||||
public async void SaveBotBackup(BotBackup botBackup)
|
||||
public async void SaveOrUpdateBotBackup(BotBackup botBackup)
|
||||
{
|
||||
await _botRepository.InsertBotAsync(botBackup);
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace Managing.Application.ManageBot
|
||||
return _botRepository.GetBots().FirstOrDefault(b => b.Name == name);
|
||||
}
|
||||
|
||||
public void SaveBotBackup(string name, Enums.BotType botType, string data)
|
||||
public void SaveOrUpdateBotBackup(string name, Enums.BotType botType, string data)
|
||||
{
|
||||
var backup = GetBotBackup(name);
|
||||
|
||||
@@ -53,9 +53,9 @@ namespace Managing.Application.ManageBot
|
||||
{
|
||||
backup.Data = data;
|
||||
_botRepository.UpdateBackupBot(backup);
|
||||
return;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
var botBackup = new BotBackup
|
||||
{
|
||||
Name = name,
|
||||
@@ -65,6 +65,7 @@ namespace Managing.Application.ManageBot
|
||||
|
||||
_botRepository.InsertBotAsync(botBackup);
|
||||
}
|
||||
}
|
||||
|
||||
public class BotTaskWrapper
|
||||
{
|
||||
@@ -197,6 +198,11 @@ namespace Managing.Application.ManageBot
|
||||
return Task.FromResult(Enums.BotStatus.Down.ToString());
|
||||
}
|
||||
|
||||
public void DeleteBotBackup(string backupBotName)
|
||||
{
|
||||
_botRepository.DeleteBotBackup(backupBotName);
|
||||
}
|
||||
|
||||
public ITradingBot CreateScalpingBot(string accountName, MoneyManagement moneyManagement, string name,
|
||||
Enums.Ticker ticker, string scenario, Enums.Timeframe interval, bool isForWatchingOnly)
|
||||
{
|
||||
|
||||
@@ -74,6 +74,7 @@ public class LoadBackupBotCommandHandler : IRequestHandler<LoadBackupBotCommand,
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"Error loading bot {backupBot.Name}", ex.Message);
|
||||
_botService.DeleteBotBackup(backupBot.Name);
|
||||
result.Add(backupBot.Name, BotStatus.Down);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,19 +27,16 @@ namespace Managing.Application.ManageBot
|
||||
{
|
||||
case BotType.SimpleBot:
|
||||
var bot = _botFactory.CreateSimpleBot(request.Name, null);
|
||||
bot.Start();
|
||||
_botService.AddSimpleBotToCache(bot);
|
||||
return Task.FromResult(bot.GetStatus());
|
||||
case BotType.ScalpingBot:
|
||||
var sBot = _botFactory.CreateScalpingBot(request.AccountName, moneyManagement, request.Name,
|
||||
request.Ticker, request.Scenario, request.Timeframe, request.IsForWatchingOnly);
|
||||
sBot.Start();
|
||||
_botService.AddTradingBotToCache(sBot);
|
||||
return Task.FromResult(sBot.GetStatus());
|
||||
case BotType.FlippingBot:
|
||||
var fBot = _botFactory.CreateFlippingBot(request.AccountName, moneyManagement, request.Name,
|
||||
request.Ticker, request.Scenario, request.Timeframe, request.IsForWatchingOnly);
|
||||
fBot.Start();
|
||||
_botService.AddTradingBotToCache(fBot);
|
||||
return Task.FromResult(fBot.GetStatus());
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ namespace Managing.Domain.Strategies
|
||||
|
||||
public void UpdateCandles(HashSet<Candle> newCandles)
|
||||
{
|
||||
if (newCandles == null || newCandles.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (Candles)
|
||||
{
|
||||
foreach (var item in newCandles.ToList())
|
||||
|
||||
@@ -8,10 +8,10 @@ import type {
|
||||
Time,
|
||||
UTCTimestamp,
|
||||
} from 'lightweight-charts'
|
||||
import { LineStyle, createChart, CrosshairMode } from 'lightweight-charts'
|
||||
import {LineStyle, createChart, CrosshairMode} from 'lightweight-charts'
|
||||
import moment from 'moment'
|
||||
import * as React from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import {useEffect, useRef, useState} from 'react'
|
||||
|
||||
import type {
|
||||
Candle,
|
||||
@@ -43,10 +43,10 @@ const TradeChart = ({
|
||||
stream,
|
||||
width,
|
||||
height,
|
||||
}: ITradeChartProps) => {
|
||||
}: ITradeChartProps) => {
|
||||
const chartRef = React.useRef<HTMLDivElement>(null)
|
||||
const chart = useRef<IChartApi>()
|
||||
const { themeProperty } = useTheme()
|
||||
const {themeProperty} = useTheme()
|
||||
const theme = themeProperty()
|
||||
const series1 = useRef<ISeriesApi<'Candlestick'>>()
|
||||
const [timeDiff, setTimeDiff] = useState<number>(0)
|
||||
@@ -159,7 +159,7 @@ const TradeChart = ({
|
||||
},
|
||||
height: height,
|
||||
layout: {
|
||||
background: { color: '#121212' },
|
||||
background: {color: '#121212'},
|
||||
textColor: theme.secondary,
|
||||
},
|
||||
localization: {
|
||||
@@ -207,6 +207,20 @@ const TradeChart = ({
|
||||
})
|
||||
|
||||
const data: CandlestickData[] = candles.map((c) => mapCandle(c))
|
||||
let diff = 0; // Default to 0 if there's not enough data to calculate the difference
|
||||
|
||||
console.log(data)
|
||||
console.log(data.length)
|
||||
|
||||
if (data.length > 3) {
|
||||
diff =
|
||||
(data[data.length - 1].time as number) -
|
||||
(data[data.length - 2].time as number);
|
||||
}
|
||||
|
||||
setTimeDiff(diff)
|
||||
setCandleCount(data.length)
|
||||
|
||||
series1.current.setData(data)
|
||||
series1.current.applyOptions({
|
||||
priceFormat: {
|
||||
@@ -216,11 +230,6 @@ const TradeChart = ({
|
||||
},
|
||||
})
|
||||
|
||||
const diff =
|
||||
(data[data.length - 2].time as number) -
|
||||
(data[data.length - 3].time as number)
|
||||
setTimeDiff(diff)
|
||||
setCandleCount(data.length)
|
||||
|
||||
const markers: SeriesMarker<Time>[] = []
|
||||
|
||||
@@ -268,7 +277,7 @@ const TradeChart = ({
|
||||
|
||||
if (walletBalances != null) {
|
||||
const walletSeries = chart.current.addBaselineSeries({
|
||||
baseValue: { price: walletBalances[0].value, type: 'price' },
|
||||
baseValue: {price: walletBalances[0].value, type: 'price'},
|
||||
bottomFillColor1: 'rgba( 239, 83, 80, 0.05)',
|
||||
bottomFillColor2: 'rgba( 239, 83, 80, 0.28)',
|
||||
bottomLineColor: 'rgba( 239, 83, 80, 1)',
|
||||
@@ -296,7 +305,7 @@ const TradeChart = ({
|
||||
}
|
||||
}
|
||||
|
||||
return <div ref={chartRef} />
|
||||
return <div ref={chartRef}/>
|
||||
}
|
||||
|
||||
export default TradeChart
|
||||
|
||||
Reference in New Issue
Block a user