|
@@ -505,58 +505,6 @@ async def trigger_strategy_update():
|
|
|
await trading_strategy.do_strategy(market_data)
|
|
await trading_strategy.do_strategy(market_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def process_data():
|
|
|
|
|
- """
|
|
|
|
|
- 处理从两个交易所获取的数据,并将匹配的交易对数据保存到数据库
|
|
|
|
|
- 现在使用order_book_cache作为Lighter数据源,binance_data_cache作为Binance数据源
|
|
|
|
|
- """
|
|
|
|
|
- if not order_book_cache or not binance_data_cache['latest_prices']:
|
|
|
|
|
- logger.warning("缺少必要的数据,跳过本次处理")
|
|
|
|
|
- return 0
|
|
|
|
|
-
|
|
|
|
|
- # 准备批量写入的数据
|
|
|
|
|
- batch_data = []
|
|
|
|
|
- matching_count = 0
|
|
|
|
|
-
|
|
|
|
|
- # 遍历market_id_to_market_info映射,查找匹配的交易对
|
|
|
|
|
- for market_id, market_info in market_id_to_market_info.items():
|
|
|
|
|
- # 检查Lighter数据是否存在
|
|
|
|
|
- if market_id not in order_book_cache:
|
|
|
|
|
- continue
|
|
|
|
|
-
|
|
|
|
|
- # 获取交易对符号
|
|
|
|
|
- symbol = market_info.get('symbol')
|
|
|
|
|
- # 构造Binance交易对名称
|
|
|
|
|
- binance_symbol = f"{symbol}USDT"
|
|
|
|
|
-
|
|
|
|
|
- # 检查Binance数据是否存在
|
|
|
|
|
- if binance_symbol not in binance_data_cache['latest_prices']:
|
|
|
|
|
- continue
|
|
|
|
|
-
|
|
|
|
|
- # 获取数据
|
|
|
|
|
- order_book_instance = order_book_cache[market_id]
|
|
|
|
|
- binance_latest_price = binance_data_cache['latest_prices'][binance_symbol]
|
|
|
|
|
-
|
|
|
|
|
- # 构建数据记录
|
|
|
|
|
- symbol_data = {
|
|
|
|
|
- 'symbol': symbol,
|
|
|
|
|
- 'binance_price': binance_latest_price,
|
|
|
|
|
- 'timestamp': int(time.time() * 1000) # 毫秒时间戳
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- batch_data.append(symbol_data)
|
|
|
|
|
- matching_count += 1
|
|
|
|
|
-
|
|
|
|
|
- # # 如果有匹配的数据,批量写入数据库
|
|
|
|
|
- # if batch_data:
|
|
|
|
|
- # logger.info(f"找到 {matching_count} 个匹配的交易对,准备写入数据库")
|
|
|
|
|
- # #write_batch_to_questdb(batch_data)
|
|
|
|
|
- # else:
|
|
|
|
|
- # logger.warning("没有找到匹配的交易对数据")
|
|
|
|
|
-
|
|
|
|
|
- return matching_count
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
async def main():
|
|
async def main():
|
|
|
"""运行数据收集循环的主函数"""
|
|
"""运行数据收集循环的主函数"""
|
|
|
global trading_strategy
|
|
global trading_strategy
|