dededdew
This commit is contained in:
Binary file not shown.
@@ -3,7 +3,7 @@ from peewee import *
|
||||
from models import db
|
||||
|
||||
|
||||
class Weex(Model):
|
||||
class Weex15(Model):
|
||||
id = IntegerField(primary_key=True)
|
||||
open = FloatField(null=True)
|
||||
high = FloatField(null=True)
|
||||
@@ -12,11 +12,24 @@ class Weex(Model):
|
||||
|
||||
class Meta:
|
||||
database = db
|
||||
table_name = 'weex'
|
||||
table_name = 'weex_15'
|
||||
|
||||
|
||||
class Weex1(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 = 'weex_1'
|
||||
|
||||
|
||||
# 连接到数据库
|
||||
db.connect()
|
||||
|
||||
# 创建表(如果表不存在)
|
||||
db.create_tables([Weex])
|
||||
db.create_tables([Weex15])
|
||||
db.create_tables([Weex1])
|
||||
|
||||
83
weex/抓取数据_1.py
Normal file
83
weex/抓取数据_1.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import random
|
||||
import time
|
||||
|
||||
from curl_cffi import requests
|
||||
|
||||
from models.weex import Weex1
|
||||
|
||||
headers = {
|
||||
'accept': 'application/json, text/plain, */*',
|
||||
'accept-language': 'zh-CN,zh;q=0.9,zh-HK;q=0.8,en;q=0.7',
|
||||
'appversion': '2.0.0',
|
||||
'bundleid': '',
|
||||
'cache-control': 'no-cache',
|
||||
'language': 'zh_CN',
|
||||
'origin': 'https://www.weex.com',
|
||||
'pragma': 'no-cache',
|
||||
'priority': 'u=1, i',
|
||||
'referer': 'https://www.weex.com/',
|
||||
'sec-ch-ua': '"Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
'sec-fetch-dest': 'empty',
|
||||
'sec-fetch-mode': 'cors',
|
||||
'sec-fetch-site': 'cross-site',
|
||||
'sidecar': '0115665ae5d5a18da1543cd0deabd52588c09f4d3b028876659f0801ca7af5a3ba',
|
||||
'terminalcode': '55a01525ddf9e8f4bb158345db69b510',
|
||||
'terminaltype': '1',
|
||||
'traceid': 'mgotla61s5segrwkkw',
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
|
||||
'vs': 'Z567O6188nsWfe9Njo9N7KsAbL0RO6ho',
|
||||
'x-sig': 'bb0f194c38f69c38ffbcb361c27c7295',
|
||||
'x-timestamp': '1760341017529',
|
||||
}
|
||||
|
||||
klineId = None
|
||||
klineTime = None
|
||||
contractId = None
|
||||
|
||||
while True:
|
||||
|
||||
for i in range(500):
|
||||
print(i)
|
||||
params = {
|
||||
'languageType': '1',
|
||||
'sign': 'SIGN',
|
||||
'timeZone': 'string',
|
||||
'contractId': '10000002',
|
||||
'productCode': 'ethusdt',
|
||||
'priceType': 'LAST_PRICE',
|
||||
'klineType': 'MINUTE_1',
|
||||
'limit': '200',
|
||||
}
|
||||
|
||||
if klineId:
|
||||
params['nextKey.klineId'] = klineId
|
||||
params['nextKey.contractId'] = contractId
|
||||
|
||||
if klineTime:
|
||||
params['nextKey.klineTime'] = klineTime
|
||||
|
||||
response = requests.get('https://http-gateway1.janapw.com/api/v1/public/quote/v1/getKlineV2', params=params,
|
||||
headers=headers)
|
||||
|
||||
klineId = response.json()["data"]["nextKey"]["klineId"]
|
||||
klineTime = response.json()["data"]["nextKey"]["klineTime"]
|
||||
contractId = response.json()["data"]["nextKey"]["contractId"]
|
||||
|
||||
for data in response.json()["data"]["dataList"]:
|
||||
# print(data)
|
||||
|
||||
Weex1.get_or_create(
|
||||
id=int(data[4]),
|
||||
defaults={
|
||||
'open': float(data[3]),
|
||||
'high': float(data[1]),
|
||||
'low': float(data[2]),
|
||||
'close': float(data[0]),
|
||||
}
|
||||
)
|
||||
|
||||
time.sleep(random.randint(1, 50))
|
||||
|
||||
# time.sleep(3600)
|
||||
@@ -2,7 +2,7 @@ import time
|
||||
|
||||
from curl_cffi import requests
|
||||
|
||||
from models.weex import Weex
|
||||
from models.weex import Weex15
|
||||
|
||||
headers = {
|
||||
'accept': 'application/json, text/plain, */*',
|
||||
@@ -68,7 +68,7 @@ while True:
|
||||
for data in response.json()["data"]["dataList"]:
|
||||
# print(data)
|
||||
|
||||
Weex.get_or_create(
|
||||
Weex15.get_or_create(
|
||||
id=int(data[4]),
|
||||
defaults={
|
||||
'open': float(data[3]),
|
||||
32
weex/自动化抓取数据.py
Normal file
32
weex/自动化抓取数据.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from DrissionPage import ChromiumPage, ChromiumOptions
|
||||
|
||||
from models.weex import Weex1
|
||||
|
||||
if __name__ == '__main__':
|
||||
co = ChromiumOptions()
|
||||
co.set_local_port(1001)
|
||||
|
||||
page = ChromiumPage(addr_or_opts=co)
|
||||
|
||||
page.set.window.max()
|
||||
|
||||
page.listen.start("gateway1.janapw.com/api/v1/public/quote/v1/getKlineV2")
|
||||
|
||||
page.get(url="https://www.weeaxs.site/zh-CN/futures/ETH-USDT")
|
||||
|
||||
for _ in range(10000):
|
||||
res = page.listen.wait() # 等待并获取一个数据包
|
||||
|
||||
print(_)
|
||||
print(res.response.url)
|
||||
|
||||
for data in res.response.body['data']["dataList"]:
|
||||
Weex1.get_or_create(
|
||||
id=int(data[4]),
|
||||
defaults={
|
||||
'open': float(data[3]),
|
||||
'high': float(data[1]),
|
||||
'low': float(data[2]),
|
||||
'close': float(data[0]),
|
||||
}
|
||||
)
|
||||
@@ -1,7 +1,7 @@
|
||||
import datetime
|
||||
|
||||
from loguru import logger
|
||||
from models.weex import Weex
|
||||
from models.weex import Weex15
|
||||
|
||||
|
||||
def is_bullish(candle):
|
||||
@@ -119,7 +119,7 @@ def get_data_by_date(date_str):
|
||||
end_timestamp = int((target_date + datetime.timedelta(days=1)).timestamp() * 1000) - 1
|
||||
|
||||
# 查询该天的数据,并按照 id 字段从小到大排序
|
||||
query = Weex.select().where(Weex.id.between(start_timestamp, end_timestamp)).order_by(Weex.id.asc())
|
||||
query = Weex15.select().where(Weex15.id.between(start_timestamp, end_timestamp)).order_by(Weex15.id.asc())
|
||||
results = list(query)
|
||||
|
||||
# 将结果转换为列表嵌套字典的形式
|
||||
@@ -142,7 +142,7 @@ if __name__ == '__main__':
|
||||
# 示例调用
|
||||
datas = []
|
||||
for i in range(1, 31):
|
||||
date_str = f'2025-8-{i}'
|
||||
date_str = f'2025-6-{i}'
|
||||
data = get_data_by_date(date_str)
|
||||
|
||||
datas.extend(data)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import datetime
|
||||
|
||||
from loguru import logger
|
||||
from models.weex import Weex
|
||||
from models.weex import Weex15
|
||||
|
||||
|
||||
def is_bullish(candle):
|
||||
@@ -119,7 +119,7 @@ def get_data_by_date(date_str):
|
||||
end_timestamp = int((target_date + datetime.timedelta(days=1)).timestamp() * 1000) - 1
|
||||
|
||||
# 查询该天的数据,并按照 id 字段从小到大排序
|
||||
query = Weex.select().where(Weex.id.between(start_timestamp, end_timestamp)).order_by(Weex.id.asc())
|
||||
query = Weex15.select().where(Weex15.id.between(start_timestamp, end_timestamp)).order_by(Weex15.id.asc())
|
||||
results = list(query)
|
||||
|
||||
# 将结果转换为列表嵌套字典的形式
|
||||
|
||||
Reference in New Issue
Block a user