[Mod] make flake8 happy

This commit is contained in:
nanoric 2019-09-17 15:51:50 +08:00
parent d805ed043c
commit 9aa90f538f
7 changed files with 33 additions and 51 deletions

View File

@ -374,7 +374,7 @@ class RestClient(object):
request.response = response
status_code = response.status_code
if not stream: # normal API:
if not stream: # normal API:
# just call callback with all contents received.
if status_code // 100 == 2: # 2xx codes are all successful
if status_code == 204:
@ -388,7 +388,7 @@ class RestClient(object):
request.on_failed(status_code, request)
else:
self.on_failed(status_code, request)
else: # streaming API:
else: # streaming API:
if request.on_connected:
request.on_connected(request)
# split response by lines, and call one callback for each line.

View File

@ -1,22 +1,11 @@
import json
import sys
from dataclasses import dataclass
from datetime import datetime
from threading import Lock
from typing import Dict, List, Optional, TYPE_CHECKING, Tuple
from typing import TYPE_CHECKING
from requests import ConnectionError
from vnpy.api.rest import Request
from vnpy.trader.constant import Direction, Exchange, Interval, Offset, Product, Status
from vnpy.trader.object import AccountData, BarData, CancelRequest, ContractData, OrderRequest, \
PositionData, OrderData
from .oanda_common import (INTERVAL_VT2OANDA, ORDER_TYPE_VT2OANDA,
STATUS_OANDA2VT, parse_time, INTERVAL_VT2OANDA_DELTA, parse_datetime)
from vnpy.api.rest import Request, RestClient
if TYPE_CHECKING:
from vnpy.gateway.oanda import OandaGateway
from vnpy.api.rest import RestClient
_ = lambda x: x # noqa
@ -25,6 +14,7 @@ class OandaApiBase(RestClient):
"""
Oanda Base API
"""
def __init__(self, gateway: "OandaGateway"):
super().__init__()
self.gateway = gateway
@ -62,4 +52,3 @@ class OandaApiBase(RestClient):
sys.stderr.write(
self.exception_detail(exception_type, exception_value, tb, request)
)

View File

