Commit 5703c859 authored by wenwen.tang's avatar wenwen.tang 😕

适配新数据源

parent fca62352
......@@ -8,6 +8,7 @@ import requests
from py_jftech import component, filter_weekend, next_workday, get_config, format_date
from api import RoboReportor
from basic.sync import ths_token
from reports.dao import robo_benckmark as rb
config = get_config(__name__)
......@@ -18,7 +19,7 @@ class BenchmarkAlligamReportor(RoboReportor):
@property
def report_name(self) -> str:
return 'BENCHMARK_ALLIGAM'
return 'BENCHMARK_SPX'
@property
def module_name(self) -> str:
......@@ -26,42 +27,42 @@ class BenchmarkAlligamReportor(RoboReportor):
@property
def risk(self):
return 'alligam'
return 'SPX'
@property
def base_params(self):
return {
'subjectKeys': 879,
'size': 200,
'sourceType': 'BLOOMBERG'
'code': "SPX.GI",
}
def sync_benchmark(self, start_date=None):
url = "https://quantapi.51ifind.com/api/v1/cmd_history_quotation"
headers = {
"Content-Type": "application/json",
"access_token": ths_token(),
"ifindlang": "cn"
}
params = {
**self.base_params,
'page': 0
'codes': self.base_params['code'],
'indicators': 'close',
'startdate': format_date(start_date) if start_date else "2012-01-01",
'enddate': format_date(dt.today())
}
if start_date:
params['startDate'] = format_date(start_date)
while True:
response = requests.get(f'http://jdcprod.thiztech.com/api/datas/asset-value?{urlencode(params)}').json()
if not response['success']:
raise Exception(f'''request jdc alligam failed: {response['status']}''')
if response['body']['content']:
rb.batch_insert([{
'date': dt.fromtimestamp(x['date'] / 1000),
'module': self.module_name,
'risk': self.risk,
'nav': x['calibrateValue'],
'remarks': json.dumps({
'av': x['originValue'],
'div': x['dividend'] if 'dividend' in x else 0
}, ensure_ascii=False)
} for x in response['body']['content']])
if response['body']['last']:
break
else:
params = {**params, 'page': params['page'] + 1}
response = requests.post(url, json=params, headers=headers)
response = response.json()['tables']
if len(response) == 0 or response[0].get('time') is None or len(response[0]['time']) == 0:
return
rb.batch_insert([{
'date': time,
'module': self.module_name,
'risk': self.risk,
'nav': close,
'remarks': json.dumps({
'av': close,
'div': 0
}, ensure_ascii=False)
} for time,close in zip(response[0]['time'],response[0]['table']['close'])])
def load_report(self, max_date=dt.today(), min_date=None) -> List[dict]:
max_date = filter_weekend(max_date)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment