Exemplo n.º 1
0
        internal static MappedOrder From(DataRow row)
        {
            MappedOrder order = new MappedOrder();

            order.ID                  = (Guid)row["ID"];
            order.TransactionID       = (Guid)row["TransactionID"];
            order.TransactionType     = (byte)row["TransactionType"];
            order.OrderTypeID         = (int)row["OrderTypeID"];
            order.AccountID           = (Guid)row["AccountID"];
            order.InstrumentID        = (Guid)row["InstrumentID"];
            order.ContractSize        = (decimal)row["ContractSize"];
            order.BeginTime           = (DateTime)row["BeginTime"];
            order.EndTime             = (DateTime)row["EndTime"];
            order.ExpireType          = (int)row["ExpireType"];
            order.SubmitTime          = (DateTime)row["SubmitTime"];
            order.ExecuteTime         = (DateTime)row["ExecuteTime"];
            order.SubmitorID          = (Guid)row["SubmitorID"];
            order.ApproverID          = row["ApproverID"] == DBNull.Value ? Guid.Empty : (Guid)row["ApproverID"];
            order.TradeOption         = (byte)row["TradeOption"];
            order.IsOpen              = (bool)row["IsOpen"];
            order.IsBuy               = (bool)row["IsBuy"];
            order.SetPrice            = row["SetPrice"] == DBNull.Value ? null : (string)row["SetPrice"];
            order.SetPrice2           = row["SetPrice2"] == DBNull.Value ? null : (string)row["SetPrice2"];
            order.SetPriceMaxMovePips = (int)row["SetPriceMaxMovePips"];
            order.ExecutePrice        = (string)row["ExecutePrice"];
            order.Lot                 = (decimal)row["Lot"];
            order.OriginalLot         = (decimal)row["OriginalLot"];
            order.LotBalance          = (decimal)row["LotBalance"];
            order.DQMaxMove           = (int)row["DQMaxMove"];
            order.TransactionSubType  = (byte)row["TransactionSubType"];
            order.InstrumentCategory  = (int)row["InstrumentCategory"];
            order.IsLocal             = (bool)row["IsLocal"];
            return(order);
        }
Exemplo n.º 2
0
        private void BookMappedOrder(object state)
        {
            while (this.started)
            {
                if (this.waitingForBookOrders.Count > 0)
                {
                    int         index = 0;
                    MappedOrder order = null;
                    while (index < this.waitingForBookOrders.Count)//get order which account doesn't have error
                    {
                        order = this.waitingForBookOrders[index];
                        if (!this.hasErrorAccounts.Contains(order.AccountID))
                        {
                            break;
                        }
                        else
                        {
                            index++;
                            order = null;
                        }
                    }

                    if (order == null)//if no order which account doesn't have error, try to book the first order
                    {
                        order = this.waitingForBookOrders[0];
                    }

                    if (this.Book(order))
                    {
                        this.waitingForBookOrders.Remove(order);
                    }
                    else
                    {
                        if (!this.hasErrorAccounts.Contains(order.AccountID))
                        {
                            hasErrorAccounts.Add(order.AccountID);
                        }
                    }
                }
                else
                {
                    Thread.Sleep(500);
                }
            }
        }
Exemplo n.º 3
0
        private void TagAsBooked(MappedOrder order, string info)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(this.connectionStr))
                {
                    SqlCommand command = connection.CreateCommand();
                    command.CommandText = "MappedOrder_TagAsBooked";
                    command.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    command.Parameters.Add("@orderId", SqlDbType.UniqueIdentifier).Value = order.ID;
                    command.Parameters.Add("@bookResult", SqlDbType.NVarChar).Value      = info;

                    command.ExecuteNonQuery();
                }
            }
            catch (Exception exception)
            {
                AppDebug.LogEvent("StateServer", string.Format("TagAsBooked failed, error = {0} \n {1}", exception, order.ToXmlNode().OuterXml), System.Diagnostics.EventLogEntryType.Warning);
            }
        }
Exemplo n.º 4
0
        private void ProcessMappedOrders(DataSet dataSet)
        {
            if (dataSet.Tables[0].Rows.Count > 0)
            {
                Dictionary <Guid, MappedOrder> orders = new Dictionary <Guid, MappedOrder>();
                foreach (DataRow dataRow in dataSet.Tables[0].Rows)
                {
                    MappedOrder order = MappedOrder.From(dataRow);
                    this.waitingForBookOrders.Add(order);
                    orders.Add(order.ID, order);
                }

                foreach (DataRow dataRow in dataSet.Tables[1].Rows)
                {
                    MappedOrderRelation relation = MappedOrderRelation.From(dataRow);
                    orders[relation.CloseOrderID].AddRelation(relation);
                }

                this.waitingForBookOrders.Sort(MappedOrderComparer.Default);
            }
        }
Exemplo n.º 5
0
        private bool Book(MappedOrder order)
        {
            order.Adjust();
            TransactionError error = this.bookExecutor(order);

            if (error != TransactionError.RuntimeError)
            {
                if (error != TransactionError.OK)
                {
                    AppDebug.LogEvent("StateServer", string.Format("Book failed, error = {0} \n {1}", error, order.ToXmlNode().OuterXml), System.Diagnostics.EventLogEntryType.Warning);
                }

                this.TagAsBooked(order, string.Format("Book restult is {0}", error));

                return(true);
            }
            else
            {
                AppDebug.LogEvent("StateServer", string.Format("Book failed, error = {0} \n {1}", error, order.ToXmlNode().OuterXml), System.Diagnostics.EventLogEntryType.Warning);
                return(false);
            }
        }