|
12 | 12 |
|
13 | 13 | from copy import copy |
14 | 14 | from datetime import datetime |
15 | | -from queue import Empty |
16 | 15 | from threading import Thread, Condition |
17 | 16 | from typing import Optional |
18 | 17 | import shelve |
19 | 18 | from tzlocal import get_localzone |
20 | 19 |
|
21 | | -from ibapi import comm |
22 | 20 | from ibapi.client import EClient |
23 | | -from ibapi.common import MAX_MSG_LEN, NO_VALID_ID, OrderId, TickAttrib, TickerId |
| 21 | +from ibapi.common import OrderId, TickAttrib, TickerId |
24 | 22 | from ibapi.contract import Contract, ContractDetails |
25 | 23 | from ibapi.execution import Execution |
26 | 24 | from ibapi.order import Order |
27 | 25 | from ibapi.order_state import OrderState |
28 | 26 | from ibapi.ticktype import TickType, TickTypeEnum |
29 | 27 | from ibapi.wrapper import EWrapper |
30 | | -from ibapi.errors import BAD_LENGTH |
31 | 28 | from ibapi.common import BarData as IbBarData |
32 | 29 |
|
33 | 30 | from vnpy.trader.gateway import BaseGateway |
|
89 | 86 | Exchange.BATS: "BATS", |
90 | 87 | Exchange.IEX: "IEX", |
91 | 88 | Exchange.IBKRATS: "IBKRATS", |
92 | | - Exchange.OTC: "PINK" |
| 89 | + Exchange.OTC: "PINK", |
| 90 | + Exchange.SGX: "SGX" |
93 | 91 | } |
94 | 92 | EXCHANGE_IB2VT = {v: k for k, v in EXCHANGE_VT2IB.items()} |
95 | 93 |
|
|
110 | 108 | "CMDTY": Product.SPOT, |
111 | 109 | "FUT": Product.FUTURES, |
112 | 110 | "OPT": Product.OPTION, |
113 | | - "FOT": Product.OPTION |
| 111 | + "FOT": Product.OPTION, |
| 112 | + "CONTFUT": Product.FUTURES |
114 | 113 | } |
115 | 114 |
|
116 | 115 | OPTION_VT2IB = {OptionType.CALL: "CALL", OptionType.PUT: "PUT"} |
@@ -357,6 +356,8 @@ def tickPrice( # pylint: disable=invalid-name |
357 | 356 | # We need to calculate locally. |
358 | 357 | exchange = self.tick_exchange[reqId] |
359 | 358 | if exchange is Exchange.IDEALPRO or "CMDTY" in tick.symbol: |
| 359 | + if not tick.bid_price_1 or not tick.ask_price_1: |
| 360 | + return |
360 | 361 | tick.last_price = (tick.bid_price_1 + tick.ask_price_1) / 2 |
361 | 362 | tick.datetime = datetime.now(self.local_tz) |
362 | 363 | self.gateway.on_tick(copy(tick)) |
@@ -632,7 +633,11 @@ def historicalData(self, reqId: int, ib_bar: IbBarData): |
632 | 633 | """ |
633 | 634 | Callback of history data update. |
634 | 635 | """ |
635 | | - dt = datetime.strptime(ib_bar.date, "%Y%m%d %H:%M:%S") |
| 636 | + # When requesting daily and weekly history data, the date format is "%Y%m%d" |
| 637 | + if len(ib_bar.date) > 8: |
| 638 | + dt = datetime.strptime(ib_bar.date, "%Y%m%d %H:%M:%S") |
| 639 | + else: |
| 640 | + dt = datetime.strptime(ib_bar.date, "%Y%m%d") |
636 | 641 | dt = self.local_tz.localize(dt) |
637 | 642 |
|
638 | 643 | bar = BarData( |
|
0 commit comments