Exemplo n.º 1
0
        protected override void DoRunLoopSubscriptions(string resp)
        {
            WebSocketSubscriptionEvent eventSubscr = JsonConvert.DeserializeObject <WebSocketSubscriptionEvent>(resp);

            if (ResponseRequestSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
            {
                if (eventSubscr.table == _ORDER && EventSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
                {
                    WebSocketExecutionReportEvent execReportEvent = JsonConvert.DeserializeObject <WebSocketExecutionReportEvent>(resp);

                    WebSocketSubscriptionEvent subscrEvent = EventSubscriptions[eventSubscr.GetSubscriptionEvent()];

                    subscrEvent.RunEvent(execReportEvent);
                }
                else if (eventSubscr.table == _EXECUTIONS && EventSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
                {
                    WebSocketExecutionReportEvent execReportEvent = JsonConvert.DeserializeObject <WebSocketExecutionReportEvent>(resp);

                    WebSocketSubscriptionEvent subscrEvent = EventSubscriptions[eventSubscr.GetSubscriptionEvent()];

                    subscrEvent.RunEvent(execReportEvent);
                }
                else
                {
                    //Log what we are receiving here because we are getting events that we didn't expect
                }
            }
        }
Exemplo n.º 2
0
        protected void ProcessExecutionReports(WebSocketSubscriptionEvent subscrEvent)
        {
            WebSocketExecutionReportEvent reports = (WebSocketExecutionReportEvent)subscrEvent;

            foreach (zHFT.OrderRouters.Bitmex.Common.DTO.ExecutionReport execReportDTO in reports.data)
            {
                try
                {
                    string clOrdId = "";
                    if (OrderIdMappers.ContainsKey(execReportDTO.OrderID))
                    {
                        clOrdId = OrderIdMappers[execReportDTO.OrderID];

                        if (BitMexActiveOrders.ContainsKey(clOrdId))
                        {
                            Order order = BitMexActiveOrders[clOrdId];

                            lock (tLock)
                            {
                                if (execReportDTO.ExecType == ExecType.New.ToString())
                                {
                                    order.OrderId = execReportDTO.OrderID;
                                }

                                if (execReportDTO.ExecType == ExecType.Replaced.ToString())
                                {
                                    BitMexActiveOrders.Remove(clOrdId);
                                    order.ClOrdId        = order.PendingClOrdId;
                                    order.PendingClOrdId = null;
                                    BitMexActiveOrders.Add(order.ClOrdId, order);
                                    OrderIdMappers[execReportDTO.OrderID] = order.ClOrdId;
                                }

                                if (execReportDTO.ExecType == ExecType.Canceled.ToString() ||
                                    execReportDTO.ExecType == ExecType.Stopped.ToString() ||
                                    execReportDTO.ExecType == ExecType.Rejected.ToString() ||
                                    execReportDTO.ExecType == ExecType.Suspended.ToString() ||
                                    execReportDTO.ExecType == ExecType.Expired.ToString())
                                {
                                    BitMexActiveOrders.Remove(order.ClOrdId);
                                    OrderIdMappers.Remove(order.OrderId);
                                }
                            }

                            WSExecutionReportWrapper wrapper = new WSExecutionReportWrapper(execReportDTO, order);
                            OnMessageRcv(wrapper);
                        }
                    }
                    else
                    {
                        DoLog(string.Format("Unknown order processing execution report for OrderId {0} ", execReportDTO.OrderID), Main.Common.Util.Constants.MessageType.Information);
                    }
                }
                catch (Exception ex)
                {
                    DoLog(string.Format("Error processing execution report for ClOrdId {0}:{1} ", execReportDTO.ClOrdID, ex.Message), Main.Common.Util.Constants.MessageType.Error);
                }
            }
        }