| 24 | |
| 25 | |
| 26 | class TestApp(EClient, EWrapper): |
| 27 | def __init__(self): |
| 28 | EClient.__init__(self, self) |
| 29 | self.nextValidOrderId = None |
| 30 | self.permId2ord = {} |
| 31 | |
| 32 | @iswrapper |
| 33 | def nextValidId(self, orderId: int): |
| 34 | super().nextValidId(orderId) |
| 35 | logging.debug("setting nextValidOrderId: %d", orderId) |
| 36 | self.nextValidOrderId = orderId |
| 37 | |
| 38 | def placeOneOrder(self): |
| 39 | con = Contract() |
| 40 | con.symbol = "AMD" |
| 41 | con.secType = "STK" |
| 42 | con.currency = "USD" |
| 43 | con.exchange = "SMART" |
| 44 | order = Order() |
| 45 | order.action = "BUY" |
| 46 | order.orderType = "LMT" |
| 47 | order.tif = "GTC" |
| 48 | order.totalQuantity = 3 |
| 49 | order.lmtPrice = 1.23 |
| 50 | self.placeOrder(self.nextOrderId(), con, order) |
| 51 | |
| 52 | def cancelOneOrder(self): |
| 53 | pass |
| 54 | |
| 55 | def nextOrderId(self): |
| 56 | id_ = self.nextValidOrderId |
| 57 | self.nextValidOrderId += 1 |
| 58 | return id_ |
| 59 | |
| 60 | @iswrapper |
| 61 | def error(self, *args): |
| 62 | super().error(*args) |
| 63 | print(current_fn_name(), vars()) |
| 64 | |
| 65 | @iswrapper |
| 66 | def winError(self, *args): |
| 67 | super().error(*args) |
| 68 | print(current_fn_name(), vars()) |
| 69 | |
| 70 | @iswrapper |
| 71 | def openOrder( |
| 72 | self, orderId: OrderId, contract: Contract, order: Order, orderState: OrderState |
| 73 | ): |
| 74 | super().openOrder(orderId, contract, order, orderState) |
| 75 | print(current_fn_name(), vars()) |
| 76 | |
| 77 | order.contract = contract |
| 78 | self.permId2ord[order.permId] = order |
| 79 | |
| 80 | @iswrapper |
| 81 | def openOrderEnd(self, *args): |
| 82 | super().openOrderEnd() |
| 83 | logging.debug("Received %d openOrders", len(self.permId2ord)) |