@ -6,7 +6,7 @@ from vnpy.trader.constant import Direction, Interval, OrderType, Status
if TYPE_CHECKING:
# noinspection PyUnresolvedReferences
from vnpy.gateway.oanda import OandaGateway
from vnpy.gateway.oanda import OandaGateway # noqa
STATUS_OANDA2VT = {
"PENDING": Status.NOTTRADED,

View File

@ -5,22 +5,19 @@ todo:
"""
from dataclasses import dataclass
from datetime import datetime
from typing import Dict, List, Any, Tuple, Optional
from typing import Any, Dict, List, Optional, Tuple
from vnpy.event import Event
from vnpy.trader.constant import (Exchange, OrderType, Interval, Direction, Offset, Status)
from vnpy.trader.constant import (Direction, Exchange, Interval, Offset, OrderType, Status)
from vnpy.trader.event import EVENT_TIMER
from vnpy.trader.gateway import BaseGateway
from vnpy.trader.object import (CancelRequest, HistoryRequest, OrderData, OrderRequest,
PositionData, SubscribeRequest, TickData, BarData)
from .oanda_common import DIRECTION_OANDA2VT, OPPOSITE_DIRECTION, ORDER_TYPE_OANDA2VT, \
STOP_ORDER_STATUS_OANDA2VT, parse_datetime, STATUS_OANDA2VT, INTERVAL_VT2OANDA, local_tz, \
utc_tz, INTERVAL_VT2OANDA_INT, parse_time, INTERVAL_VT2OANDA_DELTA
from .oanda_rest_api import OandaRestApi, HistoryDataNextInfo
from vnpy.trader.object import (BarData, CancelRequest, HistoryRequest, OrderData, OrderRequest,
SubscribeRequest)
from .oanda_common import INTERVAL_VT2OANDA_DELTA, ORDER_TYPE_OANDA2VT, local_tz, parse_time, utc_tz
from .oanda_rest_api import HistoryDataNextInfo, OandaRestApi
from .oanda_stream_api import OandaStreamApi
_ = lambda x:x # noqa
_ = lambda x: x # noqa
@dataclass()
@ -99,10 +96,10 @@ class OandaGateway(BaseGateway):
self.rest_api.query_positions()
def query_first_history(self,
symbol: str,
interval: Interval,
start: datetime,
) -> Tuple[List[BarData], "HistoryDataNextInfo"]:
symbol: str,
interval: Interval,
start: datetime,
) -> Tuple[List[BarData], "HistoryDataNextInfo"]:
# datetime for a bar is close_time
# we got open_time from API.
@ -205,4 +202,3 @@ class OandaGateway(BaseGateway):
)
self.orders[order_id] = order
return order

View File

@ -1,5 +1,3 @@
import json
import sys
from dataclasses import dataclass
from datetime import datetime
from threading import Lock
@ -11,10 +9,9 @@ from vnpy.api.rest import Request
from vnpy.gateway.oanda.oanda_api_base import OandaApiBase
from vnpy.trader.constant import Direction, Exchange, Interval, Offset, Product, Status
from vnpy.trader.object import AccountData, BarData, CancelRequest, ContractData, OrderRequest, \
PositionData, OrderData
from .oanda_common import (INTERVAL_VT2OANDA, ORDER_TYPE_VT2OANDA,
STATUS_OANDA2VT, parse_time, INTERVAL_VT2OANDA_DELTA, parse_datetime,
utc_tz, local_tz)
PositionData
from .oanda_common import (INTERVAL_VT2OANDA, INTERVAL_VT2OANDA_DELTA, ORDER_TYPE_VT2OANDA,
STATUS_OANDA2VT, local_tz, parse_datetime, parse_time, utc_tz)
if TYPE_CHECKING:
from vnpy.gateway.oanda import OandaGateway
@ -122,7 +119,6 @@ class OandaRestApi(OandaApiBase):
order.time = parse_time(datetime.now().isoformat())
# Only add price for limit order.
str_price = str(req.price)
data["type"] = ORDER_TYPE_VT2OANDA[req.type]
data["price"] = str(req.price)
self.gateway.orders[order.orderid] = order
@ -240,7 +236,7 @@ class OandaRestApi(OandaApiBase):
def on_send_order(self, raw_data: dict, request: Request):
""""""
order: OrderData = request.extra
# order: OrderData = request.extra
# creation = raw_data.get('orderCreateTransaction', None)
# if creation is not None:
# order.status = Status.NOTTRADED
@ -314,7 +310,7 @@ class OandaRestApi(OandaApiBase):
gateway_name=self.gateway_name,
accountid=account_id,
balance=NAV - pnl,
frozen=0, # no frozen
frozen=0, # no frozen
)
self.gateway.on_account(account)
@ -347,15 +343,16 @@ class OandaRestApi(OandaApiBase):
def parse_position_data(self, pos_data) -> Tuple[PositionData, PositionData]:
symbol = pos_data['instrument']
pos_long, pos_short = [PositionData(
gateway_name=self.gateway_name,
symbol=symbol,
exchange=Exchange.OANDA,
direction=direction,
volume=int(data['units']),
price=float(data.get('averagePrice', 0.0)),
pnl=float(data.get('unrealizedPL', 0.0)),
)
pos_long, pos_short = [
PositionData(
gateway_name=self.gateway_name,
symbol=symbol,
exchange=Exchange.OANDA,
direction=direction,
volume=int(data['units']),
price=float(data.get('averagePrice', 0.0)),
pnl=float(data.get('unrealizedPL', 0.0)),
)
for direction, data in (
(Direction.LONG, pos_data['long']),
(Direction.SHORT, pos_data['short'])

View File

@ -1,5 +1,4 @@
from copy import copy
from copy import copy
from dataclasses import dataclass
from functools import partial
from http.client import IncompleteRead, RemoteDisconnected

View File

@ -119,6 +119,7 @@ class Exchange(Enum):
BINANCE = "BINANCE"
COINBASE = "COINBASE"
class Currency(Enum):
"""
Currency.