using YLErp.Modules.TradeRiskCalcModule; namespace YLErp.Modules.ApiModule { /// /// TapConsoleApi /// public static class TapConsoleApiHelper { public const string SimpleKey = "6ZWS6ZO+56eR5oqA5pyJ6ZmQ5YWs5Y+4OnNoYW5naGFpemlsYWlzaHVpbGFpemloYWlzaGFuZw=="; public static string GetTradeRiskResults(TradingRiskReqModel reqModel) { return PostJson("/api/v100/traderisk", reqModel); } public static string GetTradeRiskPriceCalcResults(TradingRiskPriceCalcReqModel reqModel) { return PostJson("/api/v100/traderisk_pricecalc", reqModel); } public static string GetSysInfo() { return PostJson("api/sysinfo/index", null); } public static string GetDataCacheTables() { return PostJson("api/sysinfo/DataCache/tables", null); } public static string GetDataCacheData(string tableName) { return PostJson("api/sysinfo/DataCache/data?tableName=" + tableName, null); } /// /// /// public static string GetTradePnlStaticsData() { return PostJson("api/v1/tradePnlStaticsData", null); } //------------------------------------------------ static readonly HttpClientWrap _httpClientWrap; static TapConsoleApiHelper() { _httpClientWrap = new HttpClientWrap(PS.Config.ErpElement.TapConsoleWebServer); } public static string PostJson(string apiPath, object postData) { if (_httpClientWrap.BaseAddress == null) { throw new ServiceException("TapConsoleWebServer未配置"); } try { return _httpClientWrap.PostJson(apiPath, postData, req => { req.Headers.Add("Authorization", "Basic " + SimpleKey); }); } catch (Exception ex) { if (apiPath != "/api/v100/traderisk") { LogFactory.GetLogger("TapConsoleAPI-Post").Error(apiPath, ex); } throw new ServiceException(ex.Messages()); } } } }