diff --git a/vnpy/api/rest/rest_client.py b/vnpy/api/rest/rest_client.py index 7bd4568e..ead3992f 100644 --- a/vnpy/api/rest/rest_client.py +++ b/vnpy/api/rest/rest_client.py @@ -49,6 +49,10 @@ class Request(object): self.response = None self.status = RequestStatus.ready + self.json=None + + def set_json(self, json_str: dict): + self.json=json_str def __str__(self): if self.response is None: @@ -61,6 +65,7 @@ class Request(object): "headers: {}\n" "params: {}\n" "data: {}\n" + "json: {}\n" "response:" "{}\n".format( self.method, @@ -70,6 +75,7 @@ class Request(object): self.headers, self.params, self.data, + self.json, "" if self.response is None else self.response.text, ) ) @@ -145,6 +151,7 @@ class RestClient(object): on_failed: Callable = None, on_error: Callable = None, extra: Any = None, + json_str: dict = None, ): """ Add a new request. @@ -170,6 +177,8 @@ class RestClient(object): on_error, extra, ) + if json_str is not None: + request.set_json(json_str) self._queue.put(request) return request @@ -253,10 +262,10 @@ class RestClient(object): headers=request.headers, params=request.params, data=request.data, + json=request.json, proxies=self.proxies, ) request.response = response - status_code = response.status_code if status_code // 100 == 2: # 2xx都算成功,尽管交易所都用200 jsonBody = response.json() diff --git a/vnpy/gateway/alpaca/alpaca_gateway.py b/vnpy/gateway/alpaca/alpaca_gateway.py index d102403b..3d938b44 100644 --- a/vnpy/gateway/alpaca/alpaca_gateway.py +++ b/vnpy/gateway/alpaca/alpaca_gateway.py @@ -265,26 +265,22 @@ class AlpacaRestApi(RestClient): orderid = str(self.connect_time + self._new_order_id()) data = { "symbol": req.symbol, - "qty":2, - "side":'buy', - "type":'limit', + "qty": int(req.volume), + "side": DIRECTION_VT2ALPACA[req.direction], + "type": ORDERTYPE_VT2ALPACA[req.type], "time_in_force":'opg', - "limit_price":20.50 -# "side": DIRECTION_VT2BITMEX[req.direction], -# "ordType": ORDERTYPE_VT2BITMEX[req.type], -# "orderQty": int(req.volume), -# "clOrdID": orderid, + "limit_price": float(req.price) } order = req.create_order_data(orderid, self.gateway_name) - print("debug detail order: ",order) self.add_request( "POST", "/v1/orders", callback=self.on_send_order, - data=data, + #data=data, extra=order, on_failed=self.on_failed, on_error=self.on_error, + json_str=data, ) self.gateway.on_order(order) return order.vt_orderid