示例#1
0
        protected ExchangeEngine(MessagePump messagePump)
        {
            m_MessagePump = messagePump ?? throw new ArgumentNullException(nameof(messagePump));

            m_Balances   = new ConcurrentDictionary <String, Decimal>();
            m_OrderBooks = new ConcurrentDictionary <String, SortedOrderBook>();
            m_Trades     = new List <Trade>();
        }
示例#2
0
        public static ExchangeEngine FromConfiguration(MessagePump messagePump)
        {
            switch (Config.Exchange)
            {
            case Exchange.Binance:
                return(new BinanceEngine(messagePump));

            default:
                throw new InvalidOperationException(Resources.InvalidConfigurationExchange);
            }
        }
示例#3
0
        public TradingEngine(MessagePump messagePump, ExchangeEngine exchangeEngine)
        {
            m_MessagePump    = messagePump ?? throw new ArgumentNullException(nameof(messagePump));
            m_ExchangeEngine = exchangeEngine ?? throw new ArgumentNullException(nameof(exchangeEngine));

            if (!m_ExchangeEngine.Initialized)
            {
                throw new Exception(Resources.EngineNotInitialized);
            }

            m_Arbitrages       = new BlockingCollection <Arbitrage>(new ConcurrentQueue <Arbitrage>());
            m_Executions       = new Dictionary <DateTime, Execution>();
            m_ExecutionSymbols = new HashSet <String>();
            m_CycleDurations   = new List <Int32>();

            String session      = Utilities.FormatMessage(Resources.TradingSession, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
            String sessionFrame = new String('*', session.Length);

            m_MessagePump.Signal(sessionFrame);
            m_MessagePump.Signal(session);
            m_MessagePump.Signal(sessionFrame);

            m_Consumer = Task.Factory.StartNew(() =>
            {
                foreach (Arbitrage arbitrage in m_Arbitrages.GetConsumingEnumerable())
                {
                    Task.Run(() => ExecuteArbitrage(arbitrage));
                }
            },
                                               CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);

            m_Producer = Task.Factory.StartNew(() =>
            {
                Thread.Sleep(Config.TradingCyclesDelay * 10);

                while (!m_Arbitrages.IsCompleted)
                {
                    Task.Run(() => DetectArbitrages());
                    Thread.Sleep(Config.TradingCyclesDelay);
                }
            },
                                               CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
示例#4
0
 public BinanceEngine(MessagePump messagePump) : base(messagePump)
 {
     m_Api             = new BinanceApi();
     m_OrderBooksCache = new Dictionary <String, DepthWebSocketCache>();
 }