[Mod] flake8 code quality improve

This commit is contained in:
vn.py 2019-05-17 16:14:00 +08:00
parent 16591ee97b
commit 5488a62770
3 changed files with 18 additions and 11 deletions

View File

@ -75,7 +75,8 @@ class StopAlgo(AlgoTemplate):
self.volume, self.volume,
offset=self.offset offset=self.offset
) )
self.write_log(f"停止单已触发,代码:{self.vt_symbol},方向:{self.direction}, 价格:{self.stop_price},数量:{self.volume},开平:{self.offset}") self.write_log(
f"停止单已触发,代码:{self.vt_symbol},方向:{self.direction}, 价格:{self.stop_price},数量:{self.volume},开平:{self.offset}")
else: else:
if tick.last_price <= self.stop_price: if tick.last_price <= self.stop_price:
@ -90,7 +91,8 @@ class StopAlgo(AlgoTemplate):
self.volume, self.volume,
offset=self.offset offset=self.offset
) )
self.write_log(f"停止单已触发,代码:{self.vt_symbol},方向:{self.direction}, 价格:{self.stop_price},数量:{self.volume},开平:{self.offset}") self.write_log(
f"停止单已触发,代码:{self.vt_symbol},方向:{self.direction}, 价格:{self.stop_price},数量:{self.volume},开平:{self.offset}")
self.put_variables_event() self.put_variables_event()

View File

@ -17,12 +17,12 @@ def extract_vt_symbol(vt_symbol: str):
""" """
:return: (symbol, exchange) :return: (symbol, exchange)
""" """
symbol, exchange_str = vt_symbol.split('.') symbol, exchange_str = vt_symbol.split(".")
return symbol, Exchange(exchange_str) return symbol, Exchange(exchange_str)
def generate_vt_symbol(symbol: str, exchange: Exchange): def generate_vt_symbol(symbol: str, exchange: Exchange):
return f'{symbol}.{exchange.value}' return f"{symbol}.{exchange.value}"
def _get_trader_dir(temp_name: str): def _get_trader_dir(temp_name: str):
@ -84,7 +84,7 @@ def load_json(filename: str):
filepath = get_file_path(filename) filepath = get_file_path(filename)
if filepath.exists(): if filepath.exists():
with open(filepath, mode='r',encoding = 'UTF-8') as f: with open(filepath, mode="r", encoding="UTF-8") as f:
data = json.load(f) data = json.load(f)
return data return data
else: else:
@ -97,8 +97,13 @@ def save_json(filename: str, data: dict):
Save data into json file in temp path. Save data into json file in temp path.
""" """
filepath = get_file_path(filename) filepath = get_file_path(filename)
with open(filepath, mode='w+',encoding = 'UTF-8') as f: with open(filepath, mode="w+", encoding="UTF-8") as f:
json.dump(data, f,sort_keys=True,indent =4,ensure_ascii=False) json.dump(
data,
f,
indent=4,
ensure_ascii=False
)
def round_to(value: float, target: float): def round_to(value: float, target: float):