From 4cdf809d41d12d06e57840c02ec61bc10ef65bb5 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Thu, 9 May 2019 21:33:09 +0800 Subject: [PATCH] [Add] send_orders and cancel_orders function --- vnpy/trader/gateway.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/vnpy/trader/gateway.py b/vnpy/trader/gateway.py index ac2cd704..b7af2f59 100644 --- a/vnpy/trader/gateway.py +++ b/vnpy/trader/gateway.py @@ -3,7 +3,7 @@ """ from abc import ABC, abstractmethod -from typing import Any +from typing import Any, Sequence from copy import copy from vnpy.event import Event, EventEngine @@ -210,6 +210,29 @@ class BaseGateway(ABC): """ pass + def send_orders(self, reqs: Sequence[OrderRequest]): + """ + Send a batch of orders to server. + Use a for loop of send_order function by default. + Reimplement this function if batch order supported on server. + """ + vt_orderids = [] + + for req in reqs: + vt_orderid = self.send_order(req) + vt_orderids.append(vt_orderid) + + return vt_orderids + + def cancel_orders(self, reqs: Sequence[CancelRequest]): + """ + Cancel a batch of orders to server. + Use a for loop of cancel_order function by default. + Reimplement this function if batch cancel supported on server. + """ + for req in reqs: + self.cancel_order(req) + @abstractmethod def query_account(self): """