/// <summary> /// 获取用户的UID信息 /// 通常创建后要先调用这个来得到UID,后继大量操作都需要UID才能进行。 /// </summary> /// <returns></returns> public async Task <string> GetUserInfoAsync() { var url = $"{m_url}/req/GetUserInfo"; using (var httpClient = new HttpClient()) { var args = new RestTradeMessageRequest("GetUserInfo", null); var content = new StringContent(args.GetSignedTxt(m_uname, m_apikey, m_apisecret), 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) { var dict = Helper.MyJsonSafeToObj <Dictionary <string, string> >(resp.Data); if (dict.ContainsKey("UserID")) { this.m_uid = dict["UserID"]; } return(this.m_uid); } throw new InvalidOperationException($"invalid response: code={resp?.Code}"); } }
/// <summary> /// 调整保证金 /// </summary> /// <param name="accType"></param> /// <param name="sym"></param> /// <param name="postionId"></param> /// <param name="param"></param> /// <returns></returns> public async Task <int> PosTransMgnAsync(int accType, string sym, string postionId, decimal param) { var url = $"{m_url}/req/PosTransMgn"; using (var httpClient = new HttpClient()) { var args = new RestTradeMessageRequest("PosTransMgn", new Dictionary <string, object>() { { "AId", m_uid + accType.ToString("D2") }, { "Sym", sym }, { "PId", postionId }, { "Param", param }, }); var content = new StringContent(args.GetSignedTxt(m_uname, m_apikey, m_apisecret), 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) { return(resp.Code); } throw new InvalidOperationException($"invalid response: code={resp?.Code}"); } }
/// <summary> /// 设置超时撤单 /// </summary> /// <param name="accType"></param> /// <param name="sec"></param> /// <returns></returns> public async Task <int> CancelAllAfterAsync(int accType, int sec) { var url = $"{m_url}/req/CancelAllAfter"; using (var httpClient = new HttpClient()) { var args = new RestTradeMessageRequest("CancelAllAfter", new Dictionary <string, object>() { { "AId", m_uid + accType.ToString("D2") }, { "Sec", sec } }); var content = new StringContent(args.GetSignedTxt(m_uname, m_apikey, m_apisecret), 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) { //var retinfo = Helper.MyJsonSafeToObj<Dictionary<string,object>>(resp.Data); // Code Name Msg return(resp.Code); } throw new InvalidOperationException($"invalid response: code={resp?.Code}"); } }
/// <summary> /// 查用户的风险限额 /// </summary> /// <param name="accType"></param> /// <param name="sym"></param> /// <returns></returns> public async Task <Models.RiskLimit> GetRiskLimitAsync(int accType, string sym) { var url = $"{m_url}/req/GetRiskLimit"; using (var httpClient = new HttpClient()) { var args = new RestTradeMessageRequest("GetRiskLimit", new Dictionary <string, object>() { { "AId", m_uid + accType.ToString("D2") }, { "Sym", sym } }); var content = new StringContent(args.GetSignedTxt(m_uname, m_apikey, m_apisecret), 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.RiskLimit>(resp.Data)); } throw new InvalidOperationException($"invalid response: code={resp?.Code}"); } }
/// <summary> /// 扯单 /// </summary> /// <param name="ord"></param> /// <returns></returns> public async Task <Models.Ord> OrderDelAsync(Models.Ord ord) { var url = $"{m_url}/req/OrderDel"; using (var httpClient = new HttpClient()) { //ord.AId = m_uid + accType.ToString("D2"); var args = new RestTradeMessageRequest("OrderDel", ord); var content = new StringContent(args.GetSignedTxt(m_uname, m_apikey, m_apisecret), 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.Ord>(resp.Data)); } throw new InvalidOperationException($"invalid response: code={resp?.Code}"); } }
/// <summary> /// 查资金中心/我的钱包 /// </summary> /// <returns></returns> public async Task <List <Models.CcsWallet> > GetCcsWalletsAsync() { var url = $"{m_url}/req/GetCcsWallets"; using (var httpClient = new HttpClient()) { //var args = new RestTradeMessageRequest("GetWallets", new Dictionary<string, object>() { { "AId", m_uid + "00" } }); var args = new RestTradeMessageRequest("GetCcsWallets", null); var content = new StringContent(args.GetSignedTxt(m_uname, m_apikey, m_apisecret), 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 <List <Models.CcsWallet> >(resp.Data)); } throw new InvalidOperationException($"invalid response: code={resp?.Code}"); } }