|
|
@@ -567,7 +567,7 @@ class ArbitrageProcess:
|
|
|
logger.info(msg)
|
|
|
add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
|
|
|
- self._set_state(self.STATE_WAITING_TRANSFER_ARRIVE)
|
|
|
+ self._set_state(self.STATE_COMPLETED)
|
|
|
|
|
|
break
|
|
|
|
|
|
@@ -590,330 +590,330 @@ class ArbitrageProcess:
|
|
|
|
|
|
# traceback.print_exc()
|
|
|
|
|
|
- def _wait_exchange_rollback(self):
|
|
|
- """
|
|
|
- 市价进行交易所交易回滚
|
|
|
- """
|
|
|
- msg = "执行:中心化交易所卖出现货回滚..."
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "pending")
|
|
|
- try:
|
|
|
- # 使用预提现数量进行回滚
|
|
|
- pseudo_amount_to_sell = Decimal(self.already_bought_amount)
|
|
|
- # 处理精度
|
|
|
- pseudo_amount_to_sell = pseudo_amount_to_sell.quantize(self.coin_asset_precision, rounding=ROUND_DOWN)
|
|
|
-
|
|
|
- # 交易所币余额判断
|
|
|
- with self.mexc_lock:
|
|
|
- balances = self.mexc_data['account_info']['balances']
|
|
|
- for balance in balances:
|
|
|
- if balance['asset'] == self.coin:
|
|
|
- pseudo_amount_to_sell = min(Decimal(balance['free']), pseudo_amount_to_sell)
|
|
|
-
|
|
|
- if pseudo_amount_to_sell * self.mexc_price < Decimal('10'):
|
|
|
- msg = f"交易所剩余{self.coin}: {balance['free']}, 小于10, 不能触发回滚交易。"
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
- self._set_state(self.STATE_FAILED)
|
|
|
- return
|
|
|
- else:
|
|
|
- msg = f"交易所剩余{self.coin}: {balance['free']}, 交易所准备使用:{pseudo_amount_to_sell}, 余额校验通过(可以回滚)。"
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
- break
|
|
|
+ # def _wait_exchange_rollback(self):
|
|
|
+ # """
|
|
|
+ # 市价进行交易所交易回滚
|
|
|
+ # """
|
|
|
+ # msg = "执行:中心化交易所卖出现货回滚..."
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "pending")
|
|
|
+ # try:
|
|
|
+ # # 使用预提现数量进行回滚
|
|
|
+ # pseudo_amount_to_sell = Decimal(self.already_bought_amount)
|
|
|
+ # # 处理精度
|
|
|
+ # pseudo_amount_to_sell = pseudo_amount_to_sell.quantize(self.coin_asset_precision, rounding=ROUND_DOWN)
|
|
|
+
|
|
|
+ # # 交易所币余额判断
|
|
|
+ # with self.mexc_lock:
|
|
|
+ # balances = self.mexc_data['account_info']['balances']
|
|
|
+ # for balance in balances:
|
|
|
+ # if balance['asset'] == self.coin:
|
|
|
+ # pseudo_amount_to_sell = min(Decimal(balance['free']), pseudo_amount_to_sell)
|
|
|
+
|
|
|
+ # if pseudo_amount_to_sell * self.mexc_price < Decimal('10'):
|
|
|
+ # msg = f"交易所剩余{self.coin}: {balance['free']}, 小于10, 不能触发回滚交易。"
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+ # self._set_state(self.STATE_FAILED)
|
|
|
+ # return
|
|
|
+ # else:
|
|
|
+ # msg = f"交易所剩余{self.coin}: {balance['free']}, 交易所准备使用:{pseudo_amount_to_sell}, 余额校验通过(可以回滚)。"
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
+ # break
|
|
|
|
|
|
- ready_to_sell = pseudo_amount_to_sell
|
|
|
-
|
|
|
- # 初始化 quantity 变量
|
|
|
- quantity_for_api = None
|
|
|
- # 用求余法判断是否是整数
|
|
|
- if ready_to_sell % 1 == 0:
|
|
|
- # 如果是整数,转换为 int 类型。某些API可能只接受整数交易对的整数数量
|
|
|
- quantity_for_api = int(ready_to_sell)
|
|
|
- else:
|
|
|
- # 如果是非整数,转换为 float 类型。这是最常见的API数量类型
|
|
|
- quantity_for_api = float(ready_to_sell)
|
|
|
- order_params = {
|
|
|
- "symbol": self.symbol.replace('_', ''),
|
|
|
- "side": "SELL",
|
|
|
- "price": self.buy_price,
|
|
|
- "type": "LIMIT",
|
|
|
- "quantity": quantity_for_api,
|
|
|
- }
|
|
|
- order_params_formated = pformat(order_params, indent=2)
|
|
|
- exchange_sell_order = mexc.trade.post_order(order_params)
|
|
|
- exchange_sell_order_formated = pformat(exchange_sell_order, indent=2)
|
|
|
- if 'orderId' not in exchange_sell_order:
|
|
|
- msg = f"【回滚】交易所现货卖出下单失败\n params:{order_params_formated}\norder: {exchange_sell_order_formated}"
|
|
|
- logger.error(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
- self._set_state("FAILED")
|
|
|
-
|
|
|
- return
|
|
|
-
|
|
|
- exchange_sell_order_id = exchange_sell_order['orderId']
|
|
|
+ # ready_to_sell = pseudo_amount_to_sell
|
|
|
+
|
|
|
+ # # 初始化 quantity 变量
|
|
|
+ # quantity_for_api = None
|
|
|
+ # # 用求余法判断是否是整数
|
|
|
+ # if ready_to_sell % 1 == 0:
|
|
|
+ # # 如果是整数,转换为 int 类型。某些API可能只接受整数交易对的整数数量
|
|
|
+ # quantity_for_api = int(ready_to_sell)
|
|
|
+ # else:
|
|
|
+ # # 如果是非整数,转换为 float 类型。这是最常见的API数量类型
|
|
|
+ # quantity_for_api = float(ready_to_sell)
|
|
|
+ # order_params = {
|
|
|
+ # "symbol": self.symbol.replace('_', ''),
|
|
|
+ # "side": "SELL",
|
|
|
+ # "price": self.buy_price,
|
|
|
+ # "type": "LIMIT",
|
|
|
+ # "quantity": quantity_for_api,
|
|
|
+ # }
|
|
|
+ # order_params_formated = pformat(order_params, indent=2)
|
|
|
+ # exchange_sell_order = mexc.trade.post_order(order_params)
|
|
|
+ # exchange_sell_order_formated = pformat(exchange_sell_order, indent=2)
|
|
|
+ # if 'orderId' not in exchange_sell_order:
|
|
|
+ # msg = f"【回滚】交易所现货卖出下单失败\n params:{order_params_formated}\norder: {exchange_sell_order_formated}"
|
|
|
+ # logger.error(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+ # self._set_state("FAILED")
|
|
|
+
|
|
|
+ # return
|
|
|
+
|
|
|
+ # exchange_sell_order_id = exchange_sell_order['orderId']
|
|
|
|
|
|
- msg = f"【回滚】交易所现货卖出订单已发送, 订单ID: {exchange_sell_order_id}"
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
-
|
|
|
- # 查询交易所订单状态
|
|
|
- last_query_rst = None
|
|
|
- while True:
|
|
|
- params = {
|
|
|
- "symbol": self.symbol.replace('_', ''),
|
|
|
- "orderId": exchange_sell_order_id
|
|
|
- }
|
|
|
- order = mexc.trade.get_order(params)
|
|
|
- order_formated = pformat(order, indent=2)
|
|
|
- last_query_rst = order
|
|
|
-
|
|
|
- if order['status'] == "FILLED":
|
|
|
- money = Decimal(order['cummulativeQuoteQty'])
|
|
|
- amount = self.exchange_buy_amount
|
|
|
- price = money / amount
|
|
|
- price = price.quantize(self.price_precision, rounding=ROUND_DOWN)
|
|
|
-
|
|
|
- msg = f"【回滚】交易所现货卖出订单已完全成交, 价格:{price}。\norder: {order_formated}"
|
|
|
-
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
-
|
|
|
- self._set_state(self.STATE_FAILED)
|
|
|
- return
|
|
|
- else:
|
|
|
- # 继续等待成交
|
|
|
- pass
|
|
|
-
|
|
|
- time.sleep(1)
|
|
|
+ # msg = f"【回滚】交易所现货卖出订单已发送, 订单ID: {exchange_sell_order_id}"
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
+
|
|
|
+ # # 查询交易所订单状态
|
|
|
+ # last_query_rst = None
|
|
|
+ # while True:
|
|
|
+ # params = {
|
|
|
+ # "symbol": self.symbol.replace('_', ''),
|
|
|
+ # "orderId": exchange_sell_order_id
|
|
|
+ # }
|
|
|
+ # order = mexc.trade.get_order(params)
|
|
|
+ # order_formated = pformat(order, indent=2)
|
|
|
+ # last_query_rst = order
|
|
|
+
|
|
|
+ # if order['status'] == "FILLED":
|
|
|
+ # money = Decimal(order['cummulativeQuoteQty'])
|
|
|
+ # amount = self.exchange_buy_amount
|
|
|
+ # price = money / amount
|
|
|
+ # price = price.quantize(self.price_precision, rounding=ROUND_DOWN)
|
|
|
+
|
|
|
+ # msg = f"【回滚】交易所现货卖出订单已完全成交, 价格:{price}。\norder: {order_formated}"
|
|
|
+
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
+
|
|
|
+ # self._set_state(self.STATE_FAILED)
|
|
|
+ # return
|
|
|
+ # else:
|
|
|
+ # # 继续等待成交
|
|
|
+ # pass
|
|
|
+
|
|
|
+ # time.sleep(1)
|
|
|
|
|
|
- last_query_rst_formated = pformat(last_query_rst, indent=2)
|
|
|
- msg = f"【回滚】回滚交易订单查询超时, 订单ID: {exchange_sell_order_id}\n最终状态:{last_query_rst_formated}"
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
-
|
|
|
- self._set_state(self.STATE_FAILED)
|
|
|
- except Exception as e:
|
|
|
- exc_traceback = traceback.format_exc()
|
|
|
- msg = f"【回滚】交易所回滚交易失败\n{exc_traceback}"
|
|
|
- logger.error(msg)
|
|
|
+ # last_query_rst_formated = pformat(last_query_rst, indent=2)
|
|
|
+ # msg = f"【回滚】回滚交易订单查询超时, 订单ID: {exchange_sell_order_id}\n最终状态:{last_query_rst_formated}"
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+
|
|
|
+ # self._set_state(self.STATE_FAILED)
|
|
|
+ # except Exception as e:
|
|
|
+ # exc_traceback = traceback.format_exc()
|
|
|
+ # msg = f"【回滚】交易所回滚交易失败\n{exc_traceback}"
|
|
|
+ # logger.error(msg)
|
|
|
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
- self._set_state(self.STATE_FAILED)
|
|
|
-
|
|
|
- # traceback.print_exc()
|
|
|
-
|
|
|
- def _wait_transfer_arrive(self):
|
|
|
- """
|
|
|
- 等待资产在交易所内到账
|
|
|
- """
|
|
|
- msg = f"等待资产在交易所到账..."
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "pending")
|
|
|
-
|
|
|
- try:
|
|
|
- is_arrived = False
|
|
|
-
|
|
|
- # 先進行快速提現判斷,如果不滿足條件就走後面的等待充值模式,雙模,這個步驟最多等待10分鐘
|
|
|
- waiting_times = 10
|
|
|
- last_deposit_state = None
|
|
|
- while waiting_times > 0:
|
|
|
- time.sleep(60)
|
|
|
- with self.mexc_lock:
|
|
|
- deposit_list = copy.deepcopy(self.mexc_data['deposit_list'])
|
|
|
-
|
|
|
- # 是否已經在列表中了,抹茶識別充值會稍微有點慢,所以要耐心等
|
|
|
- is_list = False
|
|
|
- # pending中的數量
|
|
|
- pending_amount = Decimal(0)
|
|
|
- for deposit in deposit_list:
|
|
|
- # 不屬于該路徑需要監聽的代幣
|
|
|
- if deposit['coin'] != f'{self.base_coin}-{self.NETWORK}':
|
|
|
- continue
|
|
|
-
|
|
|
- # 處理pending數量
|
|
|
- if Decimal(deposit['confirmTimes']) < Decimal(deposit['unlockConfirm']):
|
|
|
- pending_amount = pending_amount + Decimal(deposit['amount'])
|
|
|
-
|
|
|
- # 檢查到沒到列表中
|
|
|
- if deposit['transHash'] != self.chain_tx_hash:
|
|
|
- continue
|
|
|
- last_deposit_state = deposit
|
|
|
- is_list = True
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+ # self._set_state(self.STATE_FAILED)
|
|
|
+
|
|
|
+ # # traceback.print_exc()
|
|
|
+
|
|
|
+ # def _wait_transfer_arrive(self):
|
|
|
+ # """
|
|
|
+ # 等待资产在交易所内到账
|
|
|
+ # """
|
|
|
+ # msg = f"等待资产在交易所到账..."
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "pending")
|
|
|
+
|
|
|
+ # try:
|
|
|
+ # is_arrived = False
|
|
|
+
|
|
|
+ # # 先進行快速提現判斷,如果不滿足條件就走後面的等待充值模式,雙模,這個步驟最多等待10分鐘
|
|
|
+ # waiting_times = 10
|
|
|
+ # last_deposit_state = None
|
|
|
+ # while waiting_times > 0:
|
|
|
+ # time.sleep(60)
|
|
|
+ # with self.mexc_lock:
|
|
|
+ # deposit_list = copy.deepcopy(self.mexc_data['deposit_list'])
|
|
|
+
|
|
|
+ # # 是否已經在列表中了,抹茶識別充值會稍微有點慢,所以要耐心等
|
|
|
+ # is_list = False
|
|
|
+ # # pending中的數量
|
|
|
+ # pending_amount = Decimal(0)
|
|
|
+ # for deposit in deposit_list:
|
|
|
+ # # 不屬于該路徑需要監聽的代幣
|
|
|
+ # if deposit['coin'] != f'{self.base_coin}-{self.NETWORK}':
|
|
|
+ # continue
|
|
|
+
|
|
|
+ # # 處理pending數量
|
|
|
+ # if Decimal(deposit['confirmTimes']) < Decimal(deposit['unlockConfirm']):
|
|
|
+ # pending_amount = pending_amount + Decimal(deposit['amount'])
|
|
|
+
|
|
|
+ # # 檢查到沒到列表中
|
|
|
+ # if deposit['transHash'] != self.chain_tx_hash:
|
|
|
+ # continue
|
|
|
+ # last_deposit_state = deposit
|
|
|
+ # is_list = True
|
|
|
|
|
|
- # 檢查是否滿足快速提現的條件
|
|
|
- if is_list:
|
|
|
- # 交易所代幣余额判断
|
|
|
- with self.mexc_lock:
|
|
|
- balances = copy.deepcopy(self.mexc_data['account_info']['balances'])
|
|
|
- asset_balance = 0
|
|
|
- for balance in balances:
|
|
|
- if balance['asset'] == self.base_coin:
|
|
|
- asset_balance = Decimal(balance['free'])
|
|
|
-
|
|
|
- # 交易所賣出餘額
|
|
|
- buy_value = self.buy_value
|
|
|
+ # # 檢查是否滿足快速提現的條件
|
|
|
+ # if is_list:
|
|
|
+ # # 交易所代幣余额判断
|
|
|
+ # with self.mexc_lock:
|
|
|
+ # balances = copy.deepcopy(self.mexc_data['account_info']['balances'])
|
|
|
+ # asset_balance = 0
|
|
|
+ # for balance in balances:
|
|
|
+ # if balance['asset'] == self.base_coin:
|
|
|
+ # asset_balance = Decimal(balance['free'])
|
|
|
+
|
|
|
+ # # 交易所賣出餘額
|
|
|
+ # buy_value = self.buy_value
|
|
|
|
|
|
- # 最終判斷
|
|
|
- if buy_value + asset_balance > pending_amount:
|
|
|
- last_deposit_state_formated = pformat(last_deposit_state, indent=2)
|
|
|
- msg = f"【flash】资产可以進行快速提現。\nbuy_value {buy_value}, asset_balance {asset_balance}, pending_amount {pending_amount}\n{last_deposit_state_formated}"
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
-
|
|
|
- self._set_state(self.STATE_TRANSFERRING_TO_CHAIN)
|
|
|
- return
|
|
|
- else:
|
|
|
- logger.info(f"buy_value{buy_value}, asset_balance{asset_balance}, pending_amount{pending_amount}")
|
|
|
+ # # 最終判斷
|
|
|
+ # if buy_value + asset_balance > pending_amount:
|
|
|
+ # last_deposit_state_formated = pformat(last_deposit_state, indent=2)
|
|
|
+ # msg = f"【flash】资产可以進行快速提現。\nbuy_value {buy_value}, asset_balance {asset_balance}, pending_amount {pending_amount}\n{last_deposit_state_formated}"
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
+
|
|
|
+ # self._set_state(self.STATE_TRANSFERRING_TO_CHAIN)
|
|
|
+ # return
|
|
|
+ # else:
|
|
|
+ # logger.info(f"buy_value{buy_value}, asset_balance{asset_balance}, pending_amount{pending_amount}")
|
|
|
|
|
|
- logger.info(f"正在檢查快速提現條件...({waiting_times}/10)")
|
|
|
- waiting_times = waiting_times - 1
|
|
|
-
|
|
|
- # 最多等待30分钟
|
|
|
- waiting_times = 30
|
|
|
- last_deposit_state = None
|
|
|
- last_deposit_state_formated = None
|
|
|
- while waiting_times > 0:
|
|
|
- with self.mexc_lock:
|
|
|
- deposit_list = copy.deepcopy(self.mexc_data['deposit_list'])
|
|
|
- for deposit in deposit_list:
|
|
|
- if deposit['transHash'] != self.chain_tx_hash:
|
|
|
- continue
|
|
|
-
|
|
|
- last_deposit_state = deposit
|
|
|
- last_deposit_state_formated = pformat(last_deposit_state, indent=2)
|
|
|
-
|
|
|
- logger.info(f"等待资产在交易所到账...({deposit['confirmTimes']}/{deposit['unlockConfirm']})")
|
|
|
- if Decimal(deposit['confirmTimes']) >= Decimal(deposit['unlockConfirm']):
|
|
|
- is_arrived = True
|
|
|
-
|
|
|
- if is_arrived:
|
|
|
+ # logger.info(f"正在檢查快速提現條件...({waiting_times}/10)")
|
|
|
+ # waiting_times = waiting_times - 1
|
|
|
+
|
|
|
+ # # 最多等待30分钟
|
|
|
+ # waiting_times = 30
|
|
|
+ # last_deposit_state = None
|
|
|
+ # last_deposit_state_formated = None
|
|
|
+ # while waiting_times > 0:
|
|
|
+ # with self.mexc_lock:
|
|
|
+ # deposit_list = copy.deepcopy(self.mexc_data['deposit_list'])
|
|
|
+ # for deposit in deposit_list:
|
|
|
+ # if deposit['transHash'] != self.chain_tx_hash:
|
|
|
+ # continue
|
|
|
+
|
|
|
+ # last_deposit_state = deposit
|
|
|
+ # last_deposit_state_formated = pformat(last_deposit_state, indent=2)
|
|
|
+
|
|
|
+ # logger.info(f"等待资产在交易所到账...({deposit['confirmTimes']}/{deposit['unlockConfirm']})")
|
|
|
+ # if Decimal(deposit['confirmTimes']) >= Decimal(deposit['unlockConfirm']):
|
|
|
+ # is_arrived = True
|
|
|
+
|
|
|
+ # if is_arrived:
|
|
|
|
|
|
- msg = f"资产已在交易所到账。\n{last_deposit_state_formated}"
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
+ # msg = f"资产已在交易所到账。\n{last_deposit_state_formated}"
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
|
|
|
- self._set_state(self.STATE_TRANSFERRING_TO_CHAIN)
|
|
|
- return
|
|
|
+ # self._set_state(self.STATE_TRANSFERRING_TO_CHAIN)
|
|
|
+ # return
|
|
|
|
|
|
- time.sleep(60)
|
|
|
- waiting_times = waiting_times - 1
|
|
|
+ # time.sleep(60)
|
|
|
+ # waiting_times = waiting_times - 1
|
|
|
|
|
|
- msg = f"等待充值到账超时(超过30分钟)。\n{last_deposit_state_formated}"
|
|
|
- logger.error(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+ # msg = f"等待充值到账超时(超过30分钟)。\n{last_deposit_state_formated}"
|
|
|
+ # logger.error(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
|
|
|
- self._set_state(self.STATE_FAILED)
|
|
|
- except Exception as e:
|
|
|
- msg = f"查询交易所到账状态时发生错误:{e}"
|
|
|
- logger.error(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+ # self._set_state(self.STATE_FAILED)
|
|
|
+ # except Exception as e:
|
|
|
+ # msg = f"查询交易所到账状态时发生错误:{e}"
|
|
|
+ # logger.error(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
|
|
|
- self._set_state(self.STATE_FAILED)
|
|
|
+ # self._set_state(self.STATE_FAILED)
|
|
|
|
|
|
- traceback.print_exc()
|
|
|
+ # traceback.print_exc()
|
|
|
|
|
|
- def _execute_transfer_to_chain(self):
|
|
|
- """
|
|
|
- 将交易后获得的币(例如RATO)转账回链上
|
|
|
- """
|
|
|
- msg = "执行:交易所计价资产转账回链上..."
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "pending")
|
|
|
-
|
|
|
- try:
|
|
|
- self.exchange_buy_amount = self.exchange_buy_amount.quantize(self.coin_asset_precision, rounding=ROUND_DOWN)
|
|
|
- pseudo_withdrawal_amount = str(self.exchange_buy_amount)
|
|
|
-
|
|
|
- withdrawal_params = {
|
|
|
- 'coin': self.coin,
|
|
|
- 'netWork': 'ETH',
|
|
|
- 'address': self.user_wallet,
|
|
|
- 'amount': pseudo_withdrawal_amount
|
|
|
- }
|
|
|
- withdrawal_params_formated = pformat(withdrawal_params, indent=2)
|
|
|
- withdrawal_rst = mexc.wallet.post_withdraw(withdrawal_params)
|
|
|
- withdrawal_rst_formated = pformat(withdrawal_rst, indent=2)
|
|
|
- if "id" not in withdrawal_rst:
|
|
|
- msg = f"交易所提现失败\n參數: {withdrawal_params_formated}\n響應: {withdrawal_rst_formated}"
|
|
|
- logger.error(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
-
|
|
|
- self._set_state(self.STATE_FAILED)
|
|
|
- else:
|
|
|
- self.exchange_withdrawal_id = withdrawal_rst["id"]
|
|
|
- msg = f"交易所提现已发送\n{withdrawal_rst_formated}"
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
-
|
|
|
- self._set_state(self.STATE_WAITING_WITHDRAWAL_CONFIRM)
|
|
|
- except Exception as e:
|
|
|
- msg = f"转账回链上失败: {e}"
|
|
|
- logger.error(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
-
|
|
|
- self._set_state(self.STATE_FAILED)
|
|
|
-
|
|
|
- traceback.print_exc()
|
|
|
-
|
|
|
- def _wait_withdrawal_confirm(self):
|
|
|
- """
|
|
|
- 等待交易所提现到链上确认
|
|
|
- """
|
|
|
- exchange_withdrawal_id = self.exchange_withdrawal_id
|
|
|
-
|
|
|
- msg = f"等待交易所提现确认:{exchange_withdrawal_id}"
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "pending")
|
|
|
- try:
|
|
|
- is_arrived = False
|
|
|
-
|
|
|
- # 最多等待30分钟
|
|
|
- waiting_times = 60
|
|
|
- last_deposit_state = None
|
|
|
- last_deposit_state_formated = None
|
|
|
- while waiting_times > 0:
|
|
|
- with self.mexc_lock:
|
|
|
- withdraw_list = copy.deepcopy(self.mexc_data['withdraw_list'])
|
|
|
-
|
|
|
- if not isinstance(withdraw_list, list):
|
|
|
- msg = f"查询交易所提现状态时发生错误:{withdraw_list}"
|
|
|
- logger.error(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
-
|
|
|
- self._set_state("FAILED")
|
|
|
- return
|
|
|
-
|
|
|
- for withdrawal in withdraw_list:
|
|
|
- if withdrawal['id'] != exchange_withdrawal_id:
|
|
|
- continue
|
|
|
-
|
|
|
- last_deposit_state = withdrawal
|
|
|
- last_deposit_state_formated = pformat(last_deposit_state, indent=2)
|
|
|
-
|
|
|
- if withdrawal['status'] == 7:
|
|
|
- is_arrived = True
|
|
|
-
|
|
|
- if is_arrived:
|
|
|
- msg = f"提现请求已上链:\n{last_deposit_state_formated}"
|
|
|
- logger.info(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
-
|
|
|
- self._set_state(self.STATE_COMPLETED)
|
|
|
- return
|
|
|
+ # def _execute_transfer_to_chain(self):
|
|
|
+ # """
|
|
|
+ # 将交易后获得的币(例如RATO)转账回链上
|
|
|
+ # """
|
|
|
+ # msg = "执行:交易所计价资产转账回链上..."
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "pending")
|
|
|
+
|
|
|
+ # try:
|
|
|
+ # self.exchange_buy_amount = self.exchange_buy_amount.quantize(self.coin_asset_precision, rounding=ROUND_DOWN)
|
|
|
+ # pseudo_withdrawal_amount = str(self.exchange_buy_amount)
|
|
|
+
|
|
|
+ # withdrawal_params = {
|
|
|
+ # 'coin': self.coin,
|
|
|
+ # 'netWork': 'ETH',
|
|
|
+ # 'address': self.user_wallet,
|
|
|
+ # 'amount': pseudo_withdrawal_amount
|
|
|
+ # }
|
|
|
+ # withdrawal_params_formated = pformat(withdrawal_params, indent=2)
|
|
|
+ # withdrawal_rst = mexc.wallet.post_withdraw(withdrawal_params)
|
|
|
+ # withdrawal_rst_formated = pformat(withdrawal_rst, indent=2)
|
|
|
+ # if "id" not in withdrawal_rst:
|
|
|
+ # msg = f"交易所提现失败\n參數: {withdrawal_params_formated}\n響應: {withdrawal_rst_formated}"
|
|
|
+ # logger.error(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+
|
|
|
+ # self._set_state(self.STATE_FAILED)
|
|
|
+ # else:
|
|
|
+ # self.exchange_withdrawal_id = withdrawal_rst["id"]
|
|
|
+ # msg = f"交易所提现已发送\n{withdrawal_rst_formated}"
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
+
|
|
|
+ # self._set_state(self.STATE_WAITING_WITHDRAWAL_CONFIRM)
|
|
|
+ # except Exception as e:
|
|
|
+ # msg = f"转账回链上失败: {e}"
|
|
|
+ # logger.error(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+
|
|
|
+ # self._set_state(self.STATE_FAILED)
|
|
|
+
|
|
|
+ # traceback.print_exc()
|
|
|
+
|
|
|
+ # def _wait_withdrawal_confirm(self):
|
|
|
+ # """
|
|
|
+ # 等待交易所提现到链上确认
|
|
|
+ # """
|
|
|
+ # exchange_withdrawal_id = self.exchange_withdrawal_id
|
|
|
+
|
|
|
+ # msg = f"等待交易所提现确认:{exchange_withdrawal_id}"
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "pending")
|
|
|
+ # try:
|
|
|
+ # is_arrived = False
|
|
|
+
|
|
|
+ # # 最多等待30分钟
|
|
|
+ # waiting_times = 60
|
|
|
+ # last_deposit_state = None
|
|
|
+ # last_deposit_state_formated = None
|
|
|
+ # while waiting_times > 0:
|
|
|
+ # with self.mexc_lock:
|
|
|
+ # withdraw_list = copy.deepcopy(self.mexc_data['withdraw_list'])
|
|
|
+
|
|
|
+ # if not isinstance(withdraw_list, list):
|
|
|
+ # msg = f"查询交易所提现状态时发生错误:{withdraw_list}"
|
|
|
+ # logger.error(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+
|
|
|
+ # self._set_state("FAILED")
|
|
|
+ # return
|
|
|
+
|
|
|
+ # for withdrawal in withdraw_list:
|
|
|
+ # if withdrawal['id'] != exchange_withdrawal_id:
|
|
|
+ # continue
|
|
|
+
|
|
|
+ # last_deposit_state = withdrawal
|
|
|
+ # last_deposit_state_formated = pformat(last_deposit_state, indent=2)
|
|
|
+
|
|
|
+ # if withdrawal['status'] == 7:
|
|
|
+ # is_arrived = True
|
|
|
+
|
|
|
+ # if is_arrived:
|
|
|
+ # msg = f"提现请求已上链:\n{last_deposit_state_formated}"
|
|
|
+ # logger.info(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
+
|
|
|
+ # self._set_state(self.STATE_COMPLETED)
|
|
|
+ # return
|
|
|
|
|
|
- time.sleep(30)
|
|
|
- waiting_times = waiting_times - 1
|
|
|
+ # time.sleep(30)
|
|
|
+ # waiting_times = waiting_times - 1
|
|
|
|
|
|
- msg = f"等待提现到账超时(超过30分钟):\n{last_deposit_state_formated}"
|
|
|
- logger.error(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+ # msg = f"等待提现到账超时(超过30分钟):\n{last_deposit_state_formated}"
|
|
|
+ # logger.error(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
|
|
|
- self._set_state(self.STATE_FAILED)
|
|
|
- except Exception as e:
|
|
|
- msg = f"查询交易所提现状态时发生错误:{e}"
|
|
|
- logger.error(msg)
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
- self._set_state(self.STATE_FAILED)
|
|
|
+ # self._set_state(self.STATE_FAILED)
|
|
|
+ # except Exception as e:
|
|
|
+ # msg = f"查询交易所提现状态时发生错误:{e}"
|
|
|
+ # logger.error(msg)
|
|
|
+ # add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+ # self._set_state(self.STATE_FAILED)
|
|
|
|
|
|
- traceback.print_exc()
|
|
|
+ # traceback.print_exc()
|