|
|
@@ -2,6 +2,7 @@ import time
|
|
|
import logging
|
|
|
from web3_py_client import EthClient
|
|
|
import mexc_client as mexc
|
|
|
+from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN
|
|
|
|
|
|
web3 = EthClient()
|
|
|
|
|
|
@@ -43,9 +44,10 @@ class ArbitrageProcess:
|
|
|
self.to_token_addr = to_token
|
|
|
|
|
|
# 存储当前套利交易的细节信息,例如买入数量、价格等
|
|
|
+ chain_usdt_use = decimal.Decimal(from_token_amount_human)
|
|
|
self.arbitrage_details = {
|
|
|
"chain_buy_tx_hash": None, # 链上买入的tx hash
|
|
|
- "chain_usdt_use": from_token_amount_human, # 链上usdt减少量(使用量), todo, 暂用固定值代替
|
|
|
+ "chain_usdt_use": chain_usdt_use, # 链上usdt减少量(使用量), todo, 暂用固定值代替
|
|
|
"chain_buy_amount": None, # 链上币增加量(购入量), todo, 暂用即时余额代替
|
|
|
"chain_buy_price": None, # 链上购入价, todo
|
|
|
"chain_withdrawal_tx_hash": None, # 链上转入交易所的id
|
|
|
@@ -184,14 +186,11 @@ class ArbitrageProcess:
|
|
|
actual_buy_amount = web3.get_erc20_balance(self.to_token_addr)
|
|
|
self.arbitrage_details["chain_buy_amount"] = actual_buy_amount # 存储实际买入数量
|
|
|
|
|
|
- buy_token_decimal = web3.get_erc20_decimals(self.to_token_addr)
|
|
|
-
|
|
|
- buy_amount_human = actual_buy_amount / (10 ** buy_token_decimal)
|
|
|
- buy_amount_human = truncate_float_string(buy_amount_human, 2)
|
|
|
+ buy_amount_human = actual_buy_amount.quantize(decimal.Decimal('1e-2'), rounding=ROUND_DOWN)
|
|
|
sell_amount_human = self.arbitrage_details["chain_usdt_use"]
|
|
|
|
|
|
price_human = sell_amount_human / buy_amount_human
|
|
|
- price_human = truncate_float_string(price_human, 10)
|
|
|
+ price_human = price_human.quantize(decimal.Decimal('1e-8'), rounding=ROUND_DOWN)
|
|
|
|
|
|
logging.info(f"用{sell_amount_human}买入{buy_amount_human},价格{price_human}。")
|
|
|
self._set_state("TRANSFERRING_TO_EXCHANGE")
|