private void OnSetMyOrder(int row, int rowsCount, string portfolio, string symbol, StOrder_State state,
                           StOrder_Action action, StOrder_Type type, StOrder_Validity validity, double price, double amount,
                           double stop, double filled, DateTime datetime, string id, string no, int cookie)
 {
     ProduceMessage(
         TopicName.SetMyOrder,
         JsonSerializer.Serialize(
             new SetMyOrder
     {
         Row          = row,
         RowsCount    = rowsCount,
         Portfolio    = portfolio,
         Symbol       = symbol,
         State        = state,
         Action       = action,
         Type         = type,
         Validity     = validity,
         Price        = price,
         Amount       = amount,
         PriceStop    = stop,
         FilledVolume = filled,
         DateTime     = datetime,
         OrderId      = id,
         StockOrderId = no,
         UniqueId     = cookie
     }
             )
         );
 }
 private void OnUpdateOrder(string portfolio, string symbol, StOrder_State state, StOrder_Action action,
                            StOrder_Type type, StOrder_Validity validity, double price, double amount, double stop, double filled,
                            DateTime datetime, string orderId, string orderStockId, int statusMask, int cookie, string description)
 {
     ProduceMessage(
         TopicName.UpdateOrder,
         JsonSerializer.Serialize(
             new UpdateOrder
     {
         Portfolio    = portfolio,
         Symbol       = symbol,
         State        = state,
         Action       = action,
         Type         = type,
         Validity     = validity,
         Price        = price,
         Amount       = amount,
         PriceStop    = stop,
         FilledVolume = filled,
         DateTime     = datetime,
         OrderId      = orderId,
         StockOrderId = orderStockId,
         StatusMask   = statusMask,
         UniqueId     = cookie,
         Error        = description
     }
             )
         );
 }
예제 #3
0
 public void PlaceOrder(string symbol, ActionEnum action, OrderTypeEnum type, double price, double volume, double stopPrice, int cookie)
 {
     try
     {
         if (IsConnected)
         {
             WriteToLog("Place order. Symbol: {0}; Action: {1}; Price: {2}; Volume: {3}",
                        symbol, action, price, volume);
             StOrder_Validity validity = (type == OrderTypeEnum.STOP ? StOrder_Validity.StOrder_Validity_Day : StOrder_Validity.StOrder_Validity_Gtc);
             SmartComServer.PlaceOrder(Portfolio, symbol, action == ActionEnum.BUY ? StOrder_Action.StOrder_Action_Buy : StOrder_Action.StOrder_Action_Sell
                                       , type == OrderTypeEnum.LIMIT ? StOrder_Type.StOrder_Type_Limit : StOrder_Type.StOrder_Type_StopLimit, validity
                                       , price, volume, stopPrice, cookie);
         }
     } catch (Exception e)
     {
         throw new SmartException(e);
     }
 }
예제 #4
0
파일: UpdateOrder.cs 프로젝트: w1r2p1/TRx
 public UpdateOrder(string portfolio, string symbol, StOrder_State state, StOrder_Action action, StOrder_Type type, StOrder_Validity validity, double price, double amount, double stop, double filled, DateTime date, string orderId, string orderNo, int status_mask, int cookie)
 {
     this.portfolio     = portfolio;
     this.symbol        = symbol;
     this.state         = state;
     this.action        = action;
     this.type          = type;
     this.validity      = validity;
     this.price         = price;
     this.orderAmount   = amount;
     this.stop          = stop;
     this.orderUnfilled = filled;
     this.datetime      = date;
     this.orderId       = orderId;
     this.orderNo       = orderNo;
     this.statusMask    = status_mask;
     this.cookie        = cookie;
 }
예제 #5
0
        public void SendOrder(Order order)
        {
            StOrder_Action action;

            if (order.Side == Side.Buy)
            {
                action = StOrder_Action.StOrder_Action_Buy;
            }
            else
            {
                action = StOrder_Action.StOrder_Action_Sell;
            }

            StOrder_Type type;

            type = StOrder_Type.StOrder_Type_Limit;


            StOrder_Validity validity = StOrder_Validity.StOrder_Validity_Day;

            double price  = Convert.ToDouble(order.Price);
            double volume = Convert.ToDouble(order.Volume);
            int    cookie = Convert.ToInt32(order.NumberUser);

            lock (_smartComServerLocker)
            {
                SmartServer.PlaceOrder(order.PortfolioNumber, order.SecurityNameCode, action, type,
                                       validity,
                                       price, volume, 0, cookie);
            }
            _numsSendToExecuteOrders.Add(new TransactioinSmartComSendState()
            {
                NumTransaction      = order.NumberUser,
                TimeSendTransaction = DateTime.Now
            });
        }
