Example #1
0
 public BrokerBalance GetBalance()
 {
     try
     {
         Log.Debug("Hpx GetBalance Begin");
         var    path = "/api/v2/getAccountInfo?";
         string body = "method=getAccountInfo&accesskey=" + _config.Key;
         path += body;
         var req = BuildRequest(path, "GET", body);
         RestUtil.LogRestRequest(req);
         var response = _restClient.Execute(req);
         if (response == null || response.StatusCode == 0)
         {
             Log.Debug($"Hpx GetBalance response is null or failed ...");
             return(null);
         }
         JObject j = JObject.Parse(response.Content);
         j = JObject.Parse(j["data"].ToString());
         j = JObject.Parse(j["balance"].ToString());
         BrokerBalance bb = new BrokerBalance();
         bb.Broker = Broker;
         bb.Leg1   = decimal.Parse(j[_config.Leg1.ToUpper()].ToString());
         bb.Leg2   = decimal.Parse(j[_config.Leg2.ToUpper()].ToString());
         Log.Debug("Hpx GetBalance End");
         return(bb);
     }
     catch (Exception ex)
     {
         Log.Debug("Hpx GetBalance Exception:" + ex.Message);
         return(null);
     }
 }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="tradeType"> 挂单类型 1/0[buy/sell]</param>
 /// <returns></returns>
 public string GetOrdersState(int pageIndex, int tradeType)
 {
     try
     {
         Log.Debug("Hpx GetOrdersState Begin");
         var    path = "/api/v2/getOrders?";
         string body = "method=getOrders&accesskey=" + _config.Key + $"&tradeType={tradeType}&currency={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}&pageIndex=1&pageSize=100";
         path += body;
         var req = BuildRequest(path, "GET", body);
         RestUtil.LogRestRequest(req);
         var response = _restClient.Execute(req);
         if (response == null || response.StatusCode == 0)
         {
             Log.Debug($"Hpx GetOrderState response is null or failed ...");
             return(null);
         }
         Log.Debug("Hpx GetOrdersState End");
         return(response.Content);
     }
     catch (Exception ex)
     {
         Log.Debug($"Hpx GetOrdersState Exception:" + ex.Message);
         return(null);
     }
 }
Example #3
0
 private SendReply Send(SendOrderParam param)
 {
     try
     {
         Log.Debug("Hpx Send Begin");
         var    path      = "/api/v2/order?";
         int    tradetype = param.side == "buy" ? 0 : 1;
         string body      = $"method=order&accesskey=" + _config.Key + $"&amount={param.quantity}&currency={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}&price={param.price}&tradeType={tradetype}";
         path += body;
         var req = BuildRequest(path, "GET", body);
         RestUtil.LogRestRequest(req);
         var response = _restClient.Execute(req);
         if (response == null || response.StatusCode == 0)
         {
             Log.Debug($"Hpx Send response is null or failed ...");
             return(new SendReply()
             {
                 code = "-1"
             });
         }
         JObject   j     = JObject.Parse(response.Content);
         SendReply reply = j.ToObject <SendReply>();
         Log.Debug("Hpx Send End");
         return(reply);
     }
     catch (Exception ex)
     {
         Log.Debug($"Hpx Send Exception:" + ex.Message);
         return(null);
     }
 }
Example #4
0
 private OrderStateReply GetOrderState(string id)
 {
     try
     {
         Log.Debug("Hpx GetOrderState Begin");
         var    path = "/api/v2/getOrder?";
         string body = "method=getOrder&accesskey=" + _config.Key + $"&id={id}&currency={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}";
         path += body;
         var req = BuildRequest(path, "GET", body);
         RestUtil.LogRestRequest(req);
         var response = _restClient.Execute(req);
         if (response == null || response.StatusCode == 0 || response.Content.IndexOf("total_amount") < 0)
         {
             Log.Debug($"Hpx GetOrderState response is null or failed ...");
             return(null);
         }
         JObject j = JObject.Parse(response.Content);
         j = JObject.Parse(j["data"].ToString());
         OrderStateReply reply = j.ToObject <OrderStateReply>();
         Log.Debug("Hpx GetOrderState End");
         return(reply);
     }
     catch (Exception ex)
     {
         Log.Debug($"Hpx GetOrderState Exception:" + ex.Message);
         return(null);
     }
 }
Example #5
0
        private SendReply Send(SendOrderParam param)
        {
            var    path      = "/api/order?";
            int    tradetype = param.side == "buy" ? 1 : 0;
            string body      = "accesskey=" + _config.Key + $"&amount={param.quantity}&currency={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}&method=order&price={param.price}&tradeType={tradetype}";

            path += body;
            var req = BuildRequest(path, "GET", body);

            RestUtil.LogRestRequest(req);
            SetBaseUrl("trade");
            var response = _restClient.Execute(req);

            if (response == null || response.StatusCode == 0)
            {
                Log.Debug($"Zb Send response is null or failed ...");
                return(new SendReply()
                {
                    code = "-1"
                });
            }
            JObject   j     = JObject.Parse(response.Content);
            SendReply reply = j.ToObject <SendReply>();

            return(reply);
        }
Example #6
0
 public BrokerBalance GetBalance()
 {
     try
     {
         Log.Debug($"Zb GetBalance Start ...");
         var    path = "/api/getAccountInfo?";
         string body = "accesskey=" + _config.Key + "&method=getAccountInfo";
         path += body;
         var req = BuildRequest(path, "GET", body);
         RestUtil.LogRestRequest(req);
         SetBaseUrl("trade");
         var response = _restClient.Execute(req);
         if (response == null || response.StatusCode == 0)
         {
             Log.Debug($"Zb GetBalance response is null or failed ...");
             return(null);
         }
         JObject j = JObject.Parse(response.Content);
         j = JObject.Parse(j["result"].ToString());
         JArray  jar   = JArray.Parse(j["coins"].ToString());
         JObject jleg1 = null;
         JObject jleg2 = null;
         foreach (JObject jj in jar)
         {
             if (jj["enName"].ToString().ToUpper() == _config.Leg1.ToUpper())
             {
                 jleg1 = jj;
             }
             if (jj["enName"].ToString().ToUpper() == _config.Leg2.ToUpper())
             {
                 jleg2 = jj;
             }
             if (jleg1 != null && jleg2 != null)
             {
                 break;
             }
         }
         BrokerBalance bb = new BrokerBalance();
         bb.Broker = Broker;
         bb.Leg1   = decimal.Parse(jleg1["available"].ToString());
         bb.Leg2   = decimal.Parse(jleg2["available"].ToString());
         Log.Debug($"Zb GetBalance End ...");
         return(bb);
     }
     catch (Exception ex)
     {
         Log.Debug($"Zb GetBalance response is null or failed ...{ex.Message}");
         return(null);
     }
 }
Example #7
0
        private void Cancel(string orderId)
        {
            var    path = "/api/cancelOrder?";
            string body = "accesskey=" + _config.Key + $"&currency={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}&id={orderId}&method=cancelOrder";

            path += body;
            var req = BuildRequest(path, "GET", body);

            SetBaseUrl("trade");
            RestUtil.LogRestRequest(req);
            var response = _restClient.Execute(req);

            if (response == null || response.StatusCode == 0)
            {
                Log.Debug($"Zb Cancel response is null or failed ...");
                Cancel(orderId);
            }
        }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tradeType"> 挂单类型 1/0[buy/sell]</param>
        /// <returns></returns>
        public string GetOrdersState(int pageIndex, int tradeType)
        {
            var    path = "/api/getOrders?";
            string body = "accesskey=" + _config.Key + $"&currency={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}&method=getOrders&pageIndex={pageIndex}&tradeType={tradeType}";

            path += body;
            var req = BuildRequest(path, "GET", body);

            RestUtil.LogRestRequest(req);
            SetBaseUrl("trade");
            var response = _restClient.Execute(req);

            if (response == null || response.StatusCode == 0)
            {
                Log.Debug($"Zb GetOrderaState response is null or failed ...");
                return(null);
            }
            return(response.Content);
        }
Example #9
0
        private OrderStateReply GetOrderState(string id)
        {
            var    path = "/api/getOrder?";
            string body = "accesskey=" + _config.Key + $"&currency={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}&id={id}&method=getOrder";

            path += body;
            var req = BuildRequest(path, "GET", body);

            RestUtil.LogRestRequest(req);
            SetBaseUrl("trade");
            var response = _restClient.Execute(req);

            if (response == null || response.StatusCode == 0)
            {
                Log.Debug($"Zb GetOrderState response is null or failed ...");
                return(null);
            }
            JObject         j     = JObject.Parse(response.Content);
            OrderStateReply reply = j.ToObject <OrderStateReply>();

            return(reply);
        }
Example #10
0
 private void Cancel(string orderId)
 {
     try
     {
         Log.Debug("Hpx Cancel Begin");
         var    path = "/api/v2/cancel?";
         string body = "method=cancel&accesskey=" + _config.Key + $"&id={orderId}&currency={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}";
         path += body;
         var req = BuildRequest(path, "GET", body);
         RestUtil.LogRestRequest(req);
         var response = _restClient.Execute(req);
         if (response == null || response.StatusCode == 0)
         {
             Log.Debug($"Hpx Cancel response is null or failed ...");
             Cancel(orderId);
         }
         Log.Debug("Hpx Cancel End");
     }
     catch (Exception ex)
     {
         Log.Debug($"Hpx Cancel Exception:" + ex.Message);
     }
 }