Skip to content

Commit 3307c30

Browse files
committed
更新数据源路径,添加自动同步配置、修复错误代码文件
2 parents 366d461 + acee43b commit 3307c30

File tree

4 files changed

+311
-38
lines changed

4 files changed

+311
-38
lines changed

.github/workflows/auto-sync.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
on:
2+
push:
3+
branches: [master]
4+
name: Mirror GitHub Repos to Gitee
5+
jobs:
6+
run:
7+
name: Sync-GitHub-to-Gitee
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Mirror the Github repos to Gitee.
11+
uses: Yikun/hub-mirror-action@master
12+
with:
13+
src: github/BigBrotherTrade
14+
dst: gitee/timercrack
15+
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
16+
dst_token: ${{ secrets.GITEE_TOKEN }}
17+
force_update: true
18+
src_account_type: org
19+
dst_account_type: user
20+
mappings: "dashboard=>dashboards"
21+
static_list: "trader"
22+
cache_path: /github/workspace/hub-mirror-cache

test/test.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,29 @@
1-
import aioredis
1+
import sys
2+
import os
3+
import django
4+
if sys.platform == 'darwin':
5+
sys.path.append('/Users/jeffchen/Documents/gitdir/dashboard')
6+
elif sys.platform == 'win32':
7+
sys.path.append(r'E:\github\dashboard')
8+
else:
9+
sys.path.append('/root/gitee/dashboard')
10+
os.environ["DJANGO_SETTINGS_MODULE"] = "dashboard.settings"
11+
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
12+
django.setup()
213
import asyncio
14+
import datetime
15+
import pytz
16+
from trader.utils import update_from_czce
317

418

5-
async def reader(message):
6-
print(f"in reader: {message}, type={type(message)}")
7-
8-
9-
async def monitor1(pb: aioredis.client.PubSub):
10-
async for msg in pb.listen():
11-
print(f"in monitor1: {msg}, type={type(msg)}")
12-
asyncio.create_task(reader(msg))
13-
if msg['type'] == 'punsubscribe':
14-
print('quit monitor1')
15-
break
16-
17-
18-
async def main():
19-
redis = await aioredis.from_url("redis://192.168.123.142", decode_responses=True)
20-
pubsub1 = redis.pubsub()
21-
pubsub2 = redis.pubsub()
22-
await pubsub1.psubscribe('channel:*')
23-
await pubsub2.psubscribe('channel*')
24-
await redis.publish("channel:1", "1")
25-
await redis.publish("channel:2", "6")
26-
await redis.publish("channel:3", "3")
27-
await pubsub1.punsubscribe()
28-
await pubsub2.punsubscribe()
29-
loop = asyncio.get_running_loop()
30-
asyncio.run_coroutine_threadsafe(monitor1(pubsub1), loop)
31-
asyncio.run_coroutine_threadsafe(monitor1(pubsub2), loop)
32-
# await asyncio.gather(monitor1(pubsub1), monitor1(pubsub2))
33-
# await pubsub2.run()
34-
print('main done!')
35-
3619
if __name__ == "__main__":
3720
try:
3821
loop = asyncio.new_event_loop()
3922
asyncio.set_event_loop(loop)
40-
loop.create_task(main())
41-
loop.run_forever()
23+
day = datetime.datetime.now().replace(tzinfo=pytz.FixedOffset(480))
24+
day = day - datetime.timedelta(days=1)
25+
loop.run_until_complete(update_from_czce(day))
26+
print("DONE!")
4227
except KeyboardInterrupt:
4328
pass
4429

trader/utils/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async def update_from_shfe(day: datetime.datetime) -> bool:
123123
async with aiohttp.ClientSession() as session:
124124
day_str = day.strftime('%Y%m%d')
125125
await max_conn_shfe.acquire()
126-
async with session.get(f'http://{shfe_ip}/data/dailydata/kx/kx{day_str}.dat') as response:
126+
async with session.get(f'http://{shfe_ip}/data/tradedata/future/dailydata/kx{day_str}.dat') as response:
127127
rst = await response.read()
128128
rst_json = json.loads(rst)
129129
max_conn_shfe.release()
@@ -226,7 +226,7 @@ async def update_from_dce(day: datetime.datetime) -> bool:
226226
'year': day.year, 'month': day.month-1, 'day': day.day}) as response:
227227
rst = await response.text()
228228
max_conn_dce.release()
229-
for lines in rst.split('\r\n')[1:-3]:
229+
for lines in rst.split('\r\n')[3:-3]:
230230
if '小计' in lines or '品种' in lines:
231231
continue
232232
inst_data_raw = [x.strip() for x in lines.split('\t')]
@@ -297,7 +297,7 @@ async def update_from_cffex(day: datetime.datetime) -> bool:
297297
try:
298298
async with aiohttp.ClientSession() as session:
299299
await max_conn_cffex.acquire()
300-
async with session.get(f"http://{cffex_ip}/fzjy/mrhq/{day.strftime('%Y%m/%d')}/index.xml") as response:
300+
async with session.get(f"http://{cffex_ip}/sj/hqsj/rtj/{day.strftime('%Y%m/%d')}/index.xml?id=7") as response:
301301
rst = await response.text()
302302
max_conn_cffex.release()
303303
tree = ET.fromstring(rst)
@@ -693,7 +693,7 @@ async def get_contracts_argument(day: datetime.datetime = None) -> bool:
693693
async with aiohttp.ClientSession() as session:
694694
# 上期所
695695
async with session.get(
696-
f'http://{shfe_ip}/data/instrument/ContractDailyTradeArgument{day_str}.dat') as response:
696+
f'http://{shfe_ip}/data/busiparamdata/future/ContractDailyTradeArgument{day_str}.dat') as response:
697697
rst = await response.read()
698698
rst_json = json.loads(rst)
699699
for inst_data in rst_json['ContractDailyTradeArgument']:

0 commit comments

Comments
 (0)