예제 #6
0
        private void OnUpdateOrder(string portfolio, string symbol, StOrder_State smartState, StOrder_Action smartAction, StOrder_Type smartType, StOrder_Validity smartValidity, double price, double amount, double stop, double filled, DateTime datetime, string orderid, string orderno, int statusMask, int cookie)
        {
            SmartOrderState state;

            switch (smartState)
            {
            case StOrder_State.StOrder_State_ContragentReject:
                state = SmartOrderState.ContragentReject;
                break;

            case StOrder_State.StOrder_State_Submited:
                state = SmartOrderState.Submited;
                break;

            case StOrder_State.StOrder_State_Pending:
                state = SmartOrderState.Pending;
                break;

            case StOrder_State.StOrder_State_Open:
                state = SmartOrderState.Open;
                break;

            case StOrder_State.StOrder_State_Expired:
                state = SmartOrderState.Expired;
                break;

            case StOrder_State.StOrder_State_Cancel:
                state = SmartOrderState.Cancel;
                break;

            case StOrder_State.StOrder_State_Filled:
                state = SmartOrderState.Filled;
                break;

            case StOrder_State.StOrder_State_Partial:
                state = SmartOrderState.Partial;
                break;

            case StOrder_State.StOrder_State_ContragentCancel:
                state = SmartOrderState.ContragentReject;
                break;

            case StOrder_State.StOrder_State_SystemReject:
                state = SmartOrderState.SystemReject;
                break;

            case StOrder_State.StOrder_State_SystemCancel:
                state = SmartOrderState.SystemCancel;
                break;

            default:
                throw new ArgumentOutOfRangeException("smartState");
            }

            SmartOrderType type;

            switch (smartType)
            {
            case StOrder_Type.StOrder_Type_Market:
                type = SmartOrderType.Market;
                break;

            case StOrder_Type.StOrder_Type_Limit:
                type = SmartOrderType.Limit;
                break;

            case StOrder_Type.StOrder_Type_Stop:
                type = SmartOrderType.Stop;
                break;

            case StOrder_Type.StOrder_Type_StopLimit:
                type = SmartOrderType.StopLimit;
                break;

            default:
                throw new ArgumentOutOfRangeException("smartType");
            }

            SmartOrderValidity validity;

            switch (smartValidity)
            {
            case StOrder_Validity.StOrder_Validity_Day:
                validity = SmartOrderValidity.Day;
                break;

            case StOrder_Validity.StOrder_Validity_Gtc:
                validity = SmartOrderValidity.Gtc;
                break;

            default:
                throw new ArgumentOutOfRangeException("smartValidity");
            }

            OnUpdateOrder(portfolio, symbol, state, ToWrapper(smartAction), type, validity, price, amount, stop, filled, datetime, orderid, orderno, statusMask, cookie);
        }
