bitmart优化完成

This commit is contained in:
Administrator
2026-01-27 14:29:59 +08:00
parent 42fc443760
commit e48e11de45
8 changed files with 26 additions and 5 deletions

View File

@@ -6,7 +6,7 @@ BitMart 30分钟K线数据抓取脚本
import time
from loguru import logger
from bitmart.api_contract import APIContract
from models.bitmart import BitMart30
from models.bitmart_15 import BitMart15
class BitMartDataCollector:
@@ -29,11 +29,11 @@ class BitMartDataCollector:
if not end_time:
end_time = int(time.time())
if not start_time:
start_time = end_time - 3600 * 24 * 7 # 默认获取最近7天
start_time = end_time - 3600 * 24 * 1 # 默认获取最近7天
response = self.contractAPI.get_kline(
contract_symbol=self.contract_symbol,
step=30, # 30分钟
step=15, # 30分钟
start_time=start_time,
end_time=end_time
)[0]
@@ -73,7 +73,7 @@ class BitMartDataCollector:
saved_count = 0
for kline in klines:
try:
BitMart30.get_or_create(
BitMart15.get_or_create(
id=kline['id'],
defaults={
'open': kline['open'],
@@ -144,7 +144,7 @@ if __name__ == '__main__':
collector = BitMartDataCollector()
# 抓取最近30天的历史数据
collector.collect_historical_data(days=365)
collector.collect_historical_data(days=500)
# 如果需要实时抓取,可以取消下面的注释
# collector.collect_realtime_data()

21
models/bitmart_15.py Normal file
View File

@@ -0,0 +1,21 @@
from peewee import *
from models import db
class BitMart15(Model):
id = IntegerField(primary_key=True) # 时间戳(毫秒级)
open = FloatField(null=True)
high = FloatField(null=True)
low = FloatField(null=True)
close = FloatField(null=True)
class Meta:
database = db
table_name = 'bitmart_15'
# 连接到数据库
db.connect()
# 创建表(如果表不存在)
db.create_tables([BitMart15])

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.