Skip to content

Commit bdfdd14

Browse files
committed
Merge branch 'dev' of https://github.com/vnpy/vnpy into dev
2 parents f481e12 + a2ac9aa commit bdfdd14

File tree

12 files changed

+32
-20
lines changed

12 files changed

+32
-20
lines changed

vnpy/app/portfolio_strategy/backtesting.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self):
4242
self.priceticks: Dict[str, float] = 0
4343

4444
self.capital: float = 1_000_000
45-
self.risk_free: float = 0.02
45+
self.risk_free: float = 0
4646

4747
self.strategy: StrategyTemplate = None
4848
self.bars: Dict[str, BarData] = {}
@@ -520,7 +520,8 @@ def new_bars(self, dt: datetime) -> None:
520520
self.cross_limit_order()
521521
self.strategy.on_bars(bars)
522522

523-
self.update_daily_close(self.bars, dt)
523+
if self.strategy.inited:
524+
self.update_daily_close(self.bars, dt)
524525

525526
def cross_limit_order(self) -> None:
526527
"""

vnpy/gateway/coinbase/coinbase_gateway.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,6 @@ def on_query_instrument(self, data, request):
646646
pricetick=float(d["quote_increment"]),
647647
size=1,
648648
min_volume=float(d["base_min_size"]),
649-
net_position=True,
650649
history_data=True,
651650
gateway_name=self.gateway_name,
652651
)

vnpy/gateway/futu/futu_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def query_position(self):
347347
pos = PositionData(
348348
symbol=symbol,
349349
exchange=exchange,
350-
direction=Direction.LONG,
350+
direction=Direction.NET,
351351
volume=row["qty"],
352352
frozen=(float(row["qty"]) - float(row["can_sell_qty"])),
353353
price=float(row["cost_price"]),

vnpy/gateway/gateios/gateios_gateway.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ def on_query_contract(self, data, request): # type: (dict, Request)->None
413413
min_volume=d["order_size_min"],
414414
product=Product.FUTURES,
415415
gateway_name=self.gateway_name,
416-
history_data=True
416+
history_data=True,
417+
net_position=True
417418
)
418419
self.gateway.on_contract(contract)
419420

vnpy/gateway/gtja/gtja_gateway.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ def onSHBaseInfo(self, code, data):
401401
min_volume=data["i64BuyNumUnit"],
402402
pricetick=data["i64PriceLevel"] / 10000,
403403
size=1,
404+
net_position=True
404405
)
405406
self.gateway.on_contract(contract)
406407
symbol_name_map[contract.vt_symbol] = contract.name
@@ -418,6 +419,7 @@ def onSZBaseInfo(self, code, data):
418419
min_volume=data["i64BuyQtyUnit"],
419420
pricetick=data.get("i64PriceTick", 100) / 10000,
420421
size=1,
422+
net_position=True
421423
)
422424

423425
self.gateway.on_contract(contract)

vnpy/gateway/ib/ib_gateway.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@
1212

1313
from copy import copy
1414
from datetime import datetime
15-
from queue import Empty
1615
from threading import Thread, Condition
1716
from typing import Optional
1817
import shelve
1918
from tzlocal import get_localzone
2019

21-
from ibapi import comm
2220
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
2422
from ibapi.contract import Contract, ContractDetails
2523
from ibapi.execution import Execution
2624
from ibapi.order import Order
2725
from ibapi.order_state import OrderState
2826
from ibapi.ticktype import TickType, TickTypeEnum
2927
from ibapi.wrapper import EWrapper
30-
from ibapi.errors import BAD_LENGTH
3128
from ibapi.common import BarData as IbBarData
3229

3330
from vnpy.trader.gateway import BaseGateway
@@ -89,7 +86,8 @@
8986
Exchange.BATS: "BATS",
9087
Exchange.IEX: "IEX",
9188
Exchange.IBKRATS: "IBKRATS",
92-
Exchange.OTC: "PINK"
89+
Exchange.OTC: "PINK",
90+
Exchange.SGX: "SGX"
9391
}
9492
EXCHANGE_IB2VT = {v: k for k, v in EXCHANGE_VT2IB.items()}
9593

@@ -110,7 +108,8 @@
110108
"CMDTY": Product.SPOT,
111109
"FUT": Product.FUTURES,
112110
"OPT": Product.OPTION,
113-
"FOT": Product.OPTION
111+
"FOT": Product.OPTION,
112+
"CONTFUT": Product.FUTURES
114113
}
115114

116115
OPTION_VT2IB = {OptionType.CALL: "CALL", OptionType.PUT: "PUT"}
@@ -357,6 +356,8 @@ def tickPrice( # pylint: disable=invalid-name
357356
# We need to calculate locally.
358357
exchange = self.tick_exchange[reqId]
359358
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
360361
tick.last_price = (tick.bid_price_1 + tick.ask_price_1) / 2
361362
tick.datetime = datetime.now(self.local_tz)
362363
self.gateway.on_tick(copy(tick))
@@ -632,7 +633,11 @@ def historicalData(self, reqId: int, ib_bar: IbBarData):
632633
"""
633634
Callback of history data update.
634635
"""
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")
636641
dt = self.local_tz.localize(dt)
637642

638643
bar = BarData(

vnpy/gateway/kaisa/kaisa_gateway.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
START_PUSH = 200
4646
STOP_PUSH = 201
4747
SYNCHRONIZE_PUSH = 250
48-
QUERY_HISTORY = 36
4948
QUERY_CONTRACT = 52
5049
ON_TICK = 251
5150
PING = 2
@@ -253,8 +252,8 @@ def _query_contract(self):
253252
size=1,
254253
min_volume=d["lotsize"],
255254
product=Product.SPOT,
256-
history_data=True,
257255
gateway_name=self.gateway_name,
256+
net_position=True
258257
)
259258
self.on_contract(contract)
260259

@@ -525,7 +524,7 @@ def on_query_order(self, data: dict, request: Request) -> None:
525524
)
526525
self.gateway.on_trade(trade)
527526

528-
self.gateway.write_log(f"委托信息查询成功")
527+
self.gateway.write_log("委托信息查询成功")
529528
self.gateway.write_log("成交查询成功")
530529

531530
def on_send_order(self, data: dict, request: Request) -> None:

vnpy/gateway/sec/sec_gateway.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ def onRspStockQryStockStaticInfo(self, data: dict, error: dict, last: bool) -> N
849849
size=data["tradeUnit"],
850850
pricetick=0.001,
851851
product=Product.EQUITY,
852+
net_position=True,
852853
gateway_name=self.gateway_name
853854
)
854855
self.gateway.on_contract(contract)
@@ -921,7 +922,7 @@ def onRspStockQryPosition(self, data: dict, error: dict, last: bool) -> None:
921922
pos = PositionData(
922923
symbol=data["securityID"],
923924
exchange=EXCHANGE_SEC2VT[data["exchangeID"]],
924-
direction=Direction.NEt,
925+
direction=Direction.NET,
925926
volume=data["totalQty"],
926927
price=data["avgPositionPrice"],
927928
gateway_name=self.gateway_name

vnpy/gateway/tora/toraoption_gateway.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,8 @@ def send_order(self, req: OrderRequest):
884884
)
885885
self.api.ReqOrderInsert(info, self.reqid)
886886

887+
return f"{self.gateway_name}.{order_id}"
888+
887889
def cancel_order(self, req: CancelRequest) -> None:
888890
""""""
889891
self.reqid += 1

vnpy/gateway/tora/torastock_gateway.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,8 @@ def send_order(self, req: OrderRequest):
848848
)
849849
self.api.ReqOrderInsert(info, self.reqid)
850850

851+
return f"{self.gateway_name}.{order_id}"
852+
851853
def cancel_order(self, req: CancelRequest) -> None:
852854
""""""
853855
self.reqid += 1

0 commit comments

Comments
 (0)