MCPcopy Create free account
hub / github.com/QuantFans/quantdigger / make_market

Method make_market

quantdigger/kernel/engine/exchange.py:18–52  ·  view source on GitHub ↗

价格撮合

(self, bar)

Source from the content-addressed store, hash-verified

16 self._strict = strict
17
18 def make_market(self, bar):
19 """ 价格撮合"""
20 if self._open_orders:
21 fill_orders = set()
22 for order in self._open_orders:
23 transact = Transaction(order)
24 if self._strict:
25 if order.price_type == PriceType.LMT:
26 # 限价单以最高和最低价格为成交的判断条件.
27 if (order.side == TradeSide.KAI and \
28 (order.direction == Direction.LONG and order.price >= bar.low or \
29 order.direction == Direction.SHORT and order.price <= bar.high)) or \
30 (order.kpp == TradeSide.PING and \
31 (order.direction == Direction.LONG and order.price <= bar.high or \
32 order.direction == Direction.SHORT and order.price >= bar.low)):
33 transact.price = order.price
34 # Bar的结束时间做为交易成交时间.
35 transact.datetime = bar.datetime
36 fill_orders.add(order)
37 self.events.put(FillEvent(transact))
38 elif order.type == PriceType.MKT:
39 # 市价单以最高或最低价格为成交价格.
40 if order.direction == Direction.LONG:
41 transact.price = bar.high
42 else:
43 transact.price = bar.low
44 transact.datetime = bar.datetime
45 fill_orders.add(order)
46 self.events.put(FillEvent(transact))
47 else:
48 transact.datetime = bar.datetime
49 fill_orders.add(order)
50 self.events.put(FillEvent(transact))
51 if fill_orders:
52 self._open_orders -= fill_orders
53
54
55 def insert_order(self, order_event):

Callers 1

runMethod · 0.80

Calls 3

TransactionClass · 0.90
FillEventClass · 0.90
putMethod · 0.80

Tested by

no test coverage detected