Esempio n. 1
0
        /// <summary>
        /// send order
        /// выслать ордер
        /// </summary>
        public void SendOrder(Order order)
        {
            string command = ConvertToSimpleQuikOrder(order);

            int error;
            var msg = new StringBuilder(256);

            if (command == null)
            {
                return;
            }

            order.TimeCreate = ServerTime;
            SetOrder(order);

            Trans2Quik.QuikResult result = Trans2Quik.SEND_ASYNC_TRANSACTION(command, out error, msg, msg.Capacity);

            if (msg.ToString() != "")
            {
                Order newOrder = new Order();
                newOrder.NumberUser = order.NumberUser;
                newOrder.State      = OrderStateType.Fail;
                if (MyOrderEvent != null)
                {
                    MyOrderEvent(newOrder);
                }
                return;
            }

            SendLogMessage(result.ToString(), LogMessageType.System);
        }
Esempio n. 2
0
        /// <summary>
        /// cancel order
        /// отозвать ордер
        /// </summary>
        public void CancelOrder(Order order)
        {
            string command = ConvertToKillQuikOrder(order);

            int error;
            var msg = new StringBuilder(256);


            if (command == null)
            {
                return;
            }

            Trans2Quik.QuikResult result = Trans2Quik.SEND_ASYNC_TRANSACTION(command, out error, msg, msg.Capacity);

            SendLogMessage(result.ToString(), LogMessageType.System);
        }
