当前位置:网站首页>Figure seamless database integration tushare interface
Figure seamless database integration tushare interface
2022-06-11 07:49:00 【Ma Chao's blog】
Figure seamless database integration Tushare Interface
Here’s the table of contents:
Figure seamless database integration Tushare Interface
Use of third parties API, Help us quickly integrate data , Build the knowledge map data required for business analysis . This article mainly introduces how to
Tushare HTTPInterface to graph database , And use Cypher Build a map of knowledge .
Before we start Integration , Please make sure that your map database has
APOCComponents , And guarantee thatapoc.load.jsonParamsThe process can be used normally .APOC It also supportsJSON Path, That is to search in a specific mode JSON Data items in the document and return their contents , The concept is similar to that applied to XML Of XPath And apply to HTML Of jQuery. You can view more usage methods Neo4j An article by Dr. Yu, a community technology expert Neo4j Figure database advanced application series / Server extension guide APOC(5.5) - Import JSON data .
One 、Tushare Introduce
Tushare It's a free one 、 Open source python Financial data interface package . It is mainly used to collect financial data such as stocks from data 、 The process from cleaning and processing to data storage , Be able to provide financial analysts with quick 、 Clean and tidy 、 And a variety of easy to analyze data , Greatly reduce their workload in data acquisition , Make them more focused on the research and implementation of strategies and models .

Two 、 Integrate Tushare Interface
Before starting integration, make sure you have a Tushare Access account for .
Find... In the installation directory of the diagram database conf Folder , And in neo4j.conf In the file Tushare HTTP API Of URL Define an alias , Add a new line of configuration . After modifying the configuration , Restart the database service .
apoc.json.tushare.url=http://api.tushare.pro
3、 ... and 、 Use interface data
Now we can write Cypher Code can be easily accessed from Tushare Got the data . Next, I will demonstrate a case of the construction of shenwancheng's stock sharing map . Please pay attention to the use of Cypher Please set private when scripting token.
The following code first calls from... Through a batch loop stock_basic Interface to get the stock code , Then use the stock code to obtain the time series data of shenwancheng shares . Each stock code calls index_member Before the interface , It is set to perform four million addition operations to indicate the delay 1~2 second , The purpose of this operation is to ensure that HTTP Do not exceed the interface frequency limit when calling interfaces .
stock_basic Interface

index_member Interface

// Cycle through all stock codes
WITH RANGE(1,10) AS list,1000 AS limit
UNWIND list AS num
WITH num*limit AS offset,limit
// Get stock code in batches
WITH
'{"api_name":"stock_basic","token":"xxxxxxxxxxx","params":{"limit":"'+limit+'","offset":"'+offset+'"},"fields":"ts_code"}' AS payload
CALL apoc.load.jsonParams(
'tushare',
NULL,
payload,
NULL,
{}) yield value
WITH value.data.has_more AS has_more,value.data.items AS stocks
WHERE has_more
// Obtain Shenwan ingredient data
WITH has_more,stocks
UNWIND stocks AS stock
WITH stock
// Delayed execution 【HTTP API There is a limit on the frequency of calls , Let the function perform four million additions , It takes about 1~2 second 】
WITH RANGE(1,2000) AS l,stock UNWIND l AS a UNWIND l AS b WITH SUM(a+b) AS delay,stock
WITH
'{"api_name":"index_member","token":"xxxxxxxxxxx","params":{"ts_code":"'+stock[0]+'"},"fields":"index_code,index_name,con_code,con_name,in_date,out_date,is_new"}' AS payload
CALL apoc.load.jsonParams(
'tushare',
NULL,
payload,
NULL,
{}) yield value
WITH value.data.items AS items
// Build the component stock map of Shenwan industry
UNWIND items AS item
WITH item
MERGE (stk: Stocks {code:item[2]}) SET stk+={name:item[3]+'('+item[2]+')'}
MERGE (hy: Shenwan industry {code:item[0]}) SET hy+={name:item[1]+'('+item[0]+')'}
CREATE (stk)-[r: Belong to ]->(hy) SET r+={in_date:item[4],out_date:item[5],is_new:item[6]}

边栏推荐
- 20200802 T3 I always like [generating function exclusion, Lagrangian inversion]
- After 4 years of naked resignation from the test, the test post of 15K interview was rubbed on the ground, and the result made me collapse and cry
- 【AtCoder2304】Cleaning
- [software testing] 90% of the interviewers have been brushed out of such resumes
- Deux diplômés, la Banque a externalisé le travail d'essai pendant plus de quatre mois. Parler de vrais sentiments...
- Data visualization and Matplotlib
- The solution of "no startup device" after running Bochs
- 排序——归并排序
- C language - growth diary-04- preliminary exploration of local variables (local variables)
- 【CodeForces908H】New Year and Boolean Bridges (FWT)
猜你喜欢

Storage of floating point in memory

You got 8K in the 3-year function test, but you were actually pretending to work hard

二本畢業,銀行外包測試工作 4 個月有餘。聊聊一些真實感受 ...

forEach 中 return 和 for 中 break
![Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]](/img/f0/9d4609a53f398636b8062c625f7d3c.jpg)
Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]

Import on CSDN MD file

二本毕业,银行外包测试工作 4 个月有余。聊聊一些真实感受 ...

QT custom control library creation

【AtCoder1980】Mysterious Light(数学模拟)

C language - Growth Diary -02- function
随机推荐
Simple configuration of vscade
Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)
Wc2020 course selection
Note: JDBC
Use of wordcloud
Zero foundation self-study SQL course | outer join external connection
[IOT] intelligent hardware: how to obtain the WiFi signal strength of hardware products
排序——选择排序
Semiconductor memory classification
20200810 T2 dispatch money
[atcoder2376] black and white tree (game)
C language - Growth Diary -02- function
[untitled] Weng_ C lesson 1
Remote office experience sharing | community essay solicitation
C language three chess games
multi-sig SC
TiDB Cloud 上线 Google Cloud Marketplace,以全新一栈式实时 HTAP 数据库赋能全球开发者
Euler's theorem and its extension (with proof)
20200802 T3 I always like [generating function exclusion, Lagrangian inversion]
Using Tkinter to realize guessing numbers game