public static FuturesOrder LoadFromXMLString(string xmlText) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(FuturesOrder)); StringReader stringReader = new StringReader(xmlText /* result is the value from the database */); FuturesOrder deserializedEntity = (FuturesOrder)xmlSerializer.Deserialize(stringReader); return(deserializedEntity as FuturesOrder); }
public static void OrderExecuted(FuturesOrder ExOrder)//removes executed orders from data store { if (ordersInProcess.ContainsKey(ExOrder.OrderID.ToString()) == true) { ordersInProcess.Remove(ExOrder.OrderID.ToString()); } else { Console.WriteLine("No record of order"); } }
private void csvWriter(FuturesOrder newOrder) { System.Text.StringBuilder theBuilder = new System.Text.StringBuilder(); theBuilder.Append(newOrder.Active); theBuilder.Append(","); theBuilder.Append(newOrder.BuySell); theBuilder.Append(","); theBuilder.Append(newOrder.CustomerID); theBuilder.Append(","); theBuilder.Append(newOrder.Instrument); theBuilder.Append(","); theBuilder.Append(newOrder.LimitPrice); theBuilder.Append(","); theBuilder.Append(newOrder.Message); theBuilder.Append(","); theBuilder.Append(newOrder.OrderAction); theBuilder.Append(","); theBuilder.Append(newOrder.OrderID); theBuilder.Append(","); theBuilder.Append(newOrder.OrderType); theBuilder.Append(","); theBuilder.Append(newOrder.OrigQuantity); theBuilder.Append(","); theBuilder.Append(newOrder.Quantity); theBuilder.Append(","); theBuilder.Append(newOrder.Status); theBuilder.Append(","); theBuilder.Append(newOrder.StopPrice); theBuilder.Append(","); theBuilder.Append(newOrder.TimeStamp); string order = theBuilder.ToString() + Environment.NewLine; //using (StreamWriter theWriter = new StreamWriter(@"C:\Users\Mike\Documents\Visual Studio 2012\Projects\Exchange\log.csv")) string fileName = @"C:\log.csv"; File.AppendAllText(fileName, order.ToString()); //theWriter.Write(theBuilder.ToString()); }
public void start(FuturesOrder newOrder) { double gusassRadVar; orderNumber = Interlocked.Increment(ref i) + (trader * 1000000); double v1, v2, v3, v4, v5; rand = RandomProvider.GetThreadRandom(); v1 = rand.NextDouble(); v2 = rand.NextDouble(); v3 = rand.NextDouble(); v4 = rand.NextDouble(); v5 = rand.NextDouble(); //Order order = new Order(); gusassRadVar = GaussRand.StartNextGaussian(); newOrder.CustomerID = trader; newOrder.OrderAction = OrderAction(v5); if (newOrder.OrderAction == "NEW") { newOrder.OrderType = OrderType(v3); newOrder.OrderID = orderNumber; if (newOrder.OrderType == "LIMIT") { newOrder.BuySell = BuySell(v2); gusassRadVar = (newOrder.BuySell == "B" ? Math.Min(1.0, gusassRadVar) : Math.Max(-1, gusassRadVar));//to prevent buy orders from meing too high and sell orders too low newOrder.LimitPrice = Math.Round(Price.InstrumentPrice + this.sigma * gusassRadVar, 2); newOrder.Instrument = Instrument(v1); newOrder.Quantity = Quantity(v4); newOrder.OrigQuantity = newOrder.Quantity; } else if (newOrder.OrderType == "MARKET") { newOrder.LimitPrice = Price.InstrumentPrice; newOrder.Instrument = Instrument(v1); newOrder.BuySell = BuySell(v2); newOrder.Quantity = Quantity(v4); newOrder.OrigQuantity = newOrder.Quantity; } else if (newOrder.OrderType == "STOP") { newOrder.StopPrice = Math.Round(Price.InstrumentPrice + this.sigma * gusassRadVar, 2); newOrder.Instrument = Instrument(v1); newOrder.BuySell = BuySell(v2); newOrder.Quantity = Quantity(v4); newOrder.OrigQuantity = newOrder.Quantity; } else { Console.WriteLine("Not valid order type"); } } else if (newOrder.OrderAction == "DELETE") { //have to pull from previous orders some how // we need original order ID , customer ID, instrumnet, and BuySell int orders = ordersInProcess.Count; if (orders != 0) //not working { int orderToDel = rand.Next(ordersInProcess.Count); int iter = 0; foreach (DictionaryEntry order in ordersInProcess) { if (iter == orderToDel) { newOrder = order.Value as FuturesOrder; break; } iter++; } ordersInProcess.Remove(newOrder.OrderID.ToString()); newOrder.OrderAction = "DELETE"; } else { return; } } else //(newOrder.OrderAction == "Update") { //have to pull from previous orders some how // we need original order ID , customer ID, instrumnet, and BuySell int orders = ordersInProcess.Count; if (orders != 0)//not working { int orderToUpdate = rand.Next(ordersInProcess.Count); int iter = 0; foreach (DictionaryEntry order in ordersInProcess) { if (iter == orderToUpdate) { newOrder = order.Value as FuturesOrder; break; } iter++; } ordersInProcess.Remove(newOrder.OrderID.ToString()); newOrder.OrderAction = "UPDATE"; newOrder.LimitPrice = Price.InstrumentPrice + this.sigma * gusassRadVar; //submits update order with new price, uses same order number newOrder.Quantity = Quantity(v4); } else { return; } } lock (this) { newConnection.sendOrders(ToXML(newOrder)); } if (newOrder.OrderAction == "NEW") { ordersInProcess.Add(newOrder.OrderID.ToString(), newOrder);// orders will be stored here until order is executed } }