public int InsertExecutions(ExecutedOrder exeorder) { string sql = "Insert into tbl_trades(StockID,BuyRequestID,SellRequestID,ExeQuantity,ExePrice) values(@stock,@buyrequest,@sellrequest,@exequantity,@exeprice) ; SELECT last_insert_rowid();"; try { using (IDbConnection conn = _OrderDatabase.CreateConnection(_ConnString)) { using (IDbCommand command = _OrderDatabase.CreateCommand(sql, conn)) { command.Parameters.Add(_OrderDatabase.PrepareParameter("@stock", exeorder.StockID)); command.Parameters.Add(_OrderDatabase.PrepareParameter("@buyrequest", exeorder.BuyRequestID)); command.Parameters.Add(_OrderDatabase.PrepareParameter("@sellrequest", exeorder.SellRequestID)); command.Parameters.Add(_OrderDatabase.PrepareParameter("@exequantity", exeorder.ExecutionQuantity)); command.Parameters.Add(_OrderDatabase.PrepareParameter("@exeprice", exeorder.ExecutionPrice)); object obj = command.ExecuteScalar(); int id = Convert.ToInt32(obj); return(id); } } } catch (Exception ex) { Console.WriteLine(ex.Message); return(0); } }
public void processExecuted(string _fileName) { Excel.Application excelObj = new Excel.Application(); Excel.Workbook workbook = null; Excel.Worksheet worksheet = null; Excel.Range assRange = null; object misValue = System.Reflection.Missing.Value; isExecuted = true; executedFileName = _fileName; try { workbook = excelObj.Workbooks.Open(_fileName); worksheet = (Excel.Worksheet)workbook.Sheets.Item[1]; assRange = worksheet.UsedRange; assRowCount = assRange.Rows.Count; assColCount = assRange.Columns.Count; // Sort based upon the order number and then the leg number assRange.Sort(assRange.Columns[1, Type.Missing], // the first sort key - Order Number Excel.XlSortOrder.xlAscending, assRange.Columns[15, Type.Missing], // second sort key - Leg Number Type.Missing, Excel.XlSortOrder.xlAscending, Type.Missing, Excel.XlSortOrder.xlAscending, // this would be the third key Excel.XlYesNoGuess.xlYes, // ignore the header Type.Missing, Type.Missing, Excel.XlSortOrientation.xlSortColumns, Excel.XlSortMethod.xlPinYin, Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal); ExecutedOrder assExOrder; ExecutedOrder tempAssExOrder; for (int i = 2; i <= assRowCount; i++) // Start at the second row and skip the header { assExOrder = new ExecutedOrder(); assExOrder.DeliverTo = assRange[i, 9].Value.ToString(); assExOrder.DeliveryAddress = assRange[i, 10].Value.ToString(); assExOrder.DeliveryCity = assRange[i, 11].Value.ToString(); assExOrder.dtDevliveryDateTime = DateTime.FromOADate( Convert.ToDouble(assRange[i, 17].Value2) + Convert.ToDouble(assRange[i, 18].Value2) ); assExOrder.Driver = assRange[i, 19].Value.ToString(); // find if this driver has been added to the list tempAssExOrder = assExOrders.Find( delegate(ExecutedOrder aeo) { return(aeo.Driver == assExOrder.Driver); } ); // add the driver if it hasn't been added to the list, yet if (tempAssExOrder == null) { assExOrders.Add(assExOrder); } // remove the driver from the list if the deliveryDateTime is older than the new one else if (tempAssExOrder.dtDevliveryDateTime < assExOrder.dtDevliveryDateTime) { assExOrders.Remove(tempAssExOrder); assExOrders.Add(assExOrder); } } Console.Out.WriteLine(assExOrders.Count); workbook.Close(false, misValue, misValue); } catch (Exception ex) { Console.Out.WriteLine(ex.StackTrace); } finally { if (workbook != null) { Marshal.ReleaseComObject(workbook); } if (excelObj != null) { excelObj.Quit(); Marshal.ReleaseComObject(excelObj); } } }
public bool ProcessOrder(Order order) { if (order != null && order.Quantity > 0) { var result = orderdata.InsertOrder(order); if (result > 0) { order.ID = result; IList <Order> Unfilledorders = orderdata.FetchAvailableOrders(order); if (Unfilledorders != null && Unfilledorders.Count > 0) { ExecutedOrder exord = new ExecutedOrder(); exord.StockID = order.StockId; foreach (Order uforder in Unfilledorders) { if (order.OrderSide == OrderDirection.BUY) { exord.BuyRequestID = order.RequestId; exord.SellRequestID = uforder.RequestId; exord.ExecutionPrice = uforder.Price; } else { exord.BuyRequestID = uforder.RequestId; exord.SellRequestID = order.RequestId; exord.ExecutionPrice = order.Price; } if (uforder.AvailableQuantity >= order.AvailableQuantity) { exord.ExecutionQuantity = order.AvailableQuantity; } else { exord.ExecutionQuantity = uforder.AvailableQuantity; } result = orderdata.InsertExecutions(exord); if (result > 0) { orderdata.UpdateExecutedQuantity(order.ID, uforder.ID, exord.ExecutionQuantity); order.AvailableQuantity -= exord.ExecutionQuantity; } else { Console.WriteLine("Error while Executing the trade"); break; } if (order.AvailableQuantity == 0) { break; } } } } else { Console.WriteLine("Error while processing the order"); return(false); } } return(false); }