|
@@ -8,6 +8,7 @@ import json
|
|
|
from mexc_client import MexcClient
|
|
from mexc_client import MexcClient
|
|
|
from decimal import Decimal, ROUND_DOWN
|
|
from decimal import Decimal, ROUND_DOWN
|
|
|
from as_utils import add_state_flow_entry
|
|
from as_utils import add_state_flow_entry
|
|
|
|
|
+from decimal_utils import decimal_to_string_no_scientific
|
|
|
from checker.logger_config import get_logger
|
|
from checker.logger_config import get_logger
|
|
|
from pprint import pformat
|
|
from pprint import pformat
|
|
|
from pprint import pprint
|
|
from pprint import pprint
|
|
@@ -280,6 +281,7 @@ class ArbitrageProcess:
|
|
|
# 处理精度
|
|
# 处理精度
|
|
|
pseudo_amount_to_sell = pseudo_amount_to_sell.quantize(self.coin_asset_precision, rounding=ROUND_DOWN)
|
|
pseudo_amount_to_sell = pseudo_amount_to_sell.quantize(self.coin_asset_precision, rounding=ROUND_DOWN)
|
|
|
price_for_api = self.dex_price.quantize(self.price_precision, rounding=ROUND_DOWN)
|
|
price_for_api = self.dex_price.quantize(self.price_precision, rounding=ROUND_DOWN)
|
|
|
|
|
+ price_for_api = decimal_to_string_no_scientific(price_for_api)
|
|
|
# 初始化 quantity 变量
|
|
# 初始化 quantity 变量
|
|
|
quantity_for_api = None
|
|
quantity_for_api = None
|
|
|
# 用求余法判断是否是整数
|
|
# 用求余法判断是否是整数
|
|
@@ -410,10 +412,12 @@ 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)
|
|
|
|
|
|
|
|
- ready_order_price = dex_price * (Decimal(1) - self.close_limit)
|
|
|
|
|
|
|
+ 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)
|
|
|
|
|
|
|
|
# 准备购入的价值, 如果小于2u就不要提交了
|
|
# 准备购入的价值, 如果小于2u就不要提交了
|
|
|
- pseudo_value_to_buy = ready_order_price * (self.already_sold_amount - self.already_bought_amount)
|
|
|
|
|
|
|
+ pseudo_value_to_buy = price_for_api * (self.already_sold_amount - self.already_bought_amount)
|
|
|
|
|
|
|
|
if pseudo_value_to_buy < 2:
|
|
if pseudo_value_to_buy < 2:
|
|
|
break
|
|
break
|
|
@@ -435,13 +439,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}, 挂单价格{ready_order_price}, 余额校验通过。"
|
|
|
|
|
|
|
+ msg = f"交易所剩余{self.base_coin}: {free_balance}, 准备使用 {pseudo_value_to_buy}, fp {dex_price}, 挂单价格{price_for_api}, 余额校验通过。"
|
|
|
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 / ready_order_price
|
|
|
|
|
|
|
+ quantity_for_api = pseudo_value_to_buy / price_for_api
|
|
|
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,7 +459,7 @@ class ArbitrageProcess:
|
|
|
"symbol": self.symbol.replace('_', ''),
|
|
"symbol": self.symbol.replace('_', ''),
|
|
|
"side": "BUY",
|
|
"side": "BUY",
|
|
|
"type": "LIMIT",
|
|
"type": "LIMIT",
|
|
|
- "price": ready_order_price,
|
|
|
|
|
|
|
+ "price": price_for_api,
|
|
|
"quantity": quantity_for_api,
|
|
"quantity": quantity_for_api,
|
|
|
}
|
|
}
|
|
|
order_params_formated = pformat(order_params, indent=2)
|
|
order_params_formated = pformat(order_params, indent=2)
|
|
@@ -471,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 = ready_order_price
|
|
|
|
|
|
|
+ order_price = price_for_api
|
|
|
# 有订单时的逻辑
|
|
# 有订单时的逻辑
|
|
|
else:
|
|
else:
|
|
|
# 获取订单状态, 直到完全成交或超时
|
|
# 获取订单状态, 直到完全成交或超时
|
|
@@ -499,7 +503,7 @@ class ArbitrageProcess:
|
|
|
exchange_buy_order = None
|
|
exchange_buy_order = None
|
|
|
|
|
|
|
|
# 如果没有成交或取消则判断是否达到取消条件了, 这里面不能置空
|
|
# 如果没有成交或取消则判断是否达到取消条件了, 这里面不能置空
|
|
|
- elif (Decimal(1) - order_price / ready_order_price) > Decimal(0.0005):
|
|
|
|
|
|
|
+ elif (Decimal(1) - order_price / price_for_api) > 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
|