public void Start(IExchangeWorker exchangeWorker, int limit)
        {
            ExchangeWorker = exchangeWorker;

            HttpClient = Exchange.GetHttpClient();

            Logger = LoggerFactory.CreateLogger($"Historian.{Exchange.Name}.Worker.TradeCatchup");

            using (Logger.BeginExchangeScope(Exchange.Name))
            {
                EnsureHistoricalTrades();

                BeginTradeCatchupWorker(limit);
            }
        }
Exemple #2
0
        public void Start(IExchangeWorker exchangeWorker) => Task.Run(async() =>
        {
            ExchangeWorker = exchangeWorker;

            if (Exchange.SupportedStatKeys == null)
            {
                return;
            }

            Logger = LoggerFactory.CreateLogger($"Historian.{Exchange.Name}.Worker.TradeStats");

            HttpClient = Exchange.GetHttpClient();

            using (Logger.BeginExchangeScope(Exchange.Name))
            {
                using (Logger.BeginProtocolScope("Https"))
                {
                    while (true)
                    {
                        if (!ExchangeWorker.Online)
                        {
                            await Task.Delay(1000);

                            continue;
                        }

                        var symbols = ExchangeWorker.Configuration.Symbol.Select(symbolCode => SymbolFactory.Get(symbolCode)).Where(s => s.Tradable);

                        foreach (var symbol in symbols)
                        {
                            using (Logger.BeginSymbolScope(symbol.Code))
                            {
                                foreach (var statsKey in Exchange.SupportedStatKeys)
                                {
                                    using (Logger.BeginExchangeStatsScope(statsKey))
                                    {
                                        await ReceiveTradeStatsHttp(symbol, statsKey);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
Exemple #3
0
 public static string GetFullUrl(this IExchangeHttpClient ex, string relativeUrl)
 {
     return(new Uri(new Uri(ex.ApiUrl), relativeUrl).ToString());
 }
Exemple #4
0
        public async Task <TradeResult> ReceiveTradesHttp(IStorageTransaction transaction, ILogger logger, ExchangeEnum exchange, ISymbol symbol, IExchangeHttpClient httpClient, int limit, string lastTradeFilter)
        {
            logger.LogInformation($"Requesting trades from filter '{lastTradeFilter}'");

            var response = await httpClient.GetTrades(symbol, limit, lastTradeFilter);

            var tradeResult = response.Data;

            if (response.StatusCode != WrappedResponseStatusCode.Ok)
            {
                var errorCode = !string.IsNullOrEmpty(response.ErrorCode) ? $"Error Code: {response.ErrorCode} Message: " : "";

                logger.LogWarning($"Unable to get trades: {errorCode}{response.ErrorMessage}");

                return(null);
            }

            if (tradeResult.Trades.Count > 0)
            {
                await AddTrades(transaction, logger, tradeResult);
            }

            return(tradeResult);
        }