Esempio n. 3
0
        /// <summary>
        /// dispoese objects connected with server
        /// освободить объекты связанные с сервером
        /// </summary>
        public void Dispose()
        {
            if (_serverDde != null && _serverDde.IsRegistered)
            {
                //_serverDde.StopDdeInQuik();
                //_serverDde = null;
            }

            try
            {
                int error;
                var msg = new StringBuilder(256);
                Trans2Quik.DISCONNECT(out error, msg, msg.Capacity);
            }
            catch (Exception erorr)
            {
                SendLogMessage(erorr.ToString(), LogMessageType.Error);
            }

            if (DisconnectEvent != null)
            {
                DisconnectEvent();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// connect to API
        /// подключиться к Апи
        /// </summary>
        public void Connect()
        {
            try
            {
                _lastStartServerTime = DateTime.Now;



                if (string.IsNullOrWhiteSpace(((ServerParameterPath)ServerParameters[0]).Value))
                {
                    SendLogMessage(OsLocalization.Market.Message83, LogMessageType.Error);
                    return;
                }

                if (ServerStatus == ServerConnectStatus.Connect)
                {
                    return;
                }

                if (_transe2QuikStatus != ServerConnectStatus.Connect)
                {
                    int error;
                    var msg = new StringBuilder(256);

                    Trans2Quik.QuikResult result = Trans2Quik.SET_CONNECTION_STATUS_CALLBACK(StatusCallback, out error, msg,
                                                                                             msg.Capacity);

                    if (result != Trans2Quik.QuikResult.SUCCESS)
                    {
                        SendLogMessage(OsLocalization.Market.Message84 + error, LogMessageType.Error);
                        return;
                    }

                    result = Trans2Quik.CONNECT(((ServerParameterPath)ServerParameters[0]).Value, out error, msg, msg.Capacity);

                    if (result != Trans2Quik.QuikResult.SUCCESS && result != Trans2Quik.QuikResult.ALREADY_CONNECTED_TO_QUIK)
                    {
                        SendLogMessage(OsLocalization.Market.Message84 + msg, LogMessageType.Error);
                        return;
                    }

                    Trans2Quik.SET_TRANSACTIONS_REPLY_CALLBACK(TransactionReplyCallback, out error, msg,
                                                               msg.Capacity);

                    result = Trans2Quik.SUBSCRIBE_ORDERS("", "");
                    while (result != Trans2Quik.QuikResult.SUCCESS)
                    {
                        Thread.Sleep(5000);
                        result = Trans2Quik.SUBSCRIBE_ORDERS("", "");
                    }

                    result = Trans2Quik.START_ORDERS((PfnOrderStatusCallback));
                    while (result != Trans2Quik.QuikResult.SUCCESS)
                    {
                        Thread.Sleep(5000);
                        result = Trans2Quik.START_ORDERS((PfnOrderStatusCallback));
                    }

                    Trans2Quik.SUBSCRIBE_TRADES("", "");
                    Trans2Quik.START_TRADES(PfnTradeStatusCallback);

                    Trans2Quik.GetTradeAccount(0);
                }

                if (_serverDde == null)
                {
                    _serverDde = new QuikDde("OSA_DDE");
                    _serverDde.StatusChangeEvent += _serverDde_StatusChangeEvent;
                    _serverDde.UpdatePortfolios  += _serverDde_UpdatePortfolios;
                    _serverDde.UpdateSecurity    += _serverDde_UpdateSecurity;
                    _serverDde.UpdateTrade       += _serverDde_UpdateTrade;
                    _serverDde.UpdateGlass       += _serverDde_UpdateGlass;
                    _serverDde.LogMessageEvent   += SendLogMessage;

                    if (!_serverDde.IsRegistered)
                    {
                        _serverDde.StartServer();
                    }
                    else
                    {
                        _ddeStatus = ServerConnectStatus.Connect;
                    }
                }

                if (_serverDde.IsRegistered)
                {
                    _ddeStatus = ServerConnectStatus.Connect;
                }

                Thread.Sleep(1000);
            }
            catch (Exception erorr)
            {
                SendLogMessage(erorr.ToString(), LogMessageType.Error);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// подключиться к Апи
        /// </summary>
        public void Connect()
        {
            try
            {
                _lastStartServerTime = DateTime.Now;



                if (string.IsNullOrWhiteSpace(((ServerParameterPath)ServerParameters[0]).Value))
                {
                    SendLogMessage("Ошибка. Необходимо указать местоположение Quik", LogMessageType.Error);
                    return;
                }

                if (ServerStatus == ServerConnectStatus.Connect)
                {
                    SendLogMessage("Ошибка. Соединение уже установлено", LogMessageType.Error);
                    return;
                }

                if (_transe2QuikStatus != ServerConnectStatus.Connect)
                {
                    int error;
                    var msg = new StringBuilder(256);

                    Trans2Quik.QuikResult result = Trans2Quik.SET_CONNECTION_STATUS_CALLBACK(StatusCallback, out error, msg,
                                                                                             msg.Capacity);

                    if (result != Trans2Quik.QuikResult.SUCCESS)
                    {
                        SendLogMessage("Ошибка. Trans2Quik не хочет подключаться " + error, LogMessageType.Error);
                        return;
                    }

                    result = Trans2Quik.CONNECT(((ServerParameterPath)ServerParameters[0]).Value, out error, msg, msg.Capacity);

                    if (result != Trans2Quik.QuikResult.SUCCESS && result != Trans2Quik.QuikResult.ALREADY_CONNECTED_TO_QUIK)
                    {
                        SendLogMessage("Ошибка при попытке подклчиться через Transe2Quik." + msg, LogMessageType.Error);
                        return;
                    }

                    Trans2Quik.SET_TRANSACTIONS_REPLY_CALLBACK(TransactionReplyCallback, out error, msg,
                                                               msg.Capacity);

                    result = Trans2Quik.SUBSCRIBE_ORDERS("", "");
                    while (result != Trans2Quik.QuikResult.SUCCESS)
                    {
                        Thread.Sleep(5000);
                        result = Trans2Quik.SUBSCRIBE_ORDERS("", "");
                        SendLogMessage("Повторно пытаемся включить поток сделок" + msg, LogMessageType.Error);
                    }

                    result = Trans2Quik.START_ORDERS((PfnOrderStatusCallback));
                    while (result != Trans2Quik.QuikResult.SUCCESS)
                    {
                        Thread.Sleep(5000);
                        result = Trans2Quik.START_ORDERS((PfnOrderStatusCallback));
                        SendLogMessage("Повторно пытаемся включить поток сделок" + msg, LogMessageType.Error);
                    }

                    Trans2Quik.SUBSCRIBE_TRADES("", "");
                    Trans2Quik.START_TRADES(PfnTradeStatusCallback);

                    Trans2Quik.GetTradeAccount(0);
                }

                if (_serverDde == null)
                {
                    _serverDde = new QuikDde("OSA_DDE");
                    _serverDde.StatusChangeEvent += _serverDde_StatusChangeEvent;
                    _serverDde.UpdatePortfolios  += _serverDde_UpdatePortfolios;
                    _serverDde.UpdateSecurity    += _serverDde_UpdateSecurity;
                    _serverDde.UpdateTrade       += _serverDde_UpdateTrade;
                    _serverDde.UpdateGlass       += _serverDde_UpdateGlass;
                    _serverDde.LogMessageEvent   += SendLogMessage;
                }

                Thread.Sleep(1000);

                if (!_serverDde.IsRegistered)
                {
                    _serverDde.StartServer();
                }
                else
                {
                    _ddeStatus = ServerConnectStatus.Connect;
                }
            }
            catch (Exception erorr)
            {
                SendLogMessage(erorr.ToString(), LogMessageType.Error);
            }
        }