logo

Welcome to Quantapi!


How to Use the Data API?

1. Sign Up to get a trial account.

2. Go to My Account and copy the token which is a long string of characters.

3. Check the Assets page to know the code of the assets

4. There are 4-5 parameters for an API Call:
asset, token, d (which means duration), f (which means format), q(which means stock code, now available only to hkex asset)
e.g. asset=gold, token=123456789xyz, d=1y (eg. 30d=30 days, 4w=4 week, 2m=2 months, 1y=1 year, etc.), f=csv (json or csv)
Actual API call (use code at 6.):
https://quantapi.co/api/gold/123456789xyz/?d=1m&f=csv
For stocks (use code at 7.):
e.g. Hong Kong Stocks (code: hkex):
https://quantapi.co/api/hkex/123456789xyz/?d=1m&f=csv&q=3988
e.g. Shanghai Stocks (code: shex):
https://quantapi.co/api/shex/123456789xyz/?d=1m&f=csv&q=600021
e.g. Shenzhen Stocks (code: szex):
https://quantapi.co/api/szex/123456789xyz/?d=1m&f=csv&q=000001

* The demo key (123456789xyz) is for demo purpose and only display asset=gold data. Please Sign Up your account to get full access.

5. There you go. Click the link or Copy the link to use it in your program to get the data.

6. Below is python code snippets which you can copy and paste to use.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#import required packages
import pandas as pd

#get data from quantapi json format
def get_quantapi(symbol, token, duration, format):
	query = 'https://quantapi.co/api/' + symbol + '/' + token + '/?d=' + duration + '&f=' + format
	df = pd.read_json(query)
	df = df[['date', 'open', 'high', 'low', 'close']]
	df = df.sort_values('date', ascending = True)
	print(df)
	return df
    
#sample code to get gold price
symbol = 'gold'
token = '123456789xyz'
duration = '1m'
format = 'json'
df = get_quantapi(symbol, token, duration, format)

7. For hkex, shex, szex (OHLCV) stocks data, please use below code. Just change symbol='':

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#import required packages
import pandas as pd

#get data from quantapi json format
def get_quantapi(symbol, token, code, duration, format):
	query = 'https://quantapi.co/api/' + symbol + '/' + token + '/?d=' + duration + '&f=' + format + '&q=' + code
	df = pd.read_json(query)
	df = df[['date', 'open', 'high', 'low', 'close', 'volume']]
	df = df.sort_values('date', ascending = True)
	print(df)
	return df
    
#sample code to get hkex stock price
symbol = 'hkex'
token = 'You token here'
duration = '1m'
format = 'json'
code = '3988'
df = get_quantapi(symbol, token, code, duration, format)