Explorar el Código

修复字符串加入计算的问题

skyfffire hace 2 meses
padre
commit
cdde20e902
Se han modificado 1 ficheros con 10 adiciones y 10 borrados
  1. 10 10
      s_erc20_to_mexc.py

+ 10 - 10
s_erc20_to_mexc.py

@@ -395,7 +395,7 @@ class ArbitrageProcess:
         try:
         try:
             exchange_buy_order = None
             exchange_buy_order = None
             order_error_times = 0
             order_error_times = 0
-            order_price = Decimal(0)
+            last_order_price = Decimal(0)
             dex_price = Decimal(0)
             dex_price = Decimal(0)
             self.already_bought_amount = Decimal(0)
             self.already_bought_amount = Decimal(0)
 
 
@@ -412,12 +412,11 @@ class ArbitrageProcess:
                     dex_price = Decimal(table_data['dex_price'])
                     dex_price = Decimal(table_data['dex_price'])
                     dex_price = dex_price.quantize(self.price_precision, rounding=ROUND_DOWN)
                     dex_price = dex_price.quantize(self.price_precision, rounding=ROUND_DOWN)
 
 
-                    price_for_api = dex_price * (Decimal(1) - self.close_limit)
-                    price_for_api = price_for_api.quantize(self.price_precision, rounding=ROUND_DOWN)
-                    price_for_api = decimal_to_string_no_scientific(price_for_api)
+                    ready_buy_price = dex_price * (Decimal(1) - self.close_limit)
+                    ready_buy_price = ready_buy_price.quantize(self.price_precision, rounding=ROUND_DOWN)
 
 
                     # 准备购入的价值, 如果小于2u就不要提交了
                     # 准备购入的价值, 如果小于2u就不要提交了
-                    pseudo_value_to_buy = price_for_api * (self.already_sold_amount - self.already_bought_amount)
+                    pseudo_value_to_buy = ready_buy_price * (self.already_sold_amount - self.already_bought_amount)
 
 
                     if pseudo_value_to_buy < 2:
                     if pseudo_value_to_buy < 2:
                         break
                         break
@@ -439,13 +438,13 @@ class ArbitrageProcess:
                                         self._set_state(self.STATE_FAILED)
                                         self._set_state(self.STATE_FAILED)
                                         return
                                         return
                                     else:
                                     else:
-                                        msg = f"交易所剩余{self.base_coin}: {free_balance}, 准备使用 {pseudo_value_to_buy}, fp {dex_price}, 挂单价格{price_for_api},  余额校验通过。"
+                                        msg = f"交易所剩余{self.base_coin}: {free_balance}, 准备使用 {pseudo_value_to_buy}, fp {dex_price}, 挂单价格{ready_buy_price},  余额校验通过。"
                                         logger.info(msg)
                                         logger.info(msg)
                                         # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
                                         # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
                                         break
                                         break
 
 
                         # 实际能购入的数量(可能会亏损导致买不回来, 所以要考虑实际有多少money)
                         # 实际能购入的数量(可能会亏损导致买不回来, 所以要考虑实际有多少money)
-                        quantity_for_api = pseudo_value_to_buy / price_for_api
+                        quantity_for_api = pseudo_value_to_buy / ready_buy_price
                         quantity_for_api = quantity_for_api.quantize(self.coin_asset_precision, rounding=ROUND_DOWN)
                         quantity_for_api = quantity_for_api.quantize(self.coin_asset_precision, rounding=ROUND_DOWN)
                         # 用求余法判断是否是整数
                         # 用求余法判断是否是整数
                         if quantity_for_api % 1 == 0:
                         if quantity_for_api % 1 == 0:
@@ -455,6 +454,7 @@ class ArbitrageProcess:
                             # 如果是非整数, 转换为 float 类型。这是最常见的API数量类型
                             # 如果是非整数, 转换为 float 类型。这是最常见的API数量类型
                             quantity_for_api = float(quantity_for_api)
                             quantity_for_api = float(quantity_for_api)
 
 
+                        price_for_api = decimal_to_string_no_scientific(ready_buy_price)
                         order_params = {
                         order_params = {
                             "symbol": self.symbol.replace('_', ''),
                             "symbol": self.symbol.replace('_', ''),
                             "side": "BUY",
                             "side": "BUY",
@@ -475,7 +475,7 @@ class ArbitrageProcess:
                             order_error_times = order_error_times + 1
                             order_error_times = order_error_times + 1
                         else:
                         else:
                             self.exchange_buy_order_id = exchange_buy_order['orderId']
                             self.exchange_buy_order_id = exchange_buy_order['orderId']
-                            order_price = price_for_api
+                            last_order_price = ready_buy_price
                     # 有订单时的逻辑
                     # 有订单时的逻辑
                     else:
                     else:
                         # 获取订单状态, 直到完全成交或超时
                         # 获取订单状态, 直到完全成交或超时
@@ -503,7 +503,7 @@ class ArbitrageProcess:
                             exchange_buy_order = None
                             exchange_buy_order = None
                         
                         
                         # 如果没有成交或取消则判断是否达到取消条件了, 这里面不能置空
                         # 如果没有成交或取消则判断是否达到取消条件了, 这里面不能置空
-                        elif (Decimal(1) - order_price / price_for_api) > Decimal(0.0005):
+                        elif (Decimal(1) - last_order_price / ready_buy_price) > Decimal(0.0005):
                             params = {
                             params = {
                                 "symbol": self.symbol.replace('_', ''),
                                 "symbol": self.symbol.replace('_', ''),
                                 "orderId": self.exchange_buy_order_id
                                 "orderId": self.exchange_buy_order_id
@@ -511,7 +511,7 @@ class ArbitrageProcess:
                             _deleteed_order = mexc.trade.delete_order(params)
                             _deleteed_order = mexc.trade.delete_order(params)
                             
                             
                             # deleteed_order_formated = pformat(_deleteed_order, indent=2)
                             # deleteed_order_formated = pformat(_deleteed_order, indent=2)
-                            # msg = f"【WARNING】价格变化, 重新挂单, order price {order_price}, dex_price {dex_price} \n order: {deleteed_order_formated}"
+                            # msg = f"【WARNING】价格变化, 重新挂单, order price {last_order_price}, dex_price {dex_price} \n order: {deleteed_order_formated}"
                             # logger.warning(msg)
                             # logger.warning(msg)
                             # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
                             # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
                 except Exception as e:
                 except Exception as e: