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