Explorar o código

修复int问题。

skyfffire hai 3 meses
pai
achega
ec013b35fd
Modificáronse 3 ficheiros con 31 adicións e 12 borrados
  1. 5 5
      mexc_client.py
  2. 13 4
      s_erc20_to_mexc.py
  3. 13 3
      s_mexc_to_erc20.py

+ 5 - 5
mexc_client.py

@@ -654,11 +654,11 @@ if __name__ == '__main__':
                         'tradeSideType': 1}],
             'timezone': 'CST'}
             '''
-            # params = {
-            #     "symbols": "ZEUSETHUSDT",
-            # }
-            # info = client.market.get_exchangeInfo(params)
-            # pprint(info)
+            params = {
+                "symbols": "MANYUUSDT",
+            }
+            info = client.market.get_exchangeInfo(params)
+            pprint(info)
         except requests.exceptions.RequestException as e:
             print(f"  私有 API 请求期间出错: {e}")
             if e.response is not None:

+ 13 - 4
s_erc20_to_mexc.py

@@ -308,17 +308,26 @@ class ArbitrageProcess:
             self.already_sold_amount = Decimal(0)
             while self.already_sold_amount < self.exchange_sell_amount and order_times < 5:
                 order_times = order_times + 1
-                # 第一步直接买入,这个数量用固定数量
+                # 第一步直接卖出,这个数量用固定数量
                 pseudo_amount_to_sell = self.exchange_sell_amount - self.already_sold_amount
                 # 处理精度
                 pseudo_amount_to_sell = pseudo_amount_to_sell.quantize(self.coin_asset_precision, rounding=ROUND_DOWN)
-            
+                # 初始化 quantity 变量
+                quantity_for_api = None
+                # 用求余法判断是否是整数
+                if pseudo_amount_to_sell % 1 == 0:
+                    # 如果是整数,转换为 int 类型。某些API可能只接受整数交易对的整数数量
+                    quantity_for_api = int(pseudo_amount_to_sell)
+                else:
+                    # 如果是非整数,转换为 float 类型。这是最常见的API数量类型
+                    quantity_for_api = float(pseudo_amount_to_sell)
                 order_params = {
                     "symbol": self.symbol.replace('_', ''),
                     "side": "SELL",
                     "type": "MARKET",
-                    "quantity": float(pseudo_amount_to_sell),
+                    "quantity": quantity_for_api,
                 }
+                
                 order_params_formated = pformat(order_params, indent=2)
                 
                 exchange_sell_order = mexc.trade.post_order(order_params)
@@ -360,7 +369,7 @@ class ArbitrageProcess:
                         time.sleep(1)
                         waiting_times = waiting_times - 1
             
-            if order_times <= 5:
+            if order_times < 5:
                 msg = 'mexc现货卖出流程完成'
                 logger.info(msg)
                 add_state_flow_entry(self.process_item, self.current_state, msg, "success")

+ 13 - 3
s_mexc_to_erc20.py

@@ -339,13 +339,23 @@ class ArbitrageProcess:
                 pseudo_amount_to_buy = self.exchange_buy_amount - self.already_bought_amount
                 # 处理精度
                 pseudo_amount_to_buy = pseudo_amount_to_buy.quantize(self.coin_asset_precision, rounding=ROUND_DOWN)
-                
+                # 初始化 quantity 变量
+                quantity_for_api = None
+                # 用求余法判断是否是整数
+                if pseudo_amount_to_buy % 1 == 0:
+                    # 如果是整数,转换为 int 类型。某些API可能只接受整数交易对的整数数量
+                    quantity_for_api = int(pseudo_amount_to_buy)
+                else:
+                    # 如果是非整数,转换为 float 类型。这是最常见的API数量类型
+                    quantity_for_api = float(pseudo_amount_to_buy)
+
                 order_params = {
                     "symbol": self.symbol.replace('_', ''),
                     "side": "BUY",
                     "type": "MARKET",
-                    "quantity": float(pseudo_amount_to_buy),          # 以【幣】的數量進行買入
+                    "quantity": quantity_for_api,          # 以【幣】的數量進行買入
                 }
+
                 order_params_formated = pformat(order_params, indent=2)
                 
                 exchange_buy_order = mexc.trade.post_order(order_params)
@@ -388,7 +398,7 @@ class ArbitrageProcess:
                         time.sleep(1)
                         waiting_times = waiting_times - 1
             
-            if order_times <= 5:
+            if order_times < 5:
                 msg = 'mexc现货买入流程完成'
                 logger.info(msg)
                 add_state_flow_entry(self.process_item, self.current_state, msg, "success")