Postgres (#30)

* Add postgres

* Migrate users

* Migrate geneticRequest

* Try to fix Concurrent call

* Fix asyncawait

* Fix async and concurrent

* Migrate backtests

* Add cache for user by address

* Fix backtest migration

* Fix not open connection

* Fix backtest command error

* Fix concurrent

* Fix all concurrency

* Migrate TradingRepo

* Fix scenarios

* Migrate statistic repo

* Save botbackup

* Add settings et moneymanagement

* Add bot postgres

* fix a bit more backups

* Fix bot model

* Fix loading backup

* Remove cache market for read positions

* Add workers to postgre

* Fix workers api

* Reduce get Accounts for workers

* Migrate synth to postgre

* Fix backtest saved

* Remove mongodb

* botservice decorrelation

* Fix tradingbot scope call

* fix tradingbot

* fix concurrent

* Fix scope for genetics

* Fix account over requesting

* Fix bundle backtest worker

* fix a lot of things

* fix tab backtest

* Remove optimized moneymanagement

* Add light signal to not use User and too much property

* Make money management lighter

* insert indicators to awaitable

* Migrate add strategies to await

* Refactor scenario and indicator retrieval to use asynchronous methods throughout the application

* add more async await

* Add services

* Fix and clean

* Fix bot a bit

* Fix bot and add message for cooldown

* Remove fees

* Add script to deploy db

* Update dfeeploy script

* fix script

* Add idempotent script and backup

* finish script migration

* Fix did user and agent name on start bot
This commit is contained in:
Oda
2025-07-27 15:42:17 +02:00
committed by GitHub
parent 361bfbf6e8
commit 422fecea7b
294 changed files with 23953 additions and 7272 deletions

View File

@@ -100,9 +100,18 @@ public class AccountService : IAccountService
public async Task<Account> GetAccount(string name, bool hideSecrets, bool getBalance)
{
var account = await _accountRepository.GetAccountByNameAsync(name);
if (account == null)
{
throw new ArgumentException($"Account '{name}' not found");
}
ManageProperties(hideSecrets, getBalance, account);
account.User = await _userRepository.GetUserByNameAsync(account.User.Name);
if (account.User == null && account.User != null)
{
account.User = await _userRepository.GetUserByNameAsync(account.User.Name);
}
return account;
}
@@ -123,9 +132,31 @@ public class AccountService : IAccountService
return account;
}
public IEnumerable<Account> GetAccounts(bool hideSecrets, bool getBalance)
public async Task<Account> GetAccountByAccountName(string accountName, bool hideSecrets = true,
bool getBalance = false)
{
var result = _accountRepository.GetAccounts();
var account = await _accountRepository.GetAccountByNameAsync(accountName);
if (account != null)
{
ManageProperties(hideSecrets, getBalance, account);
if (account.User != null)
{
account.User = await _userRepository.GetUserByNameAsync(account.User.Name);
}
}
return account;
}
public async Task<IEnumerable<Account>> GetAccounts(bool hideSecrets, bool getBalance)
{
return await GetAccountsAsync(hideSecrets, getBalance);
}
public async Task<IEnumerable<Account>> GetAccountsAsync(bool hideSecrets, bool getBalance)
{
var result = await _accountRepository.GetAccountsAsync();
var accounts = new List<Account>();
foreach (var account in result)
@@ -139,15 +170,21 @@ public class AccountService : IAccountService
public IEnumerable<Account> GetAccountsByUser(User user, bool hideSecrets = true)
{
var cacheKey = $"user-account-{user.Name}";
return _cacheService.GetOrSave(cacheKey, () => { return GetAccounts(user, hideSecrets, false); },
TimeSpan.FromMinutes(5));
return GetAccountsByUserAsync(user, hideSecrets).Result;
}
private IEnumerable<Account> GetAccounts(User user, bool hideSecrets, bool getBalance)
public async Task<IEnumerable<Account>> GetAccountsByUserAsync(User user, bool hideSecrets = true)
{
var result = _accountRepository.GetAccounts();
var cacheKey = $"user-account-{user.Name}";
// For now, we'll get fresh data since caching async operations requires more complex logic
// This can be optimized later with proper async caching
return await GetAccountsAsync(user, hideSecrets, false);
}
private async Task<IEnumerable<Account>> GetAccountsAsync(User user, bool hideSecrets, bool getBalance)
{
var result = await _accountRepository.GetAccountsAsync();
var accounts = new List<Account>();
foreach (var account in result.Where(a => a.User.Name == user.Name))
@@ -161,11 +198,16 @@ public class AccountService : IAccountService
public IEnumerable<Account> GetAccountsBalancesByUser(User user, bool hideSecrets)
{
var cacheKey = $"user-account-balance-{user.Name}";
var accounts = _cacheService.GetOrSave(cacheKey, () => { return GetAccounts(user, true, true); },
TimeSpan.FromHours(3));
return GetAccountsBalancesByUserAsync(user, hideSecrets).Result;
}
return accounts;
public async Task<IEnumerable<Account>> GetAccountsBalancesByUserAsync(User user, bool hideSecrets)
{
var cacheKey = $"user-account-balance-{user.Name}";
// For now, get fresh data since caching async operations requires more complex logic
// This can be optimized later with proper async caching
return await GetAccountsAsync(user, hideSecrets, true);
}
public async Task<GmxClaimableSummary> GetGmxClaimableSummaryAsync(User user, string accountName)
@@ -200,7 +242,8 @@ public class AccountService : IAccountService
}
}
public async Task<SwapInfos> SwapGmxTokensAsync(User user, string accountName, Ticker fromTicker, Ticker toTicker, double amount, string orderType = "market", double? triggerRatio = null, double allowedSlippage = 0.5)
public async Task<SwapInfos> SwapGmxTokensAsync(User user, string accountName, Ticker fromTicker, Ticker toTicker,
double amount, string orderType = "market", double? triggerRatio = null, double allowedSlippage = 0.5)
{
// Get the account for the user
var account = await GetAccountByUser(user, accountName, true, false);
@@ -220,12 +263,12 @@ public class AccountService : IAccountService
{
// Call the Web3ProxyService to swap GMX tokens
var swapInfos = await _web3ProxyService.SwapGmxTokensAsync(
account.Key,
fromTicker,
toTicker,
amount,
orderType,
triggerRatio,
account.Key,
fromTicker,
toTicker,
amount,
orderType,
triggerRatio,
allowedSlippage
);
@@ -239,7 +282,8 @@ public class AccountService : IAccountService
}
}
public async Task<SwapInfos> SendTokenAsync(User user, string accountName, string recipientAddress, Ticker ticker, decimal amount, int? chainId = null)
public async Task<SwapInfos> SendTokenAsync(User user, string accountName, string recipientAddress, Ticker ticker,
decimal amount, int? chainId = null)
{
// Get the account for the user
var account = await GetAccountByUser(user, accountName, true, false);
@@ -271,10 +315,10 @@ public class AccountService : IAccountService
{
// Call the Web3ProxyService to send tokens
var swapInfos = await _web3ProxyService.SendTokenAsync(
account.Key,
recipientAddress,
ticker,
amount,
account.Key,
recipientAddress,
ticker,
amount,
chainId
);