private void WriteAskingPrice(string key, AskingPrice price) { try { var conn = GetConnection(key); var time = price.Time.ToString("yyyy-MM-dd HH:mm:ss.ff"); var sql = string.Format("insert into prices(time, nav, sell1, sell1_cnt, sell2, sell2_cnt, " + "buy1, buy1_cnt, buy2, buy2_cnt) values ( '{0}', {1}", time, price.Nav); for (int i = 0; i < LogPriceCount; ++i) { sql += "," + price.Sell[i].Price + "," + price.Sell[i].Quantity; } for (int i = 0; i < LogPriceCount; ++i) { sql += "," + price.Buy[i].Price + "," + price.Buy[i].Quantity; } sql += ")"; SQLiteCommand command = new SQLiteCommand(sql, conn); int result = command.ExecuteNonQuery(); } catch (Exception e) { Debug.Error(e.ToString()); } }
public void SetAskingPrice(string code, AskingPrice price) { foreach (var balance in _stockInfos) { if (balance.Stock.Code == code) { balance.AskingPrice = price; } } if (Phase == EPhase.Price) { ProcessPhase(); } }
private void OpenApi_ReceivedRealData(_DKHOpenAPIEvents_OnReceiveRealDataEvent real) { if (real.sRealType == "ETF NAV") { var nav = OpenApi.GetRealData(real.sRealKey, 36); _navs[real.sRealKey] = Math.Abs(nav.ToFloat()); return; } DateTime now = DateTime.Now; //DateTime time; //var strTime = OpenApi.GetRealData(real.sRealKey, 21); //if (DateTime.TryParseExact(strTime, // "HHmmss", CultureInfo.CurrentCulture, DateTimeStyles.None, out time)) //{ // now = new DateTime(now.Year, now.Month, now.Day, time.Hour, time.Minute, time.Second); //} var askingPrice = new AskingPrice(now); for (int i = 0; i < OpenApi.RealPriceCount; ++i) { askingPrice.Sell.Add(new Asking { Price = Math.Abs(OpenApi.GetRealData(real.sRealKey, i + 41).ToInt()), Quantity = OpenApi.GetRealData(real.sRealKey, i + 61).ToInt(), }); askingPrice.Buy.Add(new Asking { Price = Math.Abs(OpenApi.GetRealData(real.sRealKey, i + 51).ToInt()), Quantity = OpenApi.GetRealData(real.sRealKey, i + 71).ToInt(), }); } _navs.TryGetValue(real.sRealKey, out askingPrice.Nav); if (_trader != null) { _trader.SetAskingPrice(real.sRealKey, askingPrice); } WriteAskingPrice(real.sRealKey, askingPrice); }