diff --git a/vnpy/app/algo_trading/algos/best_limit_algo.py b/vnpy/app/algo_trading/algos/best_limit_algo.py index 1fc252ea..168d8e37 100644 --- a/vnpy/app/algo_trading/algos/best_limit_algo.py +++ b/vnpy/app/algo_trading/algos/best_limit_algo.py @@ -87,7 +87,7 @@ class BestLimitAlgo(AlgoTemplate): if not order.is_active(): self.vt_orderid = "" self.order_price = 0 - self.put_variables_event() + self.put_variables_event() def buy_best_limit(self): """""" @@ -98,7 +98,7 @@ class BestLimitAlgo(AlgoTemplate): self.order_price, order_volume, offset=self.offset - ) + ) def sell_best_limit(self): """""" @@ -109,4 +109,4 @@ class BestLimitAlgo(AlgoTemplate): self.order_price, order_volume, offset=self.offset - ) \ No newline at end of file + ) diff --git a/vnpy/app/algo_trading/algos/stop_algo.py b/vnpy/app/algo_trading/algos/stop_algo.py index 54b45bf7..14b5e94f 100644 --- a/vnpy/app/algo_trading/algos/stop_algo.py +++ b/vnpy/app/algo_trading/algos/stop_algo.py @@ -75,12 +75,13 @@ class StopAlgo(AlgoTemplate): self.volume, 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: if tick.last_price <= self.stop_price: price = self.stop_price - self.price_add - + if tick.limit_down: price = max(price, tick.limit_down) @@ -90,7 +91,8 @@ class StopAlgo(AlgoTemplate): self.volume, 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() diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index d5b6168f..bdd3f93d 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -17,12 +17,12 @@ def extract_vt_symbol(vt_symbol: str): """ :return: (symbol, exchange) """ - symbol, exchange_str = vt_symbol.split('.') + symbol, exchange_str = vt_symbol.split(".") return symbol, Exchange(exchange_str) 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): @@ -84,7 +84,7 @@ def load_json(filename: str): filepath = get_file_path(filename) 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) return data else: @@ -97,8 +97,13 @@ def save_json(filename: str, data: dict): Save data into json file in temp path. """ filepath = get_file_path(filename) - with open(filepath, mode='w+',encoding = 'UTF-8') as f: - json.dump(data, f,sort_keys=True,indent =4,ensure_ascii=False) + with open(filepath, mode="w+", encoding="UTF-8") as f: + json.dump( + data, + f, + indent=4, + ensure_ascii=False + ) def round_to(value: float, target: float):