public CBfxStockStor(IClientBfxStockStor client, string instrument, int decimalVolume,
                             int stockDept, List <int> lstPrecissions)
        {
            _client = client;

            _store     = new Dictionary <int, Dictionary <Direction, List <CBfxStockRec> > >();
            _stockDept = stockDept;

            foreach (var prec in lstPrecissions)
            {
                _store[prec] = new Dictionary <Direction, List <CBfxStockRec> >();
                _store[prec][Direction.Up]   = new List <CBfxStockRec>();
                _store[prec][Direction.Down] = new List <CBfxStockRec>();
                _dictLogger[prec]            = new CLogger(String.Format("{0}_p{1}", instrument, prec),
                                                           flushMode: true, subDir: "StockStor");
            }
            _instrument = instrument;
            _logger     = new CLogger(instrument, flushMode: false, subDir: "StockStor");

            _outStock      = new CSharedStocks(_client);
            _decimalVolume = decimalVolume;


            CUtil.ThreadStart(ThreadMain);


            _perf = new CPerfStockStor(true, instrument, lstPrecissions);
        }
Esempio n. 2
0
 //Added 2017-24-11 for updating stock from native connector
 /// <summary>
 /// Call from
 /// CPlaza2Connector
 /// </summary>
 /// <param name="instrument"></param>
 /// <param name="sourceStock"></param>
 public void UpdateStockFromNative(string instrument, ref CSharedStocks sourceStock)
 {
     if (m_stocksStructDict.ContainsKey(instrument))
     {
         m_stocksStructDict[instrument].StockConverterP2.UpdateStocksFromNative(instrument, ref sourceStock);
     }
 }
