public void onTick(GMSDK.Tick tick) { lock (this.newTickLock) { this.setNewTick(tick, true); } }
public static GMTrade ConvertTrade(GMSDK.Tick gskTick) { char buyOrSell = 'N'; switch (gskTick.trade_type) { case 0: break; case 7: buyOrSell = 'B'; break; case 8: buyOrSell = 'S'; break; } return(new GMTrade(startTimeUTC.AddSeconds(gskTick.utc_time), gskTick.last_price, gskTick.last_volume, buyOrSell, gskTick.last_amount, gskTick.cum_volume, gskTick.cum_amount, gskTick.high, gskTick.low, gskTick.open, gskTick.pre_close, gskTick.upper_limit, gskTick.lower_limit)); }
private void setNewTick(GMSDK.Tick tick, bool isPush = false) { string symbol = tick.exchange + "." + tick.sec_id; if (isPush) { this.symbolsOfPush.Add(symbol); } if (!subscribedSymbols.Contains(symbol)) { return; } Instrument curInstrument = InstrumentManager.Instruments[symbol]; if (curInstrument == null) { this.EmitError(2, "Symbol " + symbol + " was not found in InstrumentManager."); return; } GMSDK.Tick prevTick = null; if (!this.tickCache.TryGetValue(symbol, out prevTick)) { this.EmitNewTrade(GSKToGM.ConvertTrade(tick), curInstrument); this.EmitNewQuote(GSKToGM.ConvertQuote(tick), curInstrument); } else { if (tick.utc_time > prevTick.utc_time) { if (tick.last_volume > 0 || tick.last_price != prevTick.last_price) { this.EmitNewTrade(GSKToGM.ConvertTrade(tick), curInstrument); } this.EmitNewQuote(GSKToGM.ConvertQuote(tick), curInstrument); } } this.tickCache[symbol] = tick; }
public static GMLastTick ConvertTick(GMSDK.Tick gskTick) { char buyOrSell = 'N'; switch (gskTick.trade_type) { case 0: break; case 7: buyOrSell = 'B'; break; case 8: buyOrSell = 'S'; break; } return(new GMLastTick(startTimeUTC.AddSeconds(gskTick.utc_time), gskTick.last_price, gskTick.last_volume, buyOrSell, gskTick.last_amount, gskTick.cum_volume, gskTick.cum_amount, gskTick.high, gskTick.low, gskTick.open, gskTick.pre_close, gskTick.upper_limit, gskTick.lower_limit, gskTick.bid_p1, gskTick.bid_v1, gskTick.ask_p1, gskTick.ask_v1, gskTick.bid_p2, gskTick.bid_p3, gskTick.bid_p4, gskTick.bid_p5, gskTick.bid_v2, gskTick.bid_v3, gskTick.bid_v4, gskTick.bid_v5, gskTick.ask_p2, gskTick.ask_p3, gskTick.ask_p4, gskTick.ask_p5, gskTick.ask_v2, gskTick.ask_v3, gskTick.ask_v4, gskTick.ask_v5)); }
public ReportArgs GetQuotes(List <string> symbols) { List <string> securityIDs = new List <string>(); List <byte> marketIDs = new List <byte>(); foreach (string symbol in symbols) { string[] temp = symbol.Split('.'); string market = temp[0]; byte marketID = 0; switch (market) { case "SHSE": marketID = 1; break; case "SZSE": marketID = 0; break; } marketIDs.Add(marketID); string securityID = temp[1]; securityIDs.Add(securityID); } short count = (short)securityIDs.Count; ReportArgs reportArgs = new ReportArgs(); StringBuilder errInfo = new StringBuilder(256); StringBuilder result = new StringBuilder(1024 * 1024); if (TdxHqWrapper.TdxHq_GetSecurityQuotes(marketIDs.ToArray(), securityIDs.ToArray(), ref count, result, errInfo)) { reportArgs.Succeeded = true; List <GMSDK.Tick> ticks = new List <GMSDK.Tick>(); List <string[]> data = this.pickUp(result); for (int i = 1; i < data.Count; i++) { GMSDK.Tick tick = new GMSDK.Tick(); int marketID = int.Parse(data[i][0]); switch (marketID) { case 0: tick.exchange = "SZSE"; break; case 1: tick.exchange = "SHSE"; break; } tick.sec_id = data[i][1]; tick.last_price = float.Parse(data[i][3]); tick.pre_close = float.Parse(data[i][4]); tick.open = float.Parse(data[i][5]); tick.high = float.Parse(data[i][6]); tick.low = float.Parse(data[i][7]); tick.utc_time = double.Parse(data[i][8]); tick.cum_volume = double.Parse(data[i][10]); tick.last_volume = int.Parse(data[i][11]); tick.cum_amount = double.Parse(data[i][12]); tick.bid_p1 = float.Parse(data[i][17]); tick.ask_p1 = float.Parse(data[i][18]); tick.bid_v1 = int.Parse(data[i][19]); tick.ask_v1 = int.Parse(data[i][20]); tick.bid_p2 = float.Parse(data[i][21]); tick.ask_p2 = float.Parse(data[i][22]); tick.bid_v2 = int.Parse(data[i][23]); tick.ask_v2 = int.Parse(data[i][24]); tick.bid_p3 = float.Parse(data[i][25]); tick.ask_p3 = float.Parse(data[i][26]); tick.bid_v3 = int.Parse(data[i][27]); tick.ask_v3 = int.Parse(data[i][28]); tick.bid_p4 = float.Parse(data[i][29]); tick.ask_p4 = float.Parse(data[i][30]); tick.bid_v4 = int.Parse(data[i][31]); tick.ask_v4 = int.Parse(data[i][32]); tick.bid_p5 = float.Parse(data[i][33]); tick.ask_p5 = float.Parse(data[i][34]); tick.bid_v5 = int.Parse(data[i][35]); tick.ask_v5 = int.Parse(data[i][36]); tick.upper_limit = (float)(tick.pre_close * 1.1); tick.lower_limit = (float)(tick.pre_close * 0.9); ticks.Add(tick); } reportArgs.Result = ticks; } else { reportArgs.Succeeded = false; reportArgs.ErrorInfo = errInfo.ToString(); } return(reportArgs); }
public static GMQuote ConvertQuote(GMSDK.Tick gskTick) { return(new GMQuote(startTimeUTC.AddSeconds(gskTick.utc_time), gskTick.bid_p1, gskTick.bid_v1, gskTick.ask_p1, gskTick.ask_v1, gskTick.bid_p2, gskTick.bid_p3, gskTick.bid_p4, gskTick.bid_p5, gskTick.bid_v2, gskTick.bid_v3, gskTick.bid_v4, gskTick.bid_v5, gskTick.ask_p2, gskTick.ask_p3, gskTick.ask_p4, gskTick.ask_p5, gskTick.ask_v2, gskTick.ask_v3, gskTick.ask_v4, gskTick.ask_v5)); }
public List <GMSDK.Tick> GetQuotes(List <string> symbols) { List <GMSDK.Tick> ticks = new List <GMSDK.Tick>(); if (symbols.Count <= 0) { return(ticks); } List <string> quoteStrings = new List <string>(); int k = 10; int m = symbols.Count / k + 1; for (int j = 0; j < m; j++) { int start = j * k; int n = symbols.Count - start; if (n > k) { n = k; } List <string> subSymbols = symbols.GetRange(start, n); string url = this.urlBase + "list="; for (int i = 0; i < subSymbols.Count; i++) { string newSymbol = this.ConvertSymbol(subSymbols[i]); if (i > 0) { url += "," + newSymbol; } else { url += newSymbol; } } Stream str = this._client.OpenRead(url); StreamReader reader = new StreamReader(str); //Console.WriteLine(url); string aQuote; while ((aQuote = reader.ReadLine()) != null) { quoteStrings.Add(aQuote); } str.Close(); } DateTime startTimeUTC = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); for (int i = 0; i < symbols.Count; i++) { string[] data = quoteStrings[i].Split(','); if (data.Length >= 33) { GMSDK.Tick aTick = new GMSDK.Tick(); aTick.open = float.Parse(data[1]); aTick.pre_close = float.Parse(data[2]); aTick.last_price = float.Parse(data[3]); aTick.high = float.Parse(data[4]); aTick.low = float.Parse(data[5]); aTick.cum_volume = double.Parse(data[8]); aTick.cum_amount = double.Parse(data[9]); aTick.bid_v1 = int.Parse(data[10]); aTick.bid_p1 = float.Parse(data[11]); aTick.bid_v2 = int.Parse(data[12]); aTick.bid_p2 = float.Parse(data[13]); aTick.bid_v3 = int.Parse(data[14]); aTick.bid_p3 = float.Parse(data[15]); aTick.bid_v4 = int.Parse(data[16]); aTick.bid_p4 = float.Parse(data[17]); aTick.bid_v5 = int.Parse(data[18]); aTick.bid_p5 = float.Parse(data[19]); aTick.ask_v1 = int.Parse(data[20]); aTick.ask_p1 = float.Parse(data[21]); aTick.ask_v2 = int.Parse(data[22]); aTick.ask_p2 = float.Parse(data[23]); aTick.ask_v3 = int.Parse(data[24]); aTick.ask_p3 = float.Parse(data[25]); aTick.ask_v4 = int.Parse(data[26]); aTick.ask_p4 = float.Parse(data[27]); aTick.ask_v5 = int.Parse(data[28]); aTick.ask_p5 = float.Parse(data[29]); aTick.strtime = data[30] + " " + data[31]; DateTime time = DateTime.Parse(aTick.strtime); aTick.utc_time = (time - startTimeUTC).TotalSeconds; string[] temp = symbols[i].Split('.'); aTick.exchange = temp[0]; aTick.sec_id = temp[1]; ticks.Add(aTick); } } return(ticks); }