Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/mehtadone/TeleCoinigy
Browse files Browse the repository at this point in the history
  • Loading branch information
mehtadone committed Mar 2, 2018
2 parents de89c19 + e7234c3 commit 1a82ba0
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 152 deletions.
Expand Up @@ -44,7 +44,7 @@ public async Task Handle(TradeNotificationCommand command)
profitPercentage = tradesProfitResponse.ProfitPercentage;
btcProfit = tradesProfitResponse.BtcProfit;
dollarProfit = tradesProfitResponse.DollarProfit;
lastBought = tradesProfitResponse.LastBoughtTime + TimeSpan.FromHours(_config.TimeOffset);
lastBought = tradesProfitResponse.LastBoughtTime;
}

var sb = new StringBuffer();
Expand Down
5 changes: 5 additions & 0 deletions CryptoGramBot/Services/Exchanges/BinanceService.cs
Expand Up @@ -46,6 +46,11 @@ public async Task<BalanceInformation> GetBalance()
{
var accountInfo = await _binanceWebsocketService.GetAccountInfoAsync();

if(accountInfo == null)
{
throw new Exception("Account info not had get from binance");
}

balances = BinanceConverter.BinanceToWalletBalances(accountInfo.Balances);
}
catch (Exception e)
Expand Down
Expand Up @@ -23,6 +23,7 @@ public class BinanceCacheService : IBinanceCacheService
private readonly string SYMBOL_PRICE = "price_";

private readonly int CACHE_TIME_IN_MINUTES = 60;
private readonly int USER_CACHE_TIME_IN_HOURS = 23;

#endregion

Expand Down Expand Up @@ -50,7 +51,7 @@ public AccountInfo GetAccountInfo()

public void SetAccountInfo(AccountInfo accountInfo)
{
_memoryCache.Set(ACCOUNT_INFO_KEY, accountInfo, TimeSpan.FromMinutes(CACHE_TIME_IN_MINUTES));
_memoryCache.Set(ACCOUNT_INFO_KEY, accountInfo, TimeSpan.FromHours(USER_CACHE_TIME_IN_HOURS));
}

public ImmutableList<Order> GetOrders(string symbol)
Expand All @@ -60,7 +61,7 @@ public ImmutableList<Order> GetOrders(string symbol)

public void SetOrders(string symbol, ImmutableList<Order> orders)
{
_memoryCache.Set($"{symbol}{ORDERS_BY_SYMBOL_KEY}", orders, TimeSpan.FromMinutes(CACHE_TIME_IN_MINUTES));
_memoryCache.Set($"{symbol}{ORDERS_BY_SYMBOL_KEY}", orders, TimeSpan.FromHours(USER_CACHE_TIME_IN_HOURS));
}

public ImmutableList<AccountTrade> GetAccountTrades(string symbol)
Expand All @@ -70,7 +71,7 @@ public ImmutableList<AccountTrade> GetAccountTrades(string symbol)

public void SetAccountTrades(string symbol, ImmutableList<AccountTrade> trades)
{
_memoryCache.Set($"{symbol}{ACCOUNT_TRADES_BY_SYMBOL_KEY}", trades, TimeSpan.FromMinutes(CACHE_TIME_IN_MINUTES));
_memoryCache.Set($"{symbol}{ACCOUNT_TRADES_BY_SYMBOL_KEY}", trades, TimeSpan.FromHours(USER_CACHE_TIME_IN_HOURS));
}

public List<Symbol> GetSymbols()
Expand All @@ -83,6 +84,11 @@ public void SetSymbols(List<Symbol> symbols)
_memoryCache.Set(SYMBOLS, symbols, TimeSpan.FromMinutes(CACHE_TIME_IN_MINUTES));
}

public void ClearSymbols()
{
_memoryCache.Remove(SYMBOLS);
}

public ImmutableList<Candlestick> GetCandlesticks(string symbol, CandlestickInterval interval)
{
return _memoryCache.Get<ImmutableList<Candlestick>>($"{symbol}{SYMBOL_CANDLESTICK}{interval.AsString()}");
Expand Down

0 comments on commit 1a82ba0

Please sign in to comment.