|
@@ -13,6 +13,7 @@ from psycopg.rows import dict_row
|
|
|
from datetime import datetime, timedelta
|
|
from datetime import datetime, timedelta
|
|
|
import logging
|
|
import logging
|
|
|
import os
|
|
import os
|
|
|
|
|
+import pytz
|
|
|
|
|
|
|
|
# 配置日志
|
|
# 配置日志
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
logging.basicConfig(level=logging.INFO)
|
|
@@ -119,9 +120,16 @@ def get_symbol_data(symbol):
|
|
|
|
|
|
|
|
# 转换为JSON格式
|
|
# 转换为JSON格式
|
|
|
data = []
|
|
data = []
|
|
|
|
|
+ shanghai_tz = pytz.timezone('Asia/Shanghai')
|
|
|
for row in rows:
|
|
for row in rows:
|
|
|
|
|
+ # 将时间戳转换为东8区时间
|
|
|
|
|
+ timestamp = row["timestamp"]
|
|
|
|
|
+ if timestamp and timestamp.tzinfo is None:
|
|
|
|
|
+ timestamp = pytz.utc.localize(timestamp)
|
|
|
|
|
+ if timestamp:
|
|
|
|
|
+ timestamp = timestamp.astimezone(shanghai_tz)
|
|
|
data.append({
|
|
data.append({
|
|
|
- "timestamp": row["timestamp"].isoformat() if row["timestamp"] else None,
|
|
|
|
|
|
|
+ "timestamp": timestamp.isoformat() if timestamp else None,
|
|
|
"binance_mark_price": float(row["binance_mark_price"]) if row["binance_mark_price"] else None,
|
|
"binance_mark_price": float(row["binance_mark_price"]) if row["binance_mark_price"] else None,
|
|
|
"binance_price": float(row["binance_price"]) if row["binance_price"] else None,
|
|
"binance_price": float(row["binance_price"]) if row["binance_price"] else None,
|
|
|
"lighter_mark_price": float(row["lighter_mark_price"]) if row["lighter_mark_price"] else None,
|
|
"lighter_mark_price": float(row["lighter_mark_price"]) if row["lighter_mark_price"] else None,
|
|
@@ -182,9 +190,16 @@ def get_latest_data(symbol):
|
|
|
if not row:
|
|
if not row:
|
|
|
return jsonify({"error": "没有找到数据"}), 404
|
|
return jsonify({"error": "没有找到数据"}), 404
|
|
|
|
|
|
|
|
|
|
+ shanghai_tz = pytz.timezone('Asia/Shanghai')
|
|
|
|
|
+ timestamp = row["timestamp"]
|
|
|
|
|
+ if timestamp and timestamp.tzinfo is None:
|
|
|
|
|
+ timestamp = pytz.utc.localize(timestamp)
|
|
|
|
|
+ if timestamp:
|
|
|
|
|
+ timestamp = timestamp.astimezone(shanghai_tz)
|
|
|
|
|
+
|
|
|
data = {
|
|
data = {
|
|
|
"symbol": symbol,
|
|
"symbol": symbol,
|
|
|
- "timestamp": row["timestamp"].isoformat() if row["timestamp"] else None,
|
|
|
|
|
|
|
+ "timestamp": timestamp.isoformat() if timestamp else None,
|
|
|
"binance_mark_price": float(row["binance_mark_price"]) if row["binance_mark_price"] else None,
|
|
"binance_mark_price": float(row["binance_mark_price"]) if row["binance_mark_price"] else None,
|
|
|
"binance_price": float(row["binance_price"]) if row["binance_price"] else None,
|
|
"binance_price": float(row["binance_price"]) if row["binance_price"] else None,
|
|
|
"lighter_mark_price": float(row["lighter_mark_price"]) if row["lighter_mark_price"] else None,
|
|
"lighter_mark_price": float(row["lighter_mark_price"]) if row["lighter_mark_price"] else None,
|