예제 #7
0
        private void SmartServerOnUpdateOrder(string portfolio, string symbol, StOrder_State state, StOrder_Action action, StOrder_Type type, StOrder_Validity validity, double price, double amount, double stop, double filled, DateTime datetime, string orderid, string orderno, int statusMask, int cookie, string description)
        {
            try
            {
                Order order = new Order();
                order.NumberUser       = cookie;
                order.NumberMarket     = orderno;
                order.SecurityNameCode = symbol;
                order.Price            = Convert.ToDecimal(price);
                order.Volume           = Convert.ToInt32(amount);
                order.VolumeExecute    = Convert.ToInt32(amount) - Convert.ToInt32(filled);
                order.NumberUser       = cookie;
                order.Comment          = orderid;
                order.PortfolioNumber  = portfolio;

                if (_ordersWhithId.Find(o => o.Comment == order.Comment) == null)
                {
                    _ordersWhithId.Add(order);
                }


                if (state == StOrder_State.StOrder_State_Open ||
                    state == StOrder_State.StOrder_State_Submited)
                {
                    order.State        = OrderStateType.Activ;
                    order.TimeCallBack = datetime;
                    _numsIncomeExecuteOrders.Add(cookie);
                }
                if (state == StOrder_State.StOrder_State_Pending)
                {
                    order.TimeCallBack = datetime;
                    order.State        = OrderStateType.Pending;
                    _numsIncomeExecuteOrders.Add(cookie);
                    return;
                }
                if (state == StOrder_State.StOrder_State_Cancel ||
                    state == StOrder_State.StOrder_State_SystemCancel)
                {
                    order.TimeCancel = datetime;
                    order.State      = OrderStateType.Cancel;
                    _numsIncomeCancelOrders.Add(cookie);
                    _numsIncomeExecuteOrders.Add(cookie);
                }
                if (state == StOrder_State.StOrder_State_SystemReject)
                {
                    order.State         = OrderStateType.Fail;
                    order.VolumeExecute = 0;
                    order.TimeCancel    = datetime;
                    order.TimeCallBack  = datetime;
                    _numsIncomeExecuteOrders.Add(cookie);
                    _numsIncomeCancelOrders.Add(cookie);
                }

                if (state == StOrder_State.StOrder_State_Filled)
                {
                    order.VolumeExecute = order.Volume;
                    order.TimeCallBack  = datetime;
                    order.TimeDone      = datetime;
                    order.State         = OrderStateType.Done;
                    _numsIncomeExecuteOrders.Add(cookie);
                }
                if (state == StOrder_State.StOrder_State_Partial)
                {
                    order.State        = OrderStateType.Patrial;
                    order.TimeCallBack = datetime;
                    _numsIncomeExecuteOrders.Add(cookie);
                }


                if (action == StOrder_Action.StOrder_Action_Buy ||
                    action == StOrder_Action.StOrder_Action_Cover)
                {
                    order.Side = Side.Buy;
                }
                else
                {
                    order.Side = Side.Sell;
                }

                if (type == StOrder_Type.StOrder_Type_Limit)
                {
                    order.TypeOrder = OrderPriceType.Limit;
                }
                else
                {
                    order.TypeOrder = OrderPriceType.Market;
                }

                if (MyOrderEvent != null)
                {
                    MyOrderEvent(order);
                }
            }
            catch (Exception error)
            {
                SendLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
예제 #8
0
        void scom_UpdateOrder(string portfolio, string symbol
                              , StOrder_State state, StOrder_Action action, StOrder_Type type, StOrder_Validity validity
                              , double price, double amount, double stop, double filled, DateTime datetime, string orderid, string orderno, int status_mask, int cookie)
        {
            if (!Trading)
            {
                return;
            }
            string messageInf = "";

            //string messageInf = "(" + DateTime.Now.ToString("HH:mm:ss:fff", CultureInfo.InvariantCulture) + ")"
            //    + "\tUpdateOrder(" + action.ToString() + "): " + cookie + "(" + orderid + " | " + orderno + ") price: " + price.ToString() + " stop: " + stop.ToString() + " filled: " + filled.ToString() + ": ";
            allClaims.AddOrderIdAndOrderNo(cookie, amount, action, orderid, orderno);
            string roundtrip = "";

            switch (state)
            {
            case StOrder_State.StOrder_State_Pending:
                allClaims.dicAllClaims[cookie].dt_State_Pending = DateTime.Now;
                roundtrip   = (allClaims.dicAllClaims[cookie].dtEnter - allClaims.dicAllClaims[cookie].dt_State_Pending).TotalMilliseconds.ToString();
                messageInf += DateTime.Now.ToString("HH:mm:ss:fff") + " UpdateOrder Размещен у брокера ";
                break;

            case StOrder_State.StOrder_State_Open:
                allClaims.dicAllClaims[cookie].dt_State_Open = DateTime.Now;
                roundtrip   = (allClaims.dicAllClaims[cookie].dtEnter - allClaims.dicAllClaims[cookie].dt_State_Open).TotalMilliseconds.ToString();
                messageInf += DateTime.Now.ToString("HH:mm:ss:fff") + " UpdateOrder Выведен на рынок ";
                break;

            case StOrder_State.StOrder_State_Cancel:
                allClaims.dicAllClaims[cookie].dt_State_Cancel = DateTime.Now;
                roundtrip   = (allClaims.dicAllClaims[cookie].dtEnter - allClaims.dicAllClaims[cookie].dt_State_Cancel).TotalMilliseconds.ToString();
                messageInf += DateTime.Now.ToString("HH:mm:ss:fff") + " UpdateOrder Отменён ";
                break;

            case StOrder_State.StOrder_State_Filled:
                allClaims.dicAllClaims[cookie].dt_State_Filled = DateTime.Now;
                roundtrip   = (allClaims.dicAllClaims[cookie].dtEnter - allClaims.dicAllClaims[cookie].dt_State_Filled).TotalMilliseconds.ToString();
                messageInf += DateTime.Now.ToString("HH:mm:ss:fff") + " UpdateOrder Исполнен ";
                break;

            case StOrder_State.StOrder_State_Partial:
                allClaims.dicAllClaims[cookie].dt_State_Partial = DateTime.Now;
                roundtrip   = (allClaims.dicAllClaims[cookie].dtEnter - allClaims.dicAllClaims[cookie].dt_State_Partial).TotalMilliseconds.ToString();
                messageInf += DateTime.Now.ToString("HH:mm:ss:fff") + " UpdateOrder Исполнен частично amount: " + amount.ToString() + " filled:" + filled.ToString();
                break;

            default:
                break;
            }
            if (OnInformation != null)
            {
                OnInformation(InfoElement.logfile, messageInf + " cook:" + cookie + " orderid:" + orderid + " orderNo:" + orderno + " lotCount:" + lotCount.ToString() + " roundTrip:" + roundtrip);
            }
        }
예제 #9
0
        void scom_SetMyOrder(int row, int nrows, string portfolio, string symbol, StOrder_State state, StOrder_Action action, StOrder_Type type, StOrder_Validity validity
                             , double price, double amount, double stop, double filled, DateTime datetime, string id, string no, int cookie)
        {
            allClaims.AddOrderIdAndOrderNo(cookie, amount, action, id, no);
            string messageInf = DateTime.Now.ToString("HH:mm:ss:fff") + " SetMyOrders " + cookie;

            if (OnInformation != null)
            {
                OnInformation(InfoElement.logfile, messageInf);
            }
        }
예제 #10
0
 public void PlaceOrder(string portfolio, string symbol, StOrder_Action action, StOrder_Type type, StOrder_Validity validity, double price, double amount, double stop, int cookie)
 {
     this.ordersPlaced++;
 }