Ejemplo n.º 1
0
        private void SetExternalOrder(Order order, ref OrderField field)
        {
            var orderRecord            = new OrderRecord(order);
            ExternalOrderRecord record = new ExternalOrderRecord();

            record = externalOrders.GetOrAdd(order.Instrument.Symbol, record);
            if (field.OpenClose == OpenCloseType.Open)
            {
                if (field.Side == XAPI.OrderSide.Buy)
                {
                    record.BuyOpen = orderRecord;
                }
                else
                {
                    record.SellOpen = orderRecord;
                }
            }
            else
            {
                if (field.Side == XAPI.OrderSide.Buy)
                {
                    record.BuyClose = orderRecord;
                }
                else
                {
                    record.SellClose = orderRecord;
                }
            }
        }
Ejemplo n.º 2
0
        public void ProcessNew(ref QuoteField quote, QuoteRecord record)
        {
            OrderRecord askRecord = new OrderRecord(record.AskOrder);

            this.workingOrders[quote.AskID]   = askRecord;
            this.orderIDs[askRecord.Order.Id] = quote.AskID;
            EmitExecutionReport(askRecord, (SQ.ExecType)quote.ExecType, (SQ.OrderStatus)quote.Status);

            OrderRecord bidRecord = new OrderRecord(record.BidOrder);

            this.workingOrders[quote.BidID]   = bidRecord;
            this.orderIDs[bidRecord.Order.Id] = quote.BidID;
            EmitExecutionReport(bidRecord, (SQ.ExecType)quote.ExecType, (SQ.OrderStatus)quote.Status);
        }
Ejemplo n.º 3
0
        public void ProcessNew(ref QuoteField quote, QuoteRecord record)
        {
            OrderRecord askRecord = new OrderRecord(record.AskOrder);

            this.workingOrders.Add(quote.AskID, askRecord);
            this.orderIDs.Add(askRecord.Order.Id, quote.AskID);
            EmitExecutionReport(askRecord, (SQ.ExecType)quote.ExecType, (SQ.OrderStatus)quote.Status);

            OrderRecord bidRecord = new OrderRecord(record.BidOrder);

            this.workingOrders.Add(quote.BidID, bidRecord);
            this.orderIDs.Add(bidRecord.Order.Id, quote.BidID);
            EmitExecutionReport(bidRecord, (SQ.ExecType)quote.ExecType, (SQ.OrderStatus)quote.Status);
        }
Ejemplo n.º 4
0
        public void DoOrderCancel(List <Order> ordersList)
        {
            lock (this)
            {
                OrderRecord[] recordList = new OrderRecord[ordersList.Count];
                string[]      OrderIds   = new string[ordersList.Count];

                for (int i = 0; i < ordersList.Count; ++i)
                {
                    // 如果需要下单的过程中撤单,这里有可能返回LocalID或ID
                    if (orderIDs.TryGetValue(ordersList[i].Id, out OrderIds[i]))
                    {
                        if (this.workingOrders.TryGetValue(OrderIds[i], out recordList[i]))
                        {
                            // 订单已经下到柜台上了
                            pendingCancels[OrderIds[i]] = recordList[i];
                        }
                        else if (this.pendingOrders.TryGetValue(OrderIds[i], out recordList[i]))
                        {
                            // 订单还没有下到柜台,需要撤单
                            pendingCancels[OrderIds[i]] = recordList[i];
                        }
                    }
                    else if (ordersList[i].Fields[9] != null)
                    {
                        OrderIds[i]   = (string)ordersList[i].Fields[9];
                        recordList[i] = new OrderRecord(ordersList[i]);
                    }
                }

                string   outstr = provider._TdApi.CancelOrder(OrderIds);
                string[] errs   = outstr.Split(';');

                {
                    int i = 0;
                    foreach (var e in errs)
                    {
                        if (!string.IsNullOrEmpty(e) && e != "0")
                        {
                            if (recordList[i] != null)
                            {
                                EmitExecutionReport(recordList[i], SQ.ExecType.ExecCancelReject, recordList[i].Order.Status, "Provider ErrorCode:" + e);
                            }
                        }
                        ++i;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public ExecutionReport CreateReport(
            OrderRecord record,
            SQ.ExecType?execType,
            SQ.OrderStatus?orderStatus)
        {
            ExecutionReport report = new ExecutionReport();

            report.DateTime = framework.Clock.DateTime;

            report.Order      = record.Order;
            report.Instrument = record.Order.Instrument;

            report.Side        = record.Order.Side;
            report.OrdType     = record.Order.Type;
            report.TimeInForce = record.Order.TimeInForce;

            report.OrdQty = record.Order.Qty;
            report.Price  = record.Order.Price;
            report.StopPx = record.Order.StopPx;

            report.AvgPx     = record.AvgPx;
            report.CumQty    = record.CumQty;
            report.LeavesQty = record.LeavesQty;

            if (execType != null)
            {
                report.ExecType = execType.Value;
            }

            if (orderStatus != null)
            {
                report.OrdStatus = orderStatus.Value;
            }

            return(report);
        }
Ejemplo n.º 6
0
        public void EmitExecutionReport(OrderRecord record, SQ.ExecType execType, SQ.OrderStatus orderStatus)
        {
            ExecutionReport report = CreateReport(record, execType, orderStatus);

            provider.EmitExecutionReport(report);
        }