Esempio n. 3
0
 public void UpdateInpStocksOneDir(string isin, ref CSharedStocks sourceStock, Direction dir,
                                   int precision)
 {
     if (!_inpStocks[isin].CopyStocksOneDir(ref sourceStock, dir, precision))
     {
         Error("Unable copy stock one");
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Copy data from sourceStock to _inpStocks
 ///
 /// Call from:
 /// StockConverter.ThreadStockConverter (old)
 /// P2StockConverterP2.UpdateStocksFromNative
 /// </summary>
 public void  UpdateInpStocksBothDir(string isin, ref CSharedStocks sourceStock,
                                     int precision)
 {
     if (!_inpStocks[isin].CopyStocksBothDir(ref sourceStock, precision))
     {
         Error("Unable copy stock both dir");
     }
 }
 public CBaseStockConverter(int stockDept, string isin, IClientStockConverter client)
 {
     _stockDepth = stockDept;
     Instrument  = isin;
     _client     = client;
     m_dirStock  = new CSharedStocks(_client);
     m_logger    = new CLogger("StockConverter_" + Instrument, flushMode: true, subDir: "StockConverters", useMicroseconds: false);
 }
Esempio n. 6
0
        /// <summary>
        /// Added 2017-11-24 native update stocks - directly
        /// Call from CStockBox.UpdateStockFromNative
        /// </summary>
        public void UpdateStocksFromNative(string instrument, ref CSharedStocks sourceStock)
        {
            _bidInternal = sourceStock.Bid;
            _askInternal = sourceStock.Ask;

            UpdateBidAsk(_bidInternal, _askInternal);

            _client.SnapshoterStock.UpdateInpStocksBothDir(instrument, ref sourceStock, precision: 0);

            //  _client.SnapshoterStock.UpdateOutStock(instrument, bDoNotUpdateTraders:false);
            _client.UserDealsPosBox.RefreshBotPos(Instrument);
        }
Esempio n. 7
0
        public CStockConverterP2(int stockDept, string isin, IClientStockConverter client)
            : base(stockDept, isin, client)
        {
            InpSnapshotRawStocks = new CRawStock[stockDept];
            m_dirStock           = new CSharedStocks(client);

            for (int i = 0; i < _stockDepth; i++)
            {
                InpSnapshotRawStocks[i] = new CRawStock();
            }

            (new Thread(ThreadStockConverter)).Start();
        }
Esempio n. 8
0
        public void Test()
        {
            //CSnapshoterStock snapshoterStock = new

            _snapshoterStockSmart = new CSnapshoterStockSmart(this, "StockSnapshoter",
                                                              stockDept: _stockDepth,
                                                              updateInterval: 100);

            _lstPrecissions = GetPricePrecisions();


            _stockSimulate = new CSharedStocks(_stockDepth, _lstPrecissions);
            GenerateStockHist();
        }
Esempio n. 9
0
        public CStockConverter(int stockDept, string isin, CPlaza2Connector plaza2Connector)
        {
            _stockDepth       = stockDept;
            Isin              = isin;
            m_plaza2Connector = plaza2Connector;

            InpRawStocks = new CRawStock[stockDept];
            m_dirStock   = new CSharedStocks(stockDept);

            for (int i = 0; i < _stockDepth; i++)
            {
                InpRawStocks[i] = new CRawStock();
            }

            (new Thread(ThreadStockConverter)).Start();
        }
Esempio n. 10
0
        public CSnapshoterStock(IClientSnapshoter client, string nameUpdater, int stockDept, int updateInterval) :
            base(client, nameUpdater, updateInterval)
        {
            _client = client;

            foreach (KeyValuePair <string, long> kvp in client.Instruments.DictInstrument_IsinId)
            {
                string isin = kvp.Key;


                _inpStocks[isin]  = new CSharedStocks(_client);
                _outpStocks[isin] = new CSharedStocks(_client);
                _dtLastUpdateNotTradingTime[isin] = DateTime.Now;
            }

            (new Thread(ThreadFunc)).Start();
        }
        public void UpdateCryptoStockConverterOneDir(CSharedStocks sourceStock, Direction dir, int precision)
        {
            if (precision == 0)
            {
                _bidInternal = sourceStock.Bid;
                _askInternal = sourceStock.Ask;

                UpdateBidAsk(_bidInternal, _askInternal);
                //TODO check if decimals changed



                UpdatePriceDecimalsAndMinStep(sourceStock);
            }

            _client.SnapshoterStock.UpdateInpStocksOneDir(Instrument, ref sourceStock, dir, precision);

            _client.UserDealsPosBox.RefreshBotPos(Instrument);
        }
Esempio n. 12
0
        /// <summary>
        /// 1)Copy to _outpStocks from _inpStocks
        /// 2) Trigger update.
        ///
        /// 2.1 Update Bot's stocks - in every case call (see "call from")
        /// 2.2 Update trader's stock only periodically
        ///
        ///
        /// Call from
        /// - StockDispatcher.UpdateAlgorithm - periodically update
        /// - StockProcessor.ThreadStockConverter - update if bid/ask changed
        /// </summary>
        public void UpdateOutStock(string isin, bool bDoNotUpdateTraders)
        {
            CSharedStocks ss = _inpStocks[isin];

            if (!_outpStocks[isin].CopyStocksFull(ref ss))
            {
                Error("Unable update outstock");
            }
            else //was copied successfull
            {
                //trigger all bots for update specific stock - 2018-01-11 moved
                //TriggerBotsStockUpdate(isin);
                if (!bDoNotUpdateTraders)
                {
                    if (_plaza2Connector.GlobalConfig.IsTradingServer)
                    {
                        //2018-01-11 moved here for optimisation reasons
                        TriggerBotsStockUpdate(isin);
                        TriggerTradersStocksUpdate(isin); //trigger stock dispacher update trader's stocks
                    }
                }
            }
        }
        /*
         * public bool IsOrderFromPrevSession(CRawUserDeal rd)
         * {
         *   try
         *   {
         *       long OrderId = 0;
         *
         *       if (rd.Ext_id_buy != 0)
         *           OrderId = rd.Id_ord_buy;
         *       else if (rd.Ext_id_sell != 0)
         *           OrderId = rd.Id_ord_sell;
         *
         *
         *       string isin = Instruments.GetInstrumentByIsinId(rd.Isin_Id); //DictIsin_id[rd.Isin_Id];
         *
         *       UserOrderBox.mxListRawOrders.WaitOne();
         *
         *       foreach (CRawOrdersLogStruct rols in UserOrderBox.ListRawOrdersStruct)
         *           if (rols.Id_ord == OrderId && rols.Moment < SessionBox.CurrentSession.SessionBegin)
         *           {
         *               UserOrderBox.mxListRawOrders.ReleaseMutex();
         *               return true;
         *
         *           }
         *
         *
         *       UserOrderBox.mxListRawOrders.ReleaseMutex();
         *   }
         *   catch (Exception e)
         *   {
         *       Error("IsOrderFromPrevSession", e);
         *   }
         *
         *
         *   return false; ;
         * }
         */



        /// <summary>
        /// Call from native
        /// </summary>
        /// <param name="isinId"></param>
        /// <param name="sourceStock"></param>
        public void UpdateInpStocks(long isinId, ref CSharedStocks sourceStock)
        {
            string instrument = Instruments.GetInstrumentByIsinId(isinId);

            //TODO normal
            while (SnapshoterStock == null)
            {
                Thread.Sleep(100);
            }

            if (instrument != "")
            {
                //	 SnapshoterStock.UpdateInpStocks(instrument, ref sourceStock);

                StockBoxP2.UpdateStockFromNative(instrument, ref sourceStock);
            }

            EvStockOnline.Set();
            //var s = StockBoxInp.S

            // if (stockConv != null)
            //   Thread.Sleep(0);
        }
Esempio n. 14
0
        /// <summary>
        /// Specific algorithm for periodically update traders stock
        /// </summary>
        /// <param name="isin"></param>
        protected override void UpdateAlgorithm(string isin)
        {
            if (IsTimeToUpdate(isin))
            {
                CSharedStocks inpStk = _inpStocks[isin];


                if ((_plaza2Connector.IsSessionOnline && _plaza2Connector.UseRealServer) ||
                    !_plaza2Connector.UseRealServer)

                {
                    if (inpStk.IsStocksDifferent(_outpStocks[isin]) ||                               //stock changed from last update
                        !_plaza2Connector.IsSessionActive && IsTimeToUpdateNotOnTradingTime(isin) || // time to update when session not active
                        !_plaza2Connector.UseRealServer && _plaza2Connector.IsStockOnline            //demo server and stock online
                        )
                    {
                        UpdateOutStock(isin, bDoNotUpdateTraders: false);
                        UpdateDate(isin);
                        UpdateNotTradingTimeDate(isin);
                    }
                }
            }
        }
 public void UpdateClientStockOneDir(string instrument, Direction dir, int precision,
                                     CSharedStocks stock)
 {
     _client.UpdateStockOneDir(instrument, dir, precision, stock);
 }
 public CP2StockReaderNative(IP2ConnectorNativeClient dealingServer, IP2StockReaderNativeClient client)
 {
     _dealingServer = dealingServer;
     _outStock      = new CSharedStocks(2 * STOCK_DEPTH);
     _client        = client;
 }
 public void UpdateStockConverterOneDir(string instrument, Direction dir, int precision, CSharedStocks stock)
 {
     _dictStockConverter[instrument].UpdateCryptoStockConverterOneDir(stock, dir, precision);
 }
 public void UpdateCleintStockBothDir(string instrument, int precision, CSharedStocks stock)
 {
     _client.UpdateStockBothDir(instrument, precision, stock);
 }
Esempio n. 19
0
 public void UpdateStockBothDir(string instrument, int precision, CSharedStocks stock)
 {
 }
 public void UpdateStockConverterBothDir(string instrument, int precision, CSharedStocks stock)
 {
     _dictStockConverter[instrument].UpdateCryptoStockConverterBothDir(stock, precision);
 }
 public void UpdateInpStocks(long isinId, ref CSharedStocks sourceStock)
 {
 }
 public void UpdateStockOneDir(string instrument, Direction dir, int precision, CSharedStocks stock)
 {
     _stockBoxCrypto.UpdateStockConverterOneDir(instrument, dir, precision, stock);
 }
 public void UpdateStockBothDir(string instrument, int precision, CSharedStocks stock)
 {
     _stockBoxCrypto.UpdateStockConverterBothDir(instrument, precision, stock);
 }
        private void UpdatePriceDecimalsAndMinStep(CSharedStocks sourceStock)
        {
            int maxCalcedPriceDecimals = 0;



            int  numEl    = 0;
            bool bChanged = false;

            Dictionary <int, int> _dictAmount = new Dictionary <int, int>();


            // Specific algorithm for PriceDecimals and min step calculation.
            //
            //
            // 2018-06-21 Algo changed. Do count all amounts of decimals
            // and save to dictionary. Use amount of decimals wich has more elements.
            // Perform analyze only for elements that are near spread,
            // for this purpose using "window" which determines an area near spread.
            //
            // If current value change - do trigger update of client
            //

            lock (sourceStock.Lck)
            {
                foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                {
                    int i          = 0;
                    int windowSize = 50;
                    //2018-06-22 temprorary only for precision 0
                    foreach (var el in sourceStock[dir][0])
                    {
                        if (el.Price == 0)
                        {
                            continue;
                        }

                        if (i > windowSize)
                        {
                            break;
                        }

                        int calcedPriceDecimals = CUtilConv.GetPriceDecimals(el.Price);

                        if (_dictAmount.ContainsKey(calcedPriceDecimals))
                        {
                            _dictAmount[calcedPriceDecimals]++;
                        }
                        else
                        {
                            _dictAmount[calcedPriceDecimals] = 1;
                        }



                        numEl++;

                        if (calcedPriceDecimals > maxCalcedPriceDecimals)
                        {
                            maxCalcedPriceDecimals = calcedPriceDecimals;
                        }

                        i++;
                    }
                }
            }
            //nothing to do - get out
            if (numEl == 0)
            {
                return;
            }



            int maxDecimalsAmount = 0;
            int decimalsPriceUse  = 0;

            foreach (var kvp in _dictAmount)
            {
                if (kvp.Value > maxDecimalsAmount)
                {
                    maxDecimalsAmount = kvp.Value;
                    decimalsPriceUse  = kvp.Key;
                }
            }


            // if (Instrument == "IOTUSD")
            //  bDbgFirst = true;



            if (decimalsPriceUse != _currentPriceDecimals)
            {
                Log(String.Format("Changed pirce decimals {0} --> {1}",
                                  _currentPriceDecimals, decimalsPriceUse));

                _currentPriceDecimals = decimalsPriceUse;
                //2018-04-05 temporary disabled
                //2018-04-23 enabled after change to 4 decimals
                _clientStockConvCrypto.UpdatePriceDecimals(Instrument, _currentPriceDecimals);
                bChanged = true;
            }

            decimal calcedMinStep = CUtil.GetDecimalMult(_currentPriceDecimals);


            if (calcedMinStep != _currentMinStep)
            {
                Log(String.Format("Changed min_steps  {0} --> {1}",
                                  _currentMinStep, calcedMinStep));

                _currentMinStep = calcedMinStep;
                //2018-04-05 temporary disabled
                //2018-04-23 enabled after change to 4 decimals
                _clientStockConvCrypto.UpdateCurrentMinSteps(Instrument, _currentMinStep);
                bChanged = true;
            }


            //	Thread.Sleep(30000);
            if (bChanged)
            {
                _clientStockConvCrypto.TriggerUpdateInstrumentParams(Instrument);
            }

            //for (int i=0; i<sourceStock[TradingLib.Enums.Direction.
            //CBfxUtils.GetPriceDecimals(


            sourceStock.LstStockConf = new List <CStockConf>();

            int dcmlCurr = _currentPriceDecimals;

            var lst = _client.GetPricePrecisions();

            int count = lst.Count;

            for (int i = 0; i < count; i++)
            {
                // if (Instrument == "IOTUSD")
                //   bDbgFirst = true;


                decimal currMinStep = CUtil.GetDecimalMultUnlim(dcmlCurr);

                CStockConf stockConf = new CStockConf()
                {
                    PrecissionNum = i,
                    DecimalsPrice = Math.Max(dcmlCurr, 0),
                    MinStep       = currMinStep
                };

                sourceStock.LstStockConf.Add(stockConf);

                dcmlCurr--;
            }
        }
Esempio n. 25
0
 public void UpdateStockOneDir(string instrument, Direction dir, int precision, CSharedStocks stock)
 {
 }