[Fix]use abs for trade volume

This commit is contained in:
vn.py 2019-04-17 09:20:29 +08:00
parent fdd4094d33
commit 9de35bfd43
2 changed files with 18 additions and 9 deletions

View File

@ -12,6 +12,7 @@ from vnpy.gateway.tiger import TigerGateway
from vnpy.gateway.oes import OesGateway
from vnpy.gateway.okex import OkexGateway
from vnpy.gateway.huobi import HuobiGateway
from vnpy.gateway.bitfinex import BitfinexGateway
from vnpy.app.cta_strategy import CtaStrategyApp
from vnpy.app.csv_loader import CsvLoaderApp
@ -34,6 +35,7 @@ def main():
main_engine.add_gateway(OesGateway)
main_engine.add_gateway(OkexGateway)
main_engine.add_gateway(HuobiGateway)
main_engine.add_gateway(BitfinexGateway)
main_engine.add_app(CtaStrategyApp)
main_engine.add_app(CtaBacktesterApp)

View File

@ -490,6 +490,7 @@ class BitfinexWebsocketApi(WebsocketClient):
def on_wallet(self, data):
""""""
if str(data[0]) == "exchange":
print("wallet", data)
accountid = str(data[1])
account = self.accounts.get(accountid, None)
if not account:
@ -602,7 +603,8 @@ class BitfinexWebsocketApi(WebsocketClient):
tick.__setattr__("ask_price_%s" % (n + 1), price)
tick.__setattr__("ask_volume_%s" % (n + 1), volume)
tick.datetime = datetime.strptime(d["timestamp"], "%Y-%m-%dT%H:%M:%S.%fZ")
tick.datetime = datetime.strptime(
d["timestamp"], "%Y-%m-%dT%H:%M:%S.%fZ")
self.gateway.on_tick(copy(tick))
def on_trade(self, data):
@ -619,7 +621,7 @@ class BitfinexWebsocketApi(WebsocketClient):
exchange=Exchange.BITFINEX,
orderid=data[-1],
direction=direction,
volume=data[4],
volume=abs(data[4]),
price=data[5],
tradeid=str(self.trade_id),
time=self.generate_date_time(data[2]),
@ -641,7 +643,12 @@ class BitfinexWebsocketApi(WebsocketClient):
data = d[4]
error_info = d[-1]
# Filter cancel of non-existing order
orderid = str(data[2])
if orderid == "None":
self.gateway.write_log("撤单失败,委托不存在")
return
if data[6] > 0:
direction = Direction.LONG
else: