Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
R
robo-dividend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenwen.tang
robo-dividend
Commits
4ca198df
Commit
4ca198df
authored
Oct 25, 2023
by
wenwen.tang
😕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加彭博基金抓取逻辑
parent
cf5e4abe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
15 deletions
+26
-15
sync.py
basic/sync.py
+26
-15
No files found.
basic/sync.py
View file @
4ca198df
...
...
@@ -54,7 +54,7 @@ class JDCDataSync(DataSync, ABC):
while
True
:
url
=
self
.
build_urls
(
datum
=
datum
,
page
=
page
,
start_date
=
start_date
)
if
url
is
None
:
raise
Exception
(
f
'''request data {datum['id']} not exist!'''
)
break
response
=
requests
.
get
(
url
)
.
json
()
if
not
response
[
'success'
]:
raise
Exception
(
f
'''request indictor failed: {response['status']}'''
)
...
...
@@ -177,7 +177,7 @@ class IndexSync(JDCDataSync):
return
next_workday
(
last
[
'date'
])
if
last
else
self
.
start_date
def
build_urls
(
self
,
datum
,
start_date
,
page
=
0
)
->
str
:
return
f
'http://jdcprod.thiztech.com/api/datas/index-value?page={page}&size=200&sourceCode={quote(datum["bloombergTicker"])}&sourceType=BLOOMBERG&startDate={format_date(start_date)}'
return
f
'http
s
://jdcprod.thiztech.com/api/datas/index-value?page={page}&size=200&sourceCode={quote(datum["bloombergTicker"])}&sourceType=BLOOMBERG&startDate={format_date(start_date)}'
def
store_date
(
self
,
datumid
,
datas
:
List
[
dict
]):
save_datas
=
[{
...
...
@@ -211,7 +211,7 @@ class EcoSync(JDCDataSync):
return
next_workday
(
last
[
'date'
])
if
last
else
self
.
start_date
def
build_urls
(
self
,
datum
,
start_date
,
page
=
0
)
->
str
:
return
f
'http://jdcprod.thiztech.com/api/datas/eco-value?page={page}&size=200&sourceCode={quote(datum["bloombergTicker"])}&sourceType=BLOOMBERG&startDate={format_date(start_date)}'
return
f
'http
s
://jdcprod.thiztech.com/api/datas/eco-value?page={page}&size=200&sourceCode={quote(datum["bloombergTicker"])}&sourceType=BLOOMBERG&startDate={format_date(start_date)}'
def
store_date
(
self
,
datumid
,
datas
:
List
[
dict
]):
save_datas
=
[{
...
...
@@ -229,7 +229,7 @@ class FundNavSync(JDCDataSync):
def
__init__
(
self
):
super
(
FundNavSync
,
self
)
.
__init__
()
self
.
_
subject_keys
=
self
.
find_jdc_subject_key
()
self
.
_
jdc_querys
=
self
.
find_jdc_querys
()
@
property
def
datum_type
(
self
)
->
DatumType
:
...
...
@@ -240,20 +240,31 @@ class FundNavSync(JDCDataSync):
return
next_workday
(
last
[
'nav_date'
])
if
last
else
self
.
start_date
def
build_urls
(
self
,
datum
,
start_date
,
page
=
0
)
->
str
:
if
datum
[
'id'
]
not
in
self
.
_
subject_ke
ys
:
if
datum
[
'id'
]
not
in
self
.
_
jdc_quer
ys
:
return
None
key
=
self
.
_subject_keys
[
datum
[
'id'
]]
return
f
'http://jdcprod.thiztech.com/api/datas/asset-value?subjectKeys={key}&page={page}&size=200&sourceType=TW&startDate={format_date(start_date)}'
def
find_jdc_subject_key
(
self
):
funds
=
{
x
[
'isin'
]:
x
for
x
in
self
.
_datum
.
get_datums
(
type
=
DatumType
.
FUND
)}
response
=
requests
.
get
(
'http://jdcprod.thiztech.com/api/subject?busiField=TW&sourceType=TW&subjectType=FUND'
)
querys
=
self
.
_jdc_querys
[
datum
[
'id'
]]
query_str
=
'&'
.
join
([
f
'{x[0]}={quote(str(x[1]).encode())}'
for
x
in
querys
.
items
()])
return
f
'https://jdcprod.thiztech.com/api/datas/asset-value?page={page}&size=200&startDate={format_date(start_date)}&{query_str}'
def
find_jdc_querys
(
self
):
funds
=
self
.
_datum
.
get_datums
(
type
=
DatumType
.
FUND
,
exclude
=
False
)
urls
=
{
x
[
'id'
]:
{
'sourceCode'
:
x
[
'bloombergTicker'
],
'sourceType'
:
'BLOOMBERG'
}
for
x
in
funds
if
'ftTicker'
not
in
x
and
'bloombergTicker'
in
x
}
ft_tickers
=
{
x
[
'ftTicker'
]:
x
for
x
in
funds
if
'ftTicker'
in
x
}
response
=
requests
.
get
(
'https://jdcprod.thiztech.com/api/subject?busiField=TW&sourceType=TW&subjectType=FUND'
)
response
=
response
.
json
()
if
not
response
[
'success'
]:
raise
CollectError
(
f
'''find fund subject failed: {response['status']}'''
)
content
=
response
[
'body'
][
'content'
]
content
=
[
x
for
x
in
content
if
x
.
get
(
'isin'
)]
return
{
funds
[
x
[
'isin'
]][
'id'
]:
x
[
'key'
]
for
x
in
content
if
x
[
'isin'
]
in
funds
}
return
{
**
urls
,
**
{
ft_tickers
[
x
[
'fundId'
]][
'id'
]:
{
'subjectKeys'
:
x
[
'key'
],
'sourceType'
:
'TW'
}
for
x
in
response
[
'body'
][
'content'
]
if
x
[
'fundId'
]
in
ft_tickers
}}
def
store_date
(
self
,
datumid
,
datas
:
List
[
dict
]):
save_navs
=
[{
...
...
@@ -287,7 +298,7 @@ class ExrateSync(DataSync):
return
[
x
[
'ticker'
]
for
x
in
navs_config
[
'exrate'
]]
if
'exrate'
in
navs_config
else
[]
def
build_url
(
self
,
ticker
,
start_date
,
page
=
0
):
return
f
'http://jdcprod.thiztech.com/api/datas/exrate-value?page={page}&size=200&sourceCode={quote(ticker)}&sourceType=BLOOMBERG&startDate={format_date(start_date)}'
return
f
'http
s
://jdcprod.thiztech.com/api/datas/exrate-value?page={page}&size=200&sourceCode={quote(ticker)}&sourceType=BLOOMBERG&startDate={format_date(start_date)}'
def
do_sync
(
self
,
max_date
=
dt
.
today
()):
logger
.
info
(
f
'start sync datas for type[EXRATE]'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment