Explorar el Código

第一个方向的公平价的加入

skyfffire hace 2 meses
padre
commit
f17e0abb6a
Se han modificado 1 ficheros con 18 adiciones y 0 borrados
  1. 18 0
      checker/c_erc20_to_mexc.py

+ 18 - 0
checker/c_erc20_to_mexc.py

@@ -80,6 +80,11 @@ historical_data_points = deque(maxlen=MAX_HISTORY_POINTS_PLOTLY)
 TARGET_ASSET_SYMBOL = CEX_TARGET_PAIR_USDT.split('_')[0] # e.g., RATO
 BASE_CURRENCY_SYMBOL = CEX_TARGET_PAIR_USDT.split('_')[1] # e.g., USDT (assumed to be consistent with IN_TOKEN_ADDRESS)
 
+# 价差与平均价差
+GAMMA = decimal.Decimal(0.9999)
+GAMMA_1 = decimal.Decimal(0.99)
+spread_ema = decimal.Decimal(0)
+count = decimal.Decimal(0)
 # --- 链上价格获取函数 (Okx) ---
 # 返回: price_base_per_target (例如 USDT per RATO)
 def get_chain_price_vs_target_currency(chain_id, in_token_addr, out_token_addr, amount_in_base_human, in_token_decimals, slippage, user_wallet_addr, user_exchange_wallet_addr):
@@ -298,6 +303,19 @@ def update_data_for_plotly_and_table():
         dex_price = erc20_data.get("price_base_per_target") # USDT/TARGET
         erc20_err = erc20_data.get("error")
 
+        # 加入价差,考虑spread重新计算dex_price
+        global spread_ema, count
+        spread = dex_price - cex_price
+        if count < 120:
+            count = count + 1
+            if count == 1:
+                spread_ema = spread
+            else:
+                spread_ema = spread_ema * GAMMA_1 + spread * (decimal.Decimal(1) - GAMMA_1)
+        else:
+            spread_ema = spread_ema * GAMMA + spread * (decimal.Decimal(1) - GAMMA)
+        dex_price = dex_price - spread_ema
+
         # 4. 计算百分比差异
         # diff = (CEX卖价 - 链上买价) / 链上买价
         diff_erc20_vs_cex_pct = calculate_percentage_diff(