API Integration Steps

Note:

  1. You need client id, client secret and API key in order to access the APIs.
  2. This follows OAuth2.0 authorization flow.
  3. Access token expires in 1 day.

Steps 1: Get your access token from https://auth-api.hyblockcapital.com/oauth2/token

  1. Request type is POST
  2. Request path: '/'
  3. Send the below request body :

    grant_type: "client_credentials" //it is constant

    client_id: <your-client-id>

    client_secret: <your-client-secret>

  4. Send this request header:

    Content-Type: "application/x-www-form-urlencoded" //it is constant

Steps 2: Hit your API with url https://api1.hyblockcapital.com/v1

  1. Request type is GET
  2. Request path: '/bidAsk'
  3. send following data as query parameter:

    "coin": "BTC",

    "timeframe": "1m",

    "exchange": "Binance",

    "limit": 5

  4. send following request header:

    "Authorization": "Bearer <your-access-token>"

    "x-api-key": <your API Key>

Python Script

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 import requests client_id = <your client id> client_secret = <your client secret> api_key = <your API Key> grant_type = "client_credentials" #this is constant amazon_auth_url = 'https://auth-api.hyblockcapital.com/oauth2/token' auth_data = { "grant_type": grant_type, "client_id": client_id, "client_secret": client_secret, } def update_access_token(): auth_response = requests.post( amazon_auth_url, data=auth_data, headers={'Content-Type': "application/x-www-form-urlencoded"}) return auth_response.json() def get_data(path, base_url, query_params): auth_response_json = update_access_token() auth_token_header = { "Authorization": "Bearer %s" % auth_response_json["access_token"], "x-api-key": api_key } url = base_url + path response = requests.get(url, params=query_params, headers=auth_token_header) print(response.json()) return response.json() base_url = 'https://api1.hyblockcapital.com/v1' orderbook_path = '/bidAsk' query = { "timeframe": "1m", "coin": "BTC", "exchange": "Binance", "limit": 5 } get_data(orderbook_path, base_url, query)

Javascript (NodeJS) Script

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 const axios = require('axios') const client_id = <your client id> const client_secret = <your client secret> const api_key = <your api key> const grant_type = "client_credentials" //this is constant const amazon_auth_url = 'https://auth-api.hyblockcapital.com/oauth2/token' async function get_access_token() { const auth_data = { "grant_type": grant_type, "client_id": client_id, "client_secret": client_secret, } const response = await axios({ method: 'post', url: amazon_auth_url, data: auth_data, headers: { 'Content-Type': "application/x-www-form-urlencoded" } }) return response.data } const getData = async (path, base_url, queries) => { let auth_response_json = await get_access_token() const url = base_url + path const response = await axios({ method: "get", url: url, params: queries, headers: { "Authorization": `Bearer ${auth_response_json["access_token"]}`, "x-api-key": api_key } }) console.log(response.data) } const base_url = 'https://api1.hyblockcapital.com/v1' const orderbook_path = '/bidAsk' const query = { "coin": "BTC", "timeframe": "1m", "exchange": "Binance", "limit": 5 } getData(orderbook_path, base_url, query);