|
| 1 | +--- |
| 2 | +section: dataStreams |
| 3 | +date: Last Modified |
| 4 | +title: "Data Streams Price API" |
| 5 | +metadata: |
| 6 | + title: "Data Streams Price API Reference | Chainlink Documentation" |
| 7 | + description: "Reference for the Chainlink Data Streams Price API. Learn how to authenticate, list available symbols, query historical candlestick (OHLC) data, and stream live price updates over HTTP." |
| 8 | + keywords: ["Candlestick API", "Price API", "OHLC", "HTTP Rest API", "API Client", "Trading View API"] |
| 9 | +--- |
| 10 | + |
| 11 | +import DataStreams from "@features/data-streams/common/DataStreams.astro" |
| 12 | + |
| 13 | +<DataStreams section="dsNotes" /> |
| 14 | + |
| 15 | +PriceAPI is designed and implemented to satisfy the [TradingView implementation spec](https://www.tradingview.com/broker-api-docs/rest-api-spec/#tag/Data-Integration), the industry standard to share aggregated trading data. |
| 16 | + |
| 17 | +Alignment to the TradingView spec allows for trading view integration and direct customer access to prices without resorting to consuming and decoding reports for non-transactional use cases, like dashboards, analytics platforms, portfolio trackers, research tools, and more. |
| 18 | + |
| 19 | +{/* TODO: specify mainnet and testnet domains */} |
| 20 | + |
| 21 | +## Domains |
| 22 | + |
| 23 | +| Description | Testnet URL | Mainnet URL | |
| 24 | +| ------------------ | ----------- | ----------- | |
| 25 | +| Price API endpoint | TBD | TBD | |
| 26 | + |
| 27 | +## API Endpoints |
| 28 | + |
| 29 | +### Authorize and get token |
| 30 | + |
| 31 | +##### Endpoint |
| 32 | + |
| 33 | +**`/api/v1/authorize`** |
| 34 | + |
| 35 | +| Type | Description | Parameter(s) | |
| 36 | +| :-------- | :------------------------------------------------ | :------------------------------------------------------------------------------ | |
| 37 | +| HTTP POST | Authorizes a user and returns a JWT access token. | <ul><li>`login`: The user ID.</li><li>`password`: The user's API key.</li></ul> | |
| 38 | + |
| 39 | +##### Sample request |
| 40 | + |
| 41 | +```bash |
| 42 | +curl -X POST \ |
| 43 | + -H "Content-Type: application/x-www-form-urlencoded" \ |
| 44 | + -d "login={YOUR_USER_ID}&password={YOUR_API_KEY}" \ |
| 45 | + [API_BASE]/api/v1/authorize |
| 46 | +``` |
| 47 | + |
| 48 | +##### Sample response |
| 49 | + |
| 50 | +```json |
| 51 | +{ |
| 52 | + "d": { |
| 53 | + "access_token": "[ACCESS_TOKEN]", // JWT token for subsequent requests |
| 54 | + "expiration": 1747203979 |
| 55 | + }, |
| 56 | + "s": "ok" |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +### Get list of supported symbols |
| 61 | + |
| 62 | +##### Endpoint |
| 63 | + |
| 64 | +**`/api/v1/symbol_info`** |
| 65 | + |
| 66 | +| Type | Description | Parameter(s) | |
| 67 | +| :------- | :------------------------------------------------------- | :----------------------------------------------------------------------------------------------- | |
| 68 | +| HTTP GET | Gets a list of all supported symbols on the environment. | <ul><li>`group` (optional): Filter symbols by group. Currently only supports "crypto".</li></ul> | |
| 69 | + |
| 70 | +##### Sample request |
| 71 | + |
| 72 | +```bash |
| 73 | +curl -X GET \ |
| 74 | + -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \ |
| 75 | + [API_BASE]/api/v1/symbol_info |
| 76 | +``` |
| 77 | + |
| 78 | +##### Sample response |
| 79 | + |
| 80 | +```json |
| 81 | +{ |
| 82 | + "s": "ok", |
| 83 | + "symbol": ["ETHUSD", "BTCUSD"], |
| 84 | + "currency": ["USD", "USD"], |
| 85 | + "base-currency": ["ETH", "BTC"] |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### Get candlestick data (column format) |
| 90 | + |
| 91 | +##### Endpoint |
| 92 | + |
| 93 | +**`/api/v1/history`** |
| 94 | + |
| 95 | +| Type | Description | Parameter(s) | |
| 96 | +| :------- | :-------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 97 | +| HTTP GET | Gets candlestick data in column format. | <ul><li>`symbol`: The symbol to query.</li><li>`resolution`: Resolution of the data (required but not used, use "1m").</li><li>`from`: Unix timestamp of the leftmost required bar (inclusive).</li><li>`to`: Unix timestamp of the rightmost required bar (inclusive).</li></ul> | |
| 98 | + |
| 99 | +**Note**: The resolution of the data is based on the size of the time window: |
| 100 | + |
| 101 | +| Max time window size | Resolution of candles | |
| 102 | +| :------------------- | :-------------------- | |
| 103 | +| \<= 24 hours | 1 minute | |
| 104 | +| \<= 5 days | 5 minutes | |
| 105 | +| \<= 30 days | 30 minutes | |
| 106 | +| \<= 90 days | 1 hour | |
| 107 | +| \<= 6 months | 2 hours | |
| 108 | +| > 6 months | 1 day | |
| 109 | + |
| 110 | +##### Sample request |
| 111 | + |
| 112 | +```bash |
| 113 | +curl -X GET \ |
| 114 | + -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \ |
| 115 | + "[API_BASE]/api/v1/history?symbol=ETHUSD&resolution=1m&from=1746072068&to=1746158468" |
| 116 | +``` |
| 117 | + |
| 118 | +##### Sample response |
| 119 | + |
| 120 | +```json |
| 121 | +{ |
| 122 | + "s": "ok", |
| 123 | + "t": [1746158460, 1746158400, 1746158340], |
| 124 | + "c": [1.84685e21, 1.848515087189567e21, 1.8490380305e21, 1.8481266e21], |
| 125 | + "o": [1.8483674e21, 1.848602513e21, 1.8481267e21], |
| 126 | + "h": [1.8498753129131415e21, 1.848875387e21, 1.8490380305e21], |
| 127 | + "l": [1.8468008021426886e21, 1.848243519e21, 1.8475677870725296e21], |
| 128 | + "v": [] |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +### Get candlestick data (row format) |
| 133 | + |
| 134 | +##### Endpoint |
| 135 | + |
| 136 | +**`/api/v1/history/rows`** |
| 137 | + |
| 138 | +| Type | Description | Parameter(s) | |
| 139 | +| :------- | :----------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 140 | +| HTTP GET | Gets candlestick data in row format. | <ul><li>`symbol`: The symbol to query.</li><li>`resolution`: Resolution of the data (required but not used, use "1m").</li><li>`from`: Unix timestamp of the leftmost required bar (inclusive).</li><li>`to`: Unix timestamp of the rightmost required bar (inclusive).</li></ul> | |
| 141 | + |
| 142 | +##### Sample request |
| 143 | + |
| 144 | +```bash |
| 145 | +curl -X GET \ |
| 146 | + -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \ |
| 147 | + "[API_BASE]/api/v1/history/rows?symbol=ETHUSD&resolution=1m&from=1746072068&to=1746158468" |
| 148 | +``` |
| 149 | + |
| 150 | +##### Sample response |
| 151 | + |
| 152 | +```json |
| 153 | +{ |
| 154 | + "s": "ok", |
| 155 | + "candles": [ |
| 156 | + [1746158460, 1.8483674e21, 1.8498753129131415e21, 1.8468008021426886e21, 1.84685e21, 0], |
| 157 | + [1746158400, 1.848602513e21, 1.848875387e21, 1.848243519e21, 1.848515087189567e21, 0], |
| 158 | + [1746158340, 1.8481267e21, 1.8490380305e21, 1.8475677870725296e21, 1.8490380305e21, 0] |
| 159 | + ] |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +### Get streaming price updates |
| 164 | + |
| 165 | +##### Endpoint |
| 166 | + |
| 167 | +**`/api/v1/streaming`** |
| 168 | + |
| 169 | +| Type | Description | Parameter(s) | |
| 170 | +| :------- | :-------------------------------------------------------- | :----------------------------------------------------------------------------------------------- | |
| 171 | +| HTTP GET | Gets streaming price updates using HTTP chunked encoding. | <ul><li>`symbol` or `feedId`: A comma-separated list of symbols or feed IDs to stream.</li></ul> | |
| 172 | + |
| 173 | +##### Sample request |
| 174 | + |
| 175 | +```bash |
| 176 | +curl -X GET \ |
| 177 | + -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \ |
| 178 | + -H "Connection: keep-alive" \ |
| 179 | + "[API_BASE]/api/v1/streaming?symbol=ETHUSD,BTCUSD" |
| 180 | +``` |
| 181 | + |
| 182 | +##### Sample response (Streaming) |
| 183 | + |
| 184 | +A stream of JSON objects. |
| 185 | + |
| 186 | +**Trade Response:** |
| 187 | + |
| 188 | +```json |
| 189 | +{ |
| 190 | + "f": "t", |
| 191 | + "i": "ETHUSD", |
| 192 | + "fid": "[FEED_ID]", // Hex encoded feed ID |
| 193 | + "p": 2.68312e21, |
| 194 | + "t": 1748525526, |
| 195 | + "s": 1 |
| 196 | +} |
| 197 | +``` |
| 198 | + |
| 199 | +**Heartbeat (sent every 5 seconds):** |
| 200 | + |
| 201 | +```json |
| 202 | +{ "heartbeat": 1748525528 } |
| 203 | +``` |
| 204 | + |
| 205 | +--- |
| 206 | + |
| 207 | +## Error Response Codes |
| 208 | + |
| 209 | +| Status Code | Description | |
| 210 | +| :---------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 211 | +| **400 Bad Request** | This error is triggered when: <ul><li>Required parameters are missing or malformed.</li><li>Invalid parameter values are provided.</li></ul> | |
| 212 | +| **401 Unauthorized** | This error is triggered when: <ul><li>The authorization header is missing or invalid.</li><li>The access token is expired or malformed.</li><li>Invalid credentials were provided during authorization.</li></ul> | |
| 213 | +| **404 Not Found** | This error is triggered when: <ul><li>The requested symbol is not supported.</li><li>A user is not found during authorization.</li></ul> | |
| 214 | +| **500 Internal Server** | Indicates an unexpected condition was encountered by the server, preventing it from fulfilling the request. This error typically points to issues on the server side. | |
0 commit comments