private string OrdersToString(UpdateableDataView view, int limit) { System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(limit); int num = 0; while (num < view.Count && num < limit) { DataRowView dataRowView = view[num]; list.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", new object[] { dataRowView["ID"], dataRowView["Price"], dataRowView["Volume"], dataRowView["VolumeRemaining"], dataRowView["VWAP"], dataRowView["Period"], dataRowView["Tick"], dataRowView["Timestamp"] })); num++; } return string.Join(";", list.ToArray()); }
private decimal MarketOrderVWAP(UpdateableDataView view, decimal volume) { decimal num = 0m; decimal num2 = volume; int num3 = 0; while (num3 < view.Count && num2 > 0m) { decimal num4 = System.Math.Min((decimal)view[num3]["VolumeRemaining"], num2); num = MathHelper.CalculateVWAP(num, volume - num2, num4, (decimal)view[num3]["Price"]); num2 -= num4; num3++; } return num; }
private string BookToString(UpdateableDataView view, int limit) { System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(limit); int num = 0; while (num < view.Count && num < limit) { DataRowView dataRowView = view[num]; list.Add(string.Format("{0},{1},{2}", dataRowView["TraderID"], dataRowView["Price"], dataRowView["VolumeRemaining"])); num++; } return string.Join(";", list.ToArray()); }
private System.Collections.Generic.List<PriceVolume> AggregateView(UpdateableDataView view, int limit) { System.Collections.Generic.List<PriceVolume> list = new System.Collections.Generic.List<PriceVolume>(); decimal d = -79228162514264337593543950335m; int num = 0; while (num < view.Count && list.Count < limit) { decimal num2 = (decimal)view[num]["Price"]; decimal num3 = (decimal)view[num]["VolumeRemaining"]; if (d != num2) { list.Add(new PriceVolume(num2, num3)); } else { list[list.Count - 1].Volume += num3; } d = num2; num++; } return list; }
private PriceVolume AggregatePriceVolume(string topic, UpdateableDataView view, int i, ref System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<PriceVolume>> cache) { if (!cache.ContainsKey(topic)) { cache.Add(topic, this.AggregateView(view, 20)); return this.AggregatePriceVolume(topic, view, i, ref cache); } if (i > cache[topic].Count) { return null; } return cache[topic][i - 1]; }
public Game() { DataTable dataTable = new DataTable("TradingLimitTable"); dataTable.Columns.Add("Name", typeof(string)); dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["Name"] }; dataTable.Columns.Add("Gross", typeof(decimal)); dataTable.Columns.Add("Net", typeof(decimal)); this.TradingLimitTable = dataTable; dataTable = new DataTable("PortfolioTable"); dataTable.Columns.Add("Ticker", typeof(string)); dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["Ticker"] }; dataTable.Columns.Add("Position", typeof(decimal)); dataTable.Columns.Add("VWAP", typeof(decimal)); dataTable.Columns.Add("UnitMultiplier", typeof(int)); dataTable.Columns.Add("FutureMultiplier", typeof(int)); dataTable.Columns.Add("Type", typeof(SecurityType)); dataTable.Columns.Add("Realized", typeof(decimal)); dataTable.Columns.Add("Bid", typeof(decimal)); dataTable.Columns.Add("Ask", typeof(decimal)); dataTable.Columns.Add("BidSize", typeof(int)); dataTable.Columns.Add("AskSize", typeof(int)); dataTable.Columns.Add("Last", typeof(decimal)); dataTable.Columns.Add("NLV", typeof(decimal)); dataTable.Columns.Add("Unrealized", typeof(decimal), "IIF(FutureMultiplier=0,NLV,NLV-Position*VWAP*UnitMultiplier)"); dataTable.Columns.Add("Volume", typeof(decimal)); dataTable.Columns.Add("SecurityVWAP", typeof(decimal)); this.PortfolioTable = dataTable; dataTable = new DataTable("OrderTable"); dataTable.Columns.Add("ID", typeof(int)); dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["ID"] }; dataTable.Columns.Add("TraderID", typeof(string)); dataTable.Columns.Add("Price", typeof(decimal)); dataTable.Columns.Add("Volume", typeof(decimal)); dataTable.Columns.Add("VolumeRemaining", typeof(decimal)); dataTable.Columns.Add("Type", typeof(OrderType)); dataTable.Columns.Add("VWAP", typeof(decimal)); dataTable.Columns.Add("Period", typeof(int)); dataTable.Columns.Add("Tick", typeof(int)); dataTable.Columns.Add("Timestamp", typeof(System.DateTime)); dataTable.Columns.Add("Ticker", typeof(string)); dataTable.Columns.Add(new DataColumn("ColorState", typeof(int)) { DefaultValue = 0 }); this.OrderTable = dataTable; dataTable = new DataTable("OrderHistoryTable"); dataTable.Columns.Add("ID", typeof(int)); dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["ID"] }; dataTable.Columns.Add("Ticker", typeof(string)); dataTable.Columns.Add("Price", typeof(decimal)); dataTable.Columns.Add("Volume", typeof(decimal)); dataTable.Columns.Add("VolumeRemaining", typeof(decimal)); dataTable.Columns.Add("Type", typeof(OrderType)); dataTable.Columns.Add("VWAP", typeof(decimal)); dataTable.Columns.Add("Period", typeof(int)); dataTable.Columns.Add("Tick", typeof(int)); dataTable.Columns.Add("Timestamp", typeof(System.DateTime)); dataTable.Columns.Add("Status", typeof(OrderStatus)); this.OrderHistoryTable = dataTable; dataTable = new DataTable("TransactionTable"); dataTable.Columns.Add("ID", typeof(int)); dataTable.Columns["ID"].AutoIncrement = true; dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["ID"] }; dataTable.Columns.Add("Period", typeof(int)); dataTable.Columns.Add("Tick", typeof(int)); dataTable.Columns.Add("Timestamp", typeof(System.DateTime)); dataTable.Columns.Add("Ticker", typeof(string)); dataTable.Columns.Add("Price", typeof(decimal)); dataTable.Columns.Add("Quantity", typeof(decimal)); dataTable.Columns.Add("Currency", typeof(string)); dataTable.Columns.Add("Type", typeof(TransactionType)); dataTable.Columns.Add("Value", typeof(decimal)); dataTable.Columns.Add("Balance", typeof(decimal)); this.TransactionTable = dataTable; dataTable = new System.Collections.Generic.List<AssetParameters>().ToDataTable("AssetInfoTable"); dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["Ticker"] }; dataTable.Columns.Add("LeaseCount", typeof(int)); dataTable.Columns.Add("Realized", typeof(decimal)); this.AssetInfoTable = dataTable; dataTable = new System.Collections.Generic.List<AssetUpdateMessage>().ToDataTable("AssetTable"); dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["ID"] }; this.AssetTable = dataTable; this.Assets = new DataSet(); this.Assets.Tables.Add(this.AssetInfoTable); this.Assets.Tables.Add(this.AssetTable); this.Assets.Relations.Add(this.AssetInfoTable.Columns["Ticker"], this.AssetTable.Columns["Ticker"]); dataTable = new DataTable("NewsTable"); dataTable.Columns.Add("ID", typeof(int)); dataTable.Columns["ID"].AutoIncrement = true; dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["ID"] }; dataTable.Columns.Add("Period", typeof(int)); dataTable.Columns.Add("Tick", typeof(int)); dataTable.Columns.Add("Ticker", typeof(string)); dataTable.Columns.Add("Headline", typeof(string)); dataTable.Columns.Add("Body", typeof(string)); dataTable.Columns.Add(new DataColumn("IsRead", typeof(bool)) { DefaultValue = false }); dataTable.Columns.Add("ColorState", typeof(int)); this.NewsTable = dataTable; dataTable = new DataTable("TimeSalesTable"); dataTable.Columns.Add("ID", typeof(int)); dataTable.Columns["ID"].AutoIncrement = true; dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["ID"] }; dataTable.Columns.Add("Period", typeof(int)); dataTable.Columns.Add("Tick", typeof(int)); dataTable.Columns.Add("Ticker", typeof(string)); dataTable.Columns.Add("Price", typeof(decimal)); dataTable.Columns.Add("Volume", typeof(decimal)); dataTable.Columns.Add("Buyer/Seller", typeof(string)); dataTable.Columns.Add("Value", typeof(decimal), "Price*Volume"); this.TimeSalesTable = dataTable; dataTable = new DataTable("OTCOrderTable"); dataTable.Columns.Add("ID", typeof(int)); dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["ID"] }; dataTable.Columns.Add("TraderID", typeof(string)); dataTable.Columns.Add("Target", typeof(string)); dataTable.Columns.Add("Period", typeof(int)); dataTable.Columns.Add("Tick", typeof(int)); dataTable.Columns.Add("Ticker", typeof(string)); dataTable.Columns.Add("Volume", typeof(decimal)); dataTable.Columns.Add("Price", typeof(decimal)); dataTable.Columns.Add("SettlePeriod", typeof(int)); dataTable.Columns.Add("SettleTick", typeof(int)); dataTable.Columns.Add("Status", typeof(OTCStatus)); this.OTCOrderTable = dataTable; this.OpenOrderView = new UpdateableDataView(this.OrderTable, "", "Period DESC, Tick DESC, ID DESC", DataViewRowState.CurrentRows); this.ArchivedOrderView = new UpdateableDataView(this.OrderHistoryTable, string.Format("Type={0} OR Type={1}", 1, 0), "Period DESC, Tick DESC, ID DESC", DataViewRowState.CurrentRows); this.TenderView = new UpdateableDataView(this.OrderHistoryTable, string.Format("Type={0}", 2), "Period DESC, Tick DESC, ID DESC", DataViewRowState.CurrentRows); this.EndowmentView = new UpdateableDataView(this.OrderHistoryTable, string.Format("Type={0}", 3), "Period DESC, Tick DESC, ID DESC", DataViewRowState.CurrentRows); this.TransactionView = new UpdateableDataView(this.TransactionTable, "", "Period DESC, Tick DESC, ID DESC", DataViewRowState.CurrentRows); this.AssetContainerView = new UpdateableDataView(this.AssetInfoTable, string.Format("Type={0}", 0), "Ticker ASC", DataViewRowState.CurrentRows); this.AssetTransporterView = new UpdateableDataView(this.AssetInfoTable, string.Format("Type={0} OR Type={1}", 1, 2), "Ticker ASC", DataViewRowState.CurrentRows); this.AssetConverterView = new UpdateableDataView(this.AssetInfoTable, string.Format("Type={0} OR Type={1}", 3, 4), "Ticker ASC", DataViewRowState.CurrentRows); this.AssetProducerView = new UpdateableDataView(this.AssetInfoTable, string.Format("Type={0}", 5), "Ticker ASC", DataViewRowState.CurrentRows); this.MarketView = new UpdateableDataView(this.PortfolioTable); this.OTCCompletedOrderView = new UpdateableDataView(this.OTCOrderTable, string.Format("Status<>{0}", 0), "Period DESC, Tick DESC", DataViewRowState.CurrentRows); this.OTCPendingOrderView = new UpdateableDataView(this.OTCOrderTable, string.Format("Status={0}", 0), "Period DESC, Tick DESC", DataViewRowState.CurrentRows); this.NewsView = new UpdateableDataView(this.NewsTable, "", "Period DESC, Tick DESC, ID DESC", DataViewRowState.CurrentRows); this.NewsUnreadView = new UpdateableDataView(this.NewsTable, "IsRead=0", "", DataViewRowState.CurrentRows); this.NewsUnreadView.ListChanged += delegate(object sender, ListChangedEventArgs e) { this.UnreadNewsCount = ((DataView)sender).Count; }; this.OTCPendingOrderView.ListChanged += delegate(object sender, ListChangedEventArgs e) { this.PendingOTCCount = ((DataView)sender).Count; }; }