public async Task REQ_GetLatestKLine(string sym, Models.MktKLineType typ, int count, Action <int, Models.MktQueryKLineHistoryResult> cb, CancellationToken cancellationToken) { var args = new Models.MktQueryKLineHistoryRequestArgs { Sym = sym, Typ = typ, Count = count }; var req = new WsMarketMessageRequest("GetLatestKLine", args); await this.SendRequestAsync(req, (code, data) => { //Models.MxQueryKLineHistoryResult result = new Models.MxQueryKLineHistoryResult(); if (code == 0) { var res = Helper.MyJsonSafeToObj <Models.MktQueryKLineHistoryResult>(data); cb(code, res); } else { Debug.WriteLine("[-] GetLatestKLine failed: " + data.ToString()); cb(code, null); } }, cancellationToken); }
public async Task <Models.MktQueryKLineHistoryResult> GetHistKLineAsync(string sym, Models.MktKLineType typ, int beginSec, int offset, int count) { var url = $"{m_url}/GetHistKLine"; using (var httpClient = new HttpClient()) { var args = new Models.MktQueryKLineHistoryRequestArgs(); args.Sym = sym; args.Typ = typ; args.Sec = beginSec; args.Offset = offset; args.Count = count; var content = new StringContent(Helper.MyJsonMarshal(args), Encoding.UTF8, "application/json"); var res = await httpClient.PostAsync(url, content); var contentStr = await res.Content.ReadAsStringAsync(); var resp = Helper.MyJsonUnmarshal <RestResponse>(contentStr); if (resp != null && resp.Code == 0) { return(Helper.MyJsonSafeToObj <Models.MktQueryKLineHistoryResult>(resp.Data)); } throw new InvalidOperationException($"invalid response: code={resp?.Code}"); } }
public async Task REQ_Sub_kline_xxx(string sym, Models.MktKLineType typ, Action <int, string> cb, CancellationToken cancellationToken, bool unSub) { await REQ_Sub(new List <string> { K_SUBJ_KLINE + "_" + Gmex.API.Helper.GetEnumMemberValue(typ) + "_" + sym }, cb, cancellationToken, unSub); }