Ejemplo n.º 1
0
        public SimExchange(Simulation sim, Exchange exch, PriceDataMap price_data)
        {
            try
            {
                Debug.Assert(Model.BackTesting == true);

                Sim       = sim;
                Exchange  = exch;
                PriceData = price_data;
                m_ord     = new LazyDictionary <long, Order>(k => null);
                m_his     = new LazyDictionary <long, OrderCompleted>(k => null);
                m_bal     = new LazyDictionary <Coin, AccountBalance>(k => new AccountBalance(k, 0m._(k)));
                m_depth   = new LazyDictionary <TradePair, MarketDepth>(k => new MarketDepth(k.Base, k.Quote));
                m_rng     = null;

                // Cache settings values
                m_order_value_range = SettingsData.Settings.BackTesting.OrderValueRange;
                m_spread_frac       = SettingsData.Settings.BackTesting.SpreadFrac;
                m_orders_per_book   = SettingsData.Settings.BackTesting.OrdersPerBook;

                Exchange.Sim = this;

                Reset();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Ejemplo n.º 2
0
        public Model(Func <IChartView> create_chart_cb)
        {
            try
            {
                Shutdown                = new CancellationTokenSource();
                Exchanges               = new ExchangeContainer();
                Coins                   = new CoinDataList();
                Funds                   = new FundContainer();
                Bots                    = new BotContainer(this);
                PriceData               = new PriceDataMap(Shutdown.Token);
                Charts                  = new ChartContainer(create_chart_cb);
                Indicators              = new IndicatorContainer();
                SelectedOpenOrders      = new ObservableCollection <Order>();
                SelectedCompletedOrders = new ObservableCollection <OrderCompleted>();
                SelectedTransfers       = new ObservableCollection <Transfer>();
                EditTradeContexts       = new List <EditTradeContext>();

                // Enable settings auto save after everything is up and running
                SettingsData.Settings.AutoSaveOnChanges = true;

                AllowTradesChanged += HandleAllowTradesChanged;
                BackTestingChange  += HandleBackTestingChange;
            }
            catch
            {
                Shutdown?.Cancel();
                Dispose();
                throw;
            }
        }
Ejemplo n.º 3
0
        public Simulation(IEnumerable <Exchange> exchanges, PriceDataMap price_data_map, BotContainer bots)
        {
            m_sw_main_loop = new Stopwatch();
            Exchanges      = new Dictionary <string, SimExchange>();
            PriceData      = price_data_map;
            Bots           = bots;

            // Create a SimExchange for each exchange
            Clock = StartTime;
            foreach (var exch in exchanges)
            {
                Exchanges[exch.Name] = new SimExchange(this, exch, price_data_map);
            }

            // Ensure the first update to the price data after creating the simulation
            // resets all instrument's cached data
            UpdatePriceData(force_invalidate: true);
        }