public void Send(Order order) { if (order.Broker != Broker) { throw new InvalidOperationException(); } SendOrderParam param = new SendOrderParam(order); var reply = Send(param); if (reply.code.Trim() == "3001") { order.BrokerOrderId = "0x3fffff";//余额不足 return; } if (reply.code.Trim() != "0000") { order.Status = OrderStatus.Rejected; Log.Info("Hpx Send: " + reply.message); return; } order.BrokerOrderId = reply.id; order.Status = OrderStatus.New; order.SentTime = DateTime.Now; order.LastUpdated = DateTime.Now; }
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}¤cy={_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); } }