|
@@ -191,23 +191,30 @@ class ArbitrageProcess:
|
|
|
pseudo_amount_to_sell = self.exchange_sell_amount.quantize(Decimal('1'), rounding=ROUND_DOWN)
|
|
pseudo_amount_to_sell = self.exchange_sell_amount.quantize(Decimal('1'), rounding=ROUND_DOWN)
|
|
|
|
|
|
|
|
# 交易所套保余额判断
|
|
# 交易所套保余额判断
|
|
|
- balances = mexc.trade.get_account_info()['balances']
|
|
|
|
|
- for balance in balances:
|
|
|
|
|
- if balance['asset'] == self.coin:
|
|
|
|
|
- if Decimal(balance['free']) < pseudo_amount_to_sell:
|
|
|
|
|
- msg = f"交易所剩余{self.coin}: {balance['free']}, 交易所准备卖出:{pseudo_amount_to_sell}, 不能触发套保交易。"
|
|
|
|
|
- logger.info(msg)
|
|
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
|
|
- self._set_state(self.STATE_REJECT)
|
|
|
|
|
- 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
|
|
|
|
|
|
|
+ with self.mexc_lock:
|
|
|
|
|
+ balances = self.mexc_data['account_info']['balances']
|
|
|
|
|
+
|
|
|
|
|
+ for balance in balances:
|
|
|
|
|
+ if balance['asset'] == self.coin:
|
|
|
|
|
+ if Decimal(balance['free']) < pseudo_amount_to_sell:
|
|
|
|
|
+ msg = f"交易所剩余{self.coin}: {balance['free']}, 交易所准备卖出:{pseudo_amount_to_sell}, 不能触发套保交易。"
|
|
|
|
|
+ logger.info(msg)
|
|
|
|
|
+ add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
|
|
+ self._set_state(self.STATE_REJECT)
|
|
|
|
|
+ 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")
|
|
|
|
|
+
|
|
|
|
|
+ balance['free'] = str(Decimal(balance['free']) - pseudo_amount_to_sell)
|
|
|
|
|
+
|
|
|
|
|
+ break
|
|
|
|
|
|
|
|
# step2,估算gas
|
|
# step2,估算gas
|
|
|
- latest_block = web3.w3.eth.get_block('latest')
|
|
|
|
|
|
|
+ logger.info("獲取區塊信息")
|
|
|
|
|
+ with self.core_lock:
|
|
|
|
|
+ latest_block = copy.deepcopy(self.core_data['block'])
|
|
|
self.tx['maxPriorityFeePerGas'] = int(int(self.tx['maxPriorityFeePerGas']) * self.gas_price_multiplier)
|
|
self.tx['maxPriorityFeePerGas'] = int(int(self.tx['maxPriorityFeePerGas']) * self.gas_price_multiplier)
|
|
|
self.tx['maxFeePerGas'] = int(int(latest_block['baseFeePerGas']) * 2 + self.tx['maxPriorityFeePerGas'])
|
|
self.tx['maxFeePerGas'] = int(int(latest_block['baseFeePerGas']) * 2 + self.tx['maxPriorityFeePerGas'])
|
|
|
|
|
|
|
@@ -215,6 +222,7 @@ class ArbitrageProcess:
|
|
|
gas_price_gwei = gas_price / Decimal('1e9')
|
|
gas_price_gwei = gas_price / Decimal('1e9')
|
|
|
gas_price_gwei = gas_price_gwei.quantize(Decimal('1e-9'), rounding=ROUND_DOWN)
|
|
gas_price_gwei = gas_price_gwei.quantize(Decimal('1e-9'), rounding=ROUND_DOWN)
|
|
|
|
|
|
|
|
|
|
+ logger.info("鏈上各種校驗")
|
|
|
estimated_gas_origin = web3.w3.eth.estimate_gas(self.tx)
|
|
estimated_gas_origin = web3.w3.eth.estimate_gas(self.tx)
|
|
|
estimated_gas = int(estimated_gas_origin * self.gas_limit_multiplier)
|
|
estimated_gas = int(estimated_gas_origin * self.gas_limit_multiplier)
|
|
|
estimated_wei = Decimal(estimated_gas) * gas_price
|
|
estimated_wei = Decimal(estimated_gas) * gas_price
|
|
@@ -600,22 +608,23 @@ class ArbitrageProcess:
|
|
|
pseudo_amount_to_buy = pseudo_amount_to_buy.quantize(Decimal('1'), rounding=ROUND_DOWN)
|
|
pseudo_amount_to_buy = pseudo_amount_to_buy.quantize(Decimal('1'), rounding=ROUND_DOWN)
|
|
|
|
|
|
|
|
# 交易所U余额判断
|
|
# 交易所U余额判断
|
|
|
- balances = mexc.trade.get_account_info()['balances']
|
|
|
|
|
- for balance in balances:
|
|
|
|
|
- if balance['asset'] == self.base_coin:
|
|
|
|
|
- pseudo_amount_to_buy = min(Decimal(balance['free']), pseudo_amount_to_buy)
|
|
|
|
|
-
|
|
|
|
|
- if pseudo_amount_to_buy < Decimal('10'):
|
|
|
|
|
- msg = f"交易所剩余{self.base_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.base_coin}: {balance['free']}, 交易所准备使用:{pseudo_amount_to_buy}, 余额校验通过(可以回滚)。"
|
|
|
|
|
- logger.info(msg)
|
|
|
|
|
- add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
|
|
- break
|
|
|
|
|
|
|
+ with self.mexc_lock:
|
|
|
|
|
+ balances = self.mexc_data['account_info']['balances']
|
|
|
|
|
+ for balance in balances:
|
|
|
|
|
+ if balance['asset'] == self.base_coin:
|
|
|
|
|
+ pseudo_amount_to_buy = min(Decimal(balance['free']), pseudo_amount_to_buy)
|
|
|
|
|
+
|
|
|
|
|
+ if pseudo_amount_to_buy < Decimal('10'):
|
|
|
|
|
+ msg = f"交易所剩余{self.base_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.base_coin}: {balance['free']}, 交易所准备使用:{pseudo_amount_to_buy}, 余额校验通过(可以回滚)。"
|
|
|
|
|
+ logger.info(msg)
|
|
|
|
|
+ add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
|
|
+ break
|
|
|
|
|
|
|
|
order_params = {
|
|
order_params = {
|
|
|
"symbol": self.symbol.replace('_', ''),
|
|
"symbol": self.symbol.replace('_', ''),
|
|
@@ -702,7 +711,8 @@ class ArbitrageProcess:
|
|
|
last_deposit_state = None
|
|
last_deposit_state = None
|
|
|
while waiting_times > 0:
|
|
while waiting_times > 0:
|
|
|
time.sleep(60)
|
|
time.sleep(60)
|
|
|
- deposit_list = mexc.wallet.get_deposit_list()
|
|
|
|
|
|
|
+ with mexc_lock:
|
|
|
|
|
+ deposit_list = copy.deepcopy(self.mexc_data['deposit_list'])
|
|
|
|
|
|
|
|
# 是否已經在列表中了,抹茶識別充值會稍微有點慢,所以要耐心等
|
|
# 是否已經在列表中了,抹茶識別充值會稍微有點慢,所以要耐心等
|
|
|
is_list = False
|
|
is_list = False
|
|
@@ -726,7 +736,8 @@ class ArbitrageProcess:
|
|
|
# 檢查是否滿足快速提現的條件
|
|
# 檢查是否滿足快速提現的條件
|
|
|
if is_list:
|
|
if is_list:
|
|
|
# 交易所代幣余额判断
|
|
# 交易所代幣余额判断
|
|
|
- balances = mexc.trade.get_account_info()['balances']
|
|
|
|
|
|
|
+ with mexc_lock:
|
|
|
|
|
+ balances = copy.deepcopy(self.mexc_data['account_info']['balances'])
|
|
|
asset_balance = 0
|
|
asset_balance = 0
|
|
|
for balance in balances:
|
|
for balance in balances:
|
|
|
if balance['asset'] == self.coin:
|
|
if balance['asset'] == self.coin:
|
|
@@ -755,7 +766,8 @@ class ArbitrageProcess:
|
|
|
last_deposit_state = None
|
|
last_deposit_state = None
|
|
|
last_deposit_state_formated = None
|
|
last_deposit_state_formated = None
|
|
|
while waiting_times > 0:
|
|
while waiting_times > 0:
|
|
|
- deposit_list = mexc.wallet.get_deposit_list()
|
|
|
|
|
|
|
+ with mexc_lock:
|
|
|
|
|
+ deposit_list = copy.deepcopy(self.mexc_data['deposit_list'])
|
|
|
for deposit in deposit_list:
|
|
for deposit in deposit_list:
|
|
|
if deposit['transHash'] != self.chain_tx_hash:
|
|
if deposit['transHash'] != self.chain_tx_hash:
|
|
|
continue
|
|
continue
|
|
@@ -852,17 +864,18 @@ class ArbitrageProcess:
|
|
|
last_deposit_state = None
|
|
last_deposit_state = None
|
|
|
last_deposit_state_formated = None
|
|
last_deposit_state_formated = None
|
|
|
while waiting_times > 0:
|
|
while waiting_times > 0:
|
|
|
- withdrawal_list = mexc.wallet.get_withdraw_list()
|
|
|
|
|
|
|
+ with mexc_lock:
|
|
|
|
|
+ withdraw_list = copy.deepcopy(self.mexc_data['withdraw_list'])
|
|
|
|
|
|
|
|
- if not isinstance(withdrawal_list, list):
|
|
|
|
|
- msg = f"查询交易所提现状态时发生错误:{withdrawal_list}"
|
|
|
|
|
|
|
+ if not isinstance(withdraw_list, list):
|
|
|
|
|
+ msg = f"查询交易所提现状态时发生错误:{withdraw_list}"
|
|
|
logger.error(msg)
|
|
logger.error(msg)
|
|
|
add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
|
|
|
|
|
self._set_state("FAILED")
|
|
self._set_state("FAILED")
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- for withdrawal in withdrawal_list:
|
|
|
|
|
|
|
+ for withdrawal in withdraw_list:
|
|
|
if withdrawal['id'] != exchange_withdrawal_id:
|
|
if withdrawal['id'] != exchange_withdrawal_id:
|
|
|
continue
|
|
continue
|
|
|
|
|
|