Fix bot launch errors

This commit is contained in:
2024-06-26 19:14:32 +07:00
parent c25752c670
commit fb976d231a
13 changed files with 54 additions and 50 deletions

View File

@@ -32,13 +32,13 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Update="appsettings.Lowpro.json"> <Content Update="appsettings.Oda.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Update="appsettings.json"> <Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Update="appsettings.Oda-docker.json"> <Content Update="appsettings.Prod.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>

View File

@@ -14,8 +14,9 @@ using Serilog.Sinks.Elasticsearch;
// Builder // Builder
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Configuration builder.Configuration.SetBasePath(System.AppContext.BaseDirectory);
.AddEnvironmentVariables(); builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json");
builder.Host.UseSerilog((hostBuilder, loggerConfiguration) => builder.Host.UseSerilog((hostBuilder, loggerConfiguration) =>
{ {

View File

@@ -5,8 +5,8 @@
}, },
"InfluxDb": { "InfluxDb": {
"Url": "http://influxdb:8086/", "Url": "http://influxdb:8086/",
"Organization": "", "Organization": "managing-org",
"Token": "" "Token": "Fw2FPL2OwTzDHzSbR2Sd5xs0EKQYy00Q-hYKYAhr9cC1_q5YySONpxuf_Ck0PTjyUiF13xXmi__bu_pXH-H9zA=="
}, },
"Serilog": { "Serilog": {
"MinimumLevel": { "MinimumLevel": {

View File

@@ -1,7 +1,7 @@
{ {
"ManagingDatabase": { "ManagingDatabase": {
"ConnectionString": "mongodb://localhost:27017", "ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "ManagingDb", "DatabaseName": "ManagingDb"
}, },
"InfluxDb": { "InfluxDb": {
"Url": "http://localhost:8086/", "Url": "http://localhost:8086/",

View File

@@ -8,7 +8,7 @@
"InfluxDb": { "InfluxDb": {
"Url": "http://influxdb:8086/", "Url": "http://influxdb:8086/",
"Organization": "managing-org", "Organization": "managing-org",
"Token": "" "Token": "Fw2FPL2OwTzDHzSbR2Sd5xs0EKQYy00Q-hYKYAhr9cC1_q5YySONpxuf_Ck0PTjyUiF13xXmi__bu_pXH-H9zA=="
}, },
"Serilog": { "Serilog": {
"MinimumLevel": { "MinimumLevel": {

View File

@@ -99,7 +99,15 @@ public class TradingBot : Bot, ITradingBot
LoadScenario(); LoadScenario();
await PreloadCandles(); await PreloadCandles();
await CancelAllOrders(); await CancelAllOrders();
try
{
await MessengerService.SendMessage($"Hi everyone, I'm going to run {Name}. \nI will send a message here everytime a signal is triggered by the {string.Join(",", Strategies.Select(s => s.Name))} strategies."); await MessengerService.SendMessage($"Hi everyone, I'm going to run {Name}. \nI will send a message here everytime a signal is triggered by the {string.Join(",", Strategies.Select(s => s.Name))} strategies.");
}
catch (Exception ex)
{
Logger.LogError(ex, ex.Message);
}
await InitWorker(Run); await InitWorker(Run);
} }
@@ -553,7 +561,7 @@ public class TradingBot : Bot, ITradingBot
private async Task CancelAllOrders() private async Task CancelAllOrders()
{ {
if (!IsForBacktest) if (!IsForBacktest && !IsForWatchingOnly)
{ {
try try
{ {

View File

@@ -2,21 +2,16 @@
using MediatR; using MediatR;
using static Managing.Common.Enums; using static Managing.Common.Enums;
using Managing.Application.Abstractions; using Managing.Application.Abstractions;
using Managing.Application.ManageBot.Commands;
using Managing.Domain.MoneyManagements;
namespace Managing.Application.ManageBot namespace Managing.Application.ManageBot
{ {
public class BackupBotCommandHandler : IRequestHandler<BackupBotCommand, bool> public class BackupBotCommandHandler : IRequestHandler<BackupBotCommand, bool>
{ {
private readonly IBotFactory _botFactory;
private readonly ITaskCache _taskCache; private readonly ITaskCache _taskCache;
private readonly IMoneyManagementService _moneyManagementService;
private readonly IBotService _botService; private readonly IBotService _botService;
public BackupBotCommandHandler(IBotFactory botFactory, ITaskCache taskCache, IBotService botService) public BackupBotCommandHandler(ITaskCache taskCache, IBotService botService)
{ {
_botFactory = botFactory;
_taskCache = taskCache; _taskCache = taskCache;
_botService = botService; _botService = botService;
} }

View File

@@ -1,6 +1,4 @@
using Managing.Application.Abstractions; using Managing.Application.Abstractions;
using Newtonsoft.Json;
using System.IO;
namespace Managing.Application.ManageBot namespace Managing.Application.ManageBot
{ {

View File

@@ -206,7 +206,7 @@ public class TradingService : ITradingService
return _cacheService.GetOrSave($"Fee-{account.Exchange}", () => return _cacheService.GetOrSave($"Fee-{account.Exchange}", () =>
{ {
return _tradingRepository.GetFee(TradingExchanges.Evm).Cost; return _tradingRepository.GetFee(TradingExchanges.Evm)?.Cost ?? 0m;
}, TimeSpan.FromHours(2)); }, TimeSpan.FromHours(2));
} }

View File

@@ -4,9 +4,9 @@ version: '3.4'
services: services:
managing.api: managing.api:
environment: environment:
- ASPNETCORE_ENVIRONMENT=oda-docker - ASPNETCORE_ENVIRONMENT=Oda-docker
- ASPNETCORE_URLS=https://+:443;http://+:80 - ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_Kestrel__Certificates__Default__Password=!MotdepasseFort11 - ASPNETCORE_Kestrel__Certificates__Default__Password=!Managing94
- ASPNETCORE_Kestrel__Certificates__Default__Path=/app/managing_cert.pfx - ASPNETCORE_Kestrel__Certificates__Default__Path=/app/managing_cert.pfx
ports: ports:
- "80:80" - "80:80"
@@ -14,20 +14,23 @@ services:
volumes: volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
- /Users/oda/ASP.NET/Https:/root/.aspnet/https:ro
- /Users/oda/Microsoft/UserSecrets:/root/.microsoft/usersecrets/$USER_SECRETS_ID
depends_on: depends_on:
- managingdb - managingdb
managing.api.workers: managing.api.workers:
environment: environment:
- ASPNETCORE_ENVIRONMENT=oda-docker - ASPNETCORE_ENVIRONMENT=Oda-docker
- ASPNETCORE_URLS=https://+:443;http://+:80 - ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_Kestrel__Certificates__Default__Password=!MotdepasseFort11 - ASPNETCORE_Kestrel__Certificates__Default__Password=!Managing94
- ASPNETCORE_Kestrel__Certificates__Default__Path=/app/managing_cert.pfx - ASPNETCORE_Kestrel__Certificates__Default__Path=/app/managing_cert.pfx
ports: ports:
- "81:80" - "81:80"
- "444:443" - "444:443"
volumes: volumes:
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
- /Users/oda/ASP.NET/Https:/root/.aspnet/https:ro
depends_on: depends_on:
- managingdb - managingdb
@@ -38,24 +41,24 @@ services:
ports: ports:
- "27017:27017" - "27017:27017"
elasticsearch: # elasticsearch:
ports: # ports:
- 9200:9200 # - 9200:9200
volumes: # volumes:
- elasticsearch-data:/usr/share/elasticsearch/data # - elasticsearch-data:/usr/share/elasticsearch/data
environment: # environment:
- discovery.type=single-node # - discovery.type=single-node
- xpack.monitoring.templates.enabled=true # - xpack.monitoring.templates.enabled=true
- ES_JAVA_OPTS=-Xms1g -Xmx1g # - ES_JAVA_OPTS=-Xms1g -Xmx1g
- xpack.security.enabled=false # - xpack.security.enabled=false
kibana: # kibana:
ports: # ports:
- 5601:5601 # - 5601:5601
depends_on: # depends_on:
- elasticsearch # - elasticsearch
environment: # environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200 # - ELASTICSEARCH_URL=http://elasticsearch:9200
influxdb: influxdb:
image: influxdb:latest image: influxdb:latest

View File

@@ -22,13 +22,13 @@ services:
networks: networks:
- managing-network - managing-network
elasticsearch: # elasticsearch:
image: elasticsearch:8.4.1 # image: elasticsearch:8.4.1
networks: # networks:
- managing-network # - managing-network
kibana: # kibana:
image: kibana:8.4.1 # image: kibana:8.4.1
influxdb: influxdb:
image: influxdb:latest image: influxdb:latest

View File

@@ -1,5 +1,4 @@
using Managing.Domain.Bots; using Managing.Infrastructure.Databases.MongoDb;
using Managing.Infrastructure.Databases.MongoDb;
using Managing.Infrastructure.Databases.MongoDb.Abstractions; using Managing.Infrastructure.Databases.MongoDb.Abstractions;
using Managing.Infrastructure.Databases.MongoDb.Collections; using Managing.Infrastructure.Databases.MongoDb.Collections;
@@ -27,7 +26,7 @@ public class BotRepository : IBotRepository
public async Task UpdateBackupBot(BotBackup bot) public async Task UpdateBackupBot(BotBackup bot)
{ {
var b = _botRepository.FindOne(b => b.Name == bot.Name); var b = await _botRepository.FindOneAsync(b => b.Name == bot.Name);
var dto = MongoMappers.Map(bot); var dto = MongoMappers.Map(bot);
dto.Id = b.Id; dto.Id = b.Id;
_botRepository.Update(dto); _botRepository.Update(dto);

View File

@@ -1,4 +1,4 @@
VITE_API_URL_LOCAL=https://localhost:5001 VITE_API_URL_LOCAL=https://localhost:443
VITE_API_URL_SERVER=https://dev-managing-api.apps.managing.live VITE_API_URL_SERVER=https://dev-managing-api.apps.managing.live
VITE_WORKER_URL_LOCAL=https://localhost:5002 VITE_WORKER_URL_LOCAL=https://localhost:5002
VITE_WORKER_URL_SERVER=https://dev-managing-worker.apps.managing.live VITE_WORKER_URL_SERVER=https://dev-managing-worker.apps.managing.live