Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bonfida/agnostic-candles
Fetch and serve tradingview candles for any AOB and Pyth markets
https://github.com/bonfida/agnostic-candles
actix-web pyth solana tradingview
Last synced: 3 months ago
JSON representation
Fetch and serve tradingview candles for any AOB and Pyth markets
- Host: GitHub
- URL: https://github.com/bonfida/agnostic-candles
- Owner: Bonfida
- License: mit
- Created: 2022-04-22T11:17:42.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-07T09:40:40.000Z (over 2 years ago)
- Last Synced: 2024-07-30T20:16:24.984Z (6 months ago)
- Topics: actix-web, pyth, solana, tradingview
- Language: Rust
- Homepage:
- Size: 51.8 KB
- Stars: 11
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Agnostic candles
Table of contents
1. [Timescaledb](#timescaledb)
2. [Configuration](#configuration)
3. [Worker](#worker)
4. [Server](#server)
5. [Deployment](#deployment)Tradingview documentation can be found [here](https://github.com/tradingview/charting_library/wiki/UDF) this is a private repository, you must ask Tradingview to get access to it.
Timescaledb
This repository uses TimescaleDB to store candles. Full documentation can be found on their [website](https://www.timescale.com/)
Configuration
Markets should be passed in a JSON file as follow
| address | name | isPyth | baseDecimals | quoteDecimals | min_mov | price_scale |
| ------------------------------- | ------------------ | -------------------------- | ----------------------------------- | ------------------------------------ | -------------------- | ----------------------- |
| string | string | bool | u8 | u8 | u8 | u16 |
| Pyth feed or AOB market address | Name of the market | `true` if this a Pyth feed | Base token decimals (for Pyth only) | Quote token decimals (for Pyth only) | Min move (cf TV doc) | Price scale (cf TV doc) |`min_mov` and `price_scale` are parameters required by the Tradingview specification, see the exact definition on [Tradingview documentation](https://github.com/tradingview/charting_library/wiki/UDF)
- `min_mov = 1` is equivalent to a tick size of 0.01
- `price_scale = 100` is equivalent to 1.01For instance
```json
[
{
"address": "ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF",
"name": "FIDA-USDC-PYTH",
"isPyth": true,
"baseDecimals": 6,
"quoteDecimals": 6,
"minMov": 1,
"priceScale": 100
}
]
```Worker
The worker directory contains the program that fetches price information from the blockchain and stores it in the database.
It takes the following parameters in input:
```
cargo run markets_json_path rpc refresh_period
```- `markets_json_path` is the path to your JSON file that contains the markets you want to fetch
- `rpc` The URL of your Solana RPC endpoint
- `refresh_period` interval at which candles are fetched (in ms)So for instance
```
cargo run ./markets.json https://solana-api.projectserum.com 10000
```The worker handles Pyth and AOB markets in separate threads. This program uses `getMultipleAccountInfo` RPC requests to optimize the number of RPC calls. However, certain RPC nodes have limits to how many accounts can be passed in 1 request (usually 100) this is why the array of accounts are split in chunks of `MAX_ACCOUNT_CHUNK` and spawned in different threads.
For AOB markets, bids and asks account addresses are being fetched at the start of the program and are cached for more efficient polling.
Server
The server uses [actix web]() and is served by default on port `8080` .
It takes the following parameters in input:
```
cargo run markets_json_path user password host port dbname
```For instance
```
cargo run ./market.json my_user my_password 127.0.0.1 5432 my_db
```it has the following endpoints required by the Tradingview [specification](https://github.com/tradingview/charting_library/wiki/UDF)
### Config
**Request:**
`GET /tradingview/config`
It exposes the tradingview configuration of your server
If you want to change the available resolutions of your server you will have to modify this configuration**Response:**
```json
{
"supported_resolutions": [
"1",
"3",
"5",
"15",
"30",
"60",
"120",
"240",
"360",
"480",
"720",
"960",
"D"
],
"supports_group_request": false,
"supports_marks": false,
"supports_search": true,
"supports_timescale_marks": false
}
```### Symbols
**Request:**
`GET /tradingview/symbols?symbol={symbol}`
Serve information for a requested symbol
**Response:**
```json
{
"name": "FIDA-USDC-PYTH",
"ticker": "FIDA-USDC-PYTH",
"description": "FIDA-USDC-PYTH",
"type": "Spot",
"session": "24x7",
"exchange": "Bonfida",
"listed_exchange": "Bonfida",
"timezone": "Etc/UTC",
"has_intraday": true,
"supported_resolutions": [
"1",
"3",
"5",
"15",
"30",
"60",
"120",
"240",
"360",
"480",
"720",
"960",
"D"
],
"minmov": 1.0,
"pricescale": 100.0
}
```### Search
`GET /tradingview/search?query={query}&search_type={search_type}&exchange={exchange}&limit={limit}`
Can be used to search existing market
**Response:**
```json
[
{
"symbol": "FIDA-USDC-PYTH",
"full_name": "FIDA-USDC-PYTH",
"description": "Name:FIDA-USDC-PYTH - Address: ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF",
"exchange": "Bonfida",
"ticker": "FIDA-USDC-PYTH",
"type": "Spot"
}
]
```### Time
**Request:**
`GET /tradingview/time`
Returns the current unix timestamp (in seconds!) of the server
**Response:**
```json
1651188181
```### History
**Request:**
`GET /tradingview/history?symbol={symbol}&from={from}&to={to}&resolution={resolution}`
Returns historical candles for a given symbol
**Response:**
```json
{
"s": "ok",
"time": [1651189320, 1651189380],
"close": [1.2090027797967196, 1.2083083698526025],
"open": [1.2090027797967196, 1.208549999864772],
"high": [1.2090027797967196, 1.208549999864772],
"low": [1.2090027797967196, 1.208055029856041],
"volume": [0, 0]
}
```### Pairs
`GET /tradingview/pairs`
This endpoint returns all pairs available on the server (not required by Tradingview)
Deployment
This repository can be deployed using docker compose (recommended) or natively.