Example #1
0
        private void GetCandles(CandleSeries series)
        {
            Security  security = series.Security;
            TimeFrame tf       = series.TimeFrame;

            string needPeriodId = GetNeedIdPeriod(tf, out var newTf, out var oldTf);

            string cmd = "<command id=\"gethistorydata\">";

            cmd += "<security>";
            cmd += "<board>" + security.NameClass + "</board>";
            cmd += "<seccode>" + security.Name + "</seccode>";
            cmd += "</security>";
            cmd += "<period>" + needPeriodId + "</period>";
            cmd += "<count>" + 1000 + "</count>";
            cmd += "<reset>" + "true" + "</reset>";
            cmd += "</command>";

            // sending command / отправка команды
            string res = _client.ConnectorSendCommand(cmd);

            if (res != "<result success=\"true\"/>")
            {
                SendLogMessage(res, LogMessageType.Error);
                return;
            }

            var startLoadingTime = DateTime.Now;

            while (startLoadingTime.AddSeconds(10) > DateTime.Now)
            {
                var candles = _allCandleSeries.Find(s => s.Seccode == security.Name && s.Period == needPeriodId);

                if (candles != null)
                {
                    //series.CandlesAll?.Clear();
                    var donorCandles = ParseCandles(candles);

                    if ((tf == TimeFrame.Min1 && needPeriodId == "1") ||
                        (tf == TimeFrame.Min5 && needPeriodId == "2") ||
                        (tf == TimeFrame.Min15 && needPeriodId == "3") ||
                        (tf == TimeFrame.Hour1 && needPeriodId == "4"))
                    {
                        series.CandlesAll = donorCandles;
                    }
                    else
                    {
                        series.CandlesAll = BuildCandles(donorCandles, newTf, oldTf);
                    }

                    series.UpdateAllCandles();
                    series.IsStarted = true;
                    return;
                }

                Thread.Sleep(1000);
            }

            SendLogMessage(OsLocalization.Market.Message95 + security.Name, LogMessageType.Error);
        }
Example #2
0
        /// <summary>
        /// subscribe to get ticks and depth by instrument
        /// подписаться на получение тиков и стаканов по инструменту
        /// </summary>
        /// <param name="security">subscribed instrument / инструмент на который подписываемся</param>
        public void Subscrible(Security security)
        {
            string cmd = "<command id=\"subscribe\">";

            cmd += "<alltrades>";
            cmd += "<security>";
            cmd += "<board>" + security.NameClass + "</board>";
            cmd += "<seccode>" + security.Name + "</seccode>";
            cmd += "</security>";
            cmd += "</alltrades>";
            cmd += "<quotes>";
            cmd += "<security>";
            cmd += "<board>" + security.NameClass + "</board>";
            cmd += "<seccode>" + security.Name + "</seccode>";
            cmd += "</security>";
            cmd += "</quotes>";
            cmd += "</command>";

            // sending command / отправка команды
            string res = _client.ConnectorSendCommand(cmd);

            if (res != "<result success=\"true\"/>")
            {
                SendLogMessage(res, LogMessageType.Error);
            }
        }
Example #3
0
        /// <summary>
        /// execute order on the exchange
        /// исполнить ордер на бирже
        /// </summary>
        private void ExecuteOnBoardOrder(Order order, decimal price, DateTime time, int slipage)
        {
            decimal realPrice = price;

            if (order.Volume == order.VolumeExecute ||
                order.State == OrderStateType.Done)
            {
                return;
            }


            if (slipage != 0)
            {
                if (order.Side == Side.Buy)
                {
                    Security mySecurity = GetSecurityForName(order.SecurityNameCode, "");

                    if (mySecurity != null && mySecurity.PriceStep != 0)
                    {
                        realPrice += mySecurity.PriceStep * slipage;
                    }
                }

                if (order.Side == Side.Sell)
                {
                    Security mySecurity = GetSecurityForName(order.SecurityNameCode, "");

                    if (mySecurity != null && mySecurity.PriceStep != 0)
                    {
                        realPrice -= mySecurity.PriceStep * slipage;
                    }
                }
            }

            MyTrade trade = new MyTrade();

            trade.NumberOrderParent = order.NumberMarket;
            trade.NumberTrade       = _iteratorNumbersMyTrades++.ToString();
            trade.SecurityNameCode  = order.SecurityNameCode;
            trade.Volume            = order.Volume;
            trade.Time  = time;
            trade.Price = realPrice;
            trade.Side  = order.Side;

            MyTradesIncome(trade);

            order.State = OrderStateType.Done;
            order.Price = realPrice;

            if (NewOrderIncomeEvent != null)
            {
                NewOrderIncomeEvent(order);
            }

            ChangePosition(order);

            CheckWaitOrdersRegime();
        }
Example #4
0
        private void HandleSecurities(List <TransaqEntity.Security> securities)
        {
            if (_securities == null)
            {
                _securities = new List <Security>();
            }
            foreach (var securityData in securities)
            {
                try
                {
                    if (securityData.Sectype != "FUT" &&
                        securityData.Sectype != "SHARE" &&
                        securityData.Sectype != "CURRENCY")
                    {
                        continue;
                    }
                    Security security = new Security();

                    security.Name      = securityData.Seccode;
                    security.NameFull  = securityData.Shortname;
                    security.NameClass = securityData.Board;
                    security.NameId    = securityData.Secid; // + "-" + securityData.Board;
                    security.Decimals  = Convert.ToInt32(securityData.Decimals);

                    security.SecurityType = securityData.Sectype == "FUT" ? SecurityType.Futures
                        : securityData.Sectype == "SHARE" ? SecurityType.Stock
                        : securityData.Sectype == "OPT" ? SecurityType.Option
                        : securityData.Sectype == "CURRENCY" ? SecurityType.CurrencyPair
                        : SecurityType.None;


                    security.Lot = Convert.ToDecimal(securityData.Lotsize.Replace(".", CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator),
                                                     CultureInfo.InvariantCulture);

                    security.PriceStep = Convert.ToDecimal(securityData.Minstep.Replace(".", CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator),
                                                           CultureInfo.InvariantCulture);

                    decimal pointCost;
                    try
                    {
                        pointCost = Convert.ToDecimal(securityData.Point_cost.Replace(
                                                          ".", CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator),
                                                      CultureInfo.InvariantCulture);
                    }
                    catch (Exception e)
                    {
                        decimal.TryParse(securityData.Point_cost, NumberStyles.Float, CultureInfo.InvariantCulture, out pointCost);
                    }

                    security.PriceStepCost = security.PriceStep * pointCost / 100;

                    security.State = securityData.Active == "true" ? SecurityStateType.Activ : SecurityStateType.Close;

                    _securities.Add(security);
                }
                catch (Exception e)
                {
                    SendLogMessage(e.Message, LogMessageType.Error);
                }
            }
            SecurityEvent?.Invoke(_securities);
        }
Example #5
0
 public List <Candle> GetCandleDataToSecurity(Security security, TimeFrameBuilder timeFrameBuilder, DateTime startTime, DateTime endTime,
                                              DateTime actualTime)
 {
     return(null);
 }
Example #6
0
 public List <Trade> GetTickDataToSecurity(Security security, DateTime startTime, DateTime endTime, DateTime actualTime)
 {
     return(null);
 }