private void OnTradeReceived(object sender, TradeEventArgs args) { try { DbRepositoryService dbRepo = null; var s = sender as BaseWebSocketExchange; if (s != null) { dbRepo = (DbRepositoryService)s.Log.DbRepository; } else { if (sender is BitstampExchange) { dbRepo = (DbRepositoryService)((BitstampExchange)sender).Log.DbRepository; } else { dbRepo = (DbRepositoryService)((BitmexExchange)sender).Log.DbRepository; } } dbRepo.SaveTrade(args); } catch (Exception ex) { _log.WriteError(String.Format("[{0}] {1} {2}", ex.GetType(), ex.Message, ex.StackTrace)); } }
public PricesPublisher(ServiceEventLogger log) { _restInstruments = new Dictionary <CurrencyName, Instrument>(); _restExchanges = new Dictionary <ExchangeName, BaseExchange>(); _wsExchanges = new Dictionary <ExchangeName, BaseExchange>(); _wsInstruments = new Dictionary <CurrencyName, Instrument>(); _dbGateway = (DbGatewayService)log.DbRepository; _dbRepo = new DbRepositoryService(); _restSubscriber = new RestExchangeListener(_dbGateway, log); _tcp = new TcpService(); _log = log; Instrument.InitWebsocketInstruments(_wsInstruments); Instrument.InitRestInstruments(_restInstruments); _restSubscriber.ExchangePricesUpdate += RestRequestHandler; }
public VwapIndicator(ServiceEventLogger log) { _initTimers = new Dictionary <int, Timer>(); _timers = new Dictionary <int, Timer>(); _frames = new Dictionary <int, List <DateTime> >(); _dbRepo = (DbRepositoryService)log.DbRepository; _log = log; Periods = new Tuple <int, string>[] { new Tuple <int, string>(3, "3m") //new Tuple<int, string>(5, "5m"), //new Tuple<int, string>(15, "15m"), //new Tuple<int, string>(30, "30m"), //new Tuple<int, string>(45, "45m"), //new Tuple<int, string>(60, "1h"), //new Tuple<int, string>(120, "2h"), //new Tuple<int, string>(240, "4h"), //new Tuple<int, string>(480, "8h") }; }
public SpreadIOTA(MatchingEngine matching, DbRepositoryService dbRepo) { _dbRepo = dbRepo; matching.BTC += (s, e) => { if (e.Exchange == ExchangeName.Binance) { btcBinance[0] = e.BidPrice; btcBinance[1] = e.AskPrice; binanceFee = e.TradingFee; } else if (e.Exchange == ExchangeName.OkEx) { btcOkex[0] = e.BidPrice; btcOkex[1] = e.AskPrice; okexFee = e.TradingFee; } SaveSpreadOkexBinance(); }; matching.IOTA += (s, e) => { if (e.Exchange == ExchangeName.Binance) { iotaBinance[0] = e.BidPrice; iotaBinance[1] = e.AskPrice; binanceFee = e.TradingFee; } else if (e.Exchange == ExchangeName.OkEx) { if (e.Instrument2 == CurrencyName.USDT) { iotaOkex[0] = e.BidPrice; iotaOkex[1] = e.AskPrice; okexFee = e.TradingFee; } } SaveSpreadOkexBinance(); }; }
public SpreadMono(MatchingEngine matching, DbRepositoryService dbRepo, ExchangeName exchange) { _dbRepo = dbRepo; matching.BTC += (s, e) => { if (e.Exchange == exchange) { btc[0] = e.BidPrice; btc[1] = e.AskPrice; tradingFee = e.TradingFee; } SaveSpread(); }; matching.IOTA += (s, e) => { if (e.Exchange == exchange) { if (e.Instrument2 == CurrencyName.Undefined) { throw new InvalidOperationException("SpreadMono"); } if (e.Instrument2 == CurrencyName.BTC) { iotaBtc[0] = e.BidPrice; iotaBtc[1] = e.AskPrice; } else if (e.Instrument2 == CurrencyName.USDT) { iotaUsd[0] = e.BidPrice; iotaUsd[1] = e.AskPrice; } tradingFee = e.TradingFee; } SaveSpread(); }; }
public InstrumentSpreadBTC(MatchingEngine matching, DbRepositoryService dbRepo) { _dbRepo = dbRepo; matching.BTC += (s, e) => { if (e.Exchange == ExchangeName.Binance) { ex1[0] = e.BidPrice; ex1[1] = e.AskPrice; } else if (e.Exchange == ExchangeName.HitBtc) { ex2[0] = e.BidPrice; ex2[1] = e.AskPrice; } else { return; } SaveSpread(); }; }
public InstrumentSpread(MatchingEngine matching, DbRepositoryService dbRepo) { _dbRepo = dbRepo; matching.XRP += (s, e) => { if (e.Instrument2 == CurrencyName.ETH) { xrp[0] = e.BidPrice; xrp[1] = e.AskPrice; } SaveSpreadOkexBinance(); }; matching.DASH += (s, e) => { if (e.Instrument2 == CurrencyName.ETH) { dash[0] = e.BidPrice; dash[1] = e.AskPrice; } SaveSpreadOkexBinance(); }; }
public MatchingEngine(ServiceEventLogger log, MessageHandling msgHandling) { _singleInstrument = new CancellationPattern(); _manyInstruments = new CancellationPattern(); _orderPlacement = new OrderPlacement(); _cancelMonitoring = new CancellationPattern(); _wsExchanges = new Dictionary <ExchangeName, BaseExchange>(); _exchanges = new Dictionary <ExchangeName, IExchange>(); _profitRatios = new Dictionary <ExchangeName, double>(); _instruments = new Dictionary <CurrencyName, Instrument>(); _wsInstruments = new Dictionary <CurrencyName, Instrument>(); _balance = new BalanceManagement(); _matchingEvent = new AutoResetEvent(false); _stopEvent1 = new AutoResetEvent(false); _stopEvent2 = new AutoResetEvent(false); _bittrex = new BittrexArbitrage(log); _orderBook = new OrderBook(); _obj = new object(); _dbRepo = (DbRepositoryService)log.DbRepository; _syncService = new SyncBalanceService(log); _msgHandling = msgHandling; _log = log; Instrument.InitWebsocketInstruments(_wsInstruments); _instruments.Add(CurrencyName.BTC, new InstrumentBTC()); _instruments.Add(CurrencyName.BCH, new InstrumentBCH()); _instruments.Add(CurrencyName.LTC, new InstrumentLTC()); _instruments.Add(CurrencyName.ETH, new InstrumentETH()); _instruments.Add(CurrencyName.XRP, new InstrumentXRP()); _instruments.Add(CurrencyName.DSH, new InstrumentDASH()); _instruments.Add(CurrencyName.IOTA, new InstrumentIOTA()); _spreadMono = new SpreadMono(this, _dbRepo, ExchangeName.OkEx); _spreadIota = new SpreadIOTA(this, _dbRepo); _spread = new InstrumentSpreadBTC(this, _dbRepo); }
public MessageHandling(ServiceEventLogger log, RestScheduler scheduler) { DbRepository = new DbRepositoryService(); _restScheduler = scheduler; _log = log; }