|
| 1 | +# Sablier Price Data |
| 2 | + |
| 3 | +Centralized repository for cryptocurrency and forex exchange rate data used across Sablier projects. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This repository serves as a single source of truth for price data shared between multiple Sablier repositories: |
| 8 | + |
| 9 | +- **Indexers** ([sablier-labs/indexers](https://github.com/sablier-labs/indexers)) - Real-time blockchain data indexing |
| 10 | +- **Accounting** ([sablier-labs/business](https://github.com/sablier-labs/business)) - Financial reporting and |
| 11 | + accounting |
| 12 | + |
| 13 | +By centralizing the data here, we avoid duplication and ensure consistency across projects. |
| 14 | + |
| 15 | +## Data Sources |
| 16 | + |
| 17 | +All price data is sourced from industry-standard APIs: |
| 18 | + |
| 19 | +- **Cryptocurrency Prices**: [CoinGecko API](https://www.coingecko.com/api) - Daily historical prices in USD |
| 20 | +- **Forex Exchange Rates**: [CurrencyFreaks API](https://currencyfreaks.com/) - Daily GBP/USD exchange rates |
| 21 | + |
| 22 | +## Data Structure |
| 23 | + |
| 24 | +Price data is organized in `data/crypto/` (cryptocurrency prices in USD) and `data/forex/` (foreign exchange rates). |
| 25 | + |
| 26 | +### TSV Format |
| 27 | + |
| 28 | +All files use tab-separated values (TSV) format with the following structure: |
| 29 | + |
| 30 | +```tsv |
| 31 | +id output |
| 32 | +"2025-02-01" 3296.390634843652 |
| 33 | +"2025-02-02" 3125.0386801320924 |
| 34 | +``` |
| 35 | + |
| 36 | +We use this data structure to make it easier to use the files in our |
| 37 | +[Envio indexers](https://github.com/sablier-labs/indexers). |
| 38 | + |
| 39 | +**Columns:** |
| 40 | + |
| 41 | +- `id`: Date in ISO 8601 format (`YYYY-MM-DD`), wrapped in double quotes |
| 42 | +- `output`: USD price as a decimal number (high precision) |
| 43 | + |
| 44 | +**Notes:** |
| 45 | + |
| 46 | +- Dates are in UTC timezone |
| 47 | +- Dates are sorted chronologically |
| 48 | +- No duplicate dates within a file |
| 49 | +- Prices are daily closing prices (00:00 UTC) |
| 50 | + |
| 51 | +## Installation |
| 52 | + |
| 53 | +Install the package via npm: |
| 54 | + |
| 55 | +```bash |
| 56 | +npm install @sablier/price-data |
| 57 | +``` |
| 58 | + |
| 59 | +Or using Bun: |
| 60 | + |
| 61 | +```bash |
| 62 | +bun add @sablier/price-data |
| 63 | +``` |
| 64 | + |
| 65 | +## Usage |
| 66 | + |
| 67 | +### Package Import |
| 68 | + |
| 69 | +Once installed, you can access the TSV data files from `node_modules/@sablier/price-data/data/`: |
| 70 | + |
| 71 | +```typescript |
| 72 | +import { readFileSync } from "node:fs"; |
| 73 | +import { join } from "node:path"; |
| 74 | + |
| 75 | +// Read ETH prices |
| 76 | +const dataPath = join(process.cwd(), "node_modules", "@sablier/price-data", "data/crypto/ETH_USD.tsv"); |
| 77 | +const ethPrices = readFileSync(dataPath, "utf-8"); |
| 78 | + |
| 79 | +// Parse TSV (skip header) |
| 80 | +const lines = ethPrices.split("\n").slice(1); |
| 81 | +const prices = lines.map((line) => { |
| 82 | + const [dateQuoted, price] = line.split("\t"); |
| 83 | + return { |
| 84 | + date: dateQuoted.replace(/"/g, ""), // Remove quotes |
| 85 | + price: parseFloat(price), |
| 86 | + }; |
| 87 | +}); |
| 88 | +``` |
| 89 | + |
| 90 | +### Direct File Access |
| 91 | + |
| 92 | +Alternatively, you can read the TSV files directly from this repository without installing the package. |
| 93 | + |
| 94 | +**Example: curl:** |
| 95 | + |
| 96 | +```bash |
| 97 | +curl -s https://raw.githubusercontent.com/sablier-labs/price-data/main/data/crypto/ETH_USD.tsv | head -n 10 |
| 98 | +``` |
| 99 | + |
| 100 | +**Example (fetch with Node.js):** |
| 101 | + |
| 102 | +```typescript |
| 103 | +const response = await fetch("https://raw.githubusercontent.com/sablier-labs/price-data/main/data/crypto/ETH_USD.tsv"); |
| 104 | +const ethPrices = await response.text(); |
| 105 | + |
| 106 | +// Parse TSV (skip header) |
| 107 | +const lines = ethPrices.split("\n").slice(1); |
| 108 | +const prices = lines.map((line) => { |
| 109 | + const [dateQuoted, price] = line.split("\t"); |
| 110 | + return { |
| 111 | + date: dateQuoted.replace(/"/g, ""), // Remove quotes |
| 112 | + price: parseFloat(price), |
| 113 | + }; |
| 114 | +}); |
| 115 | +``` |
| 116 | + |
| 117 | +### Git Submodule |
| 118 | + |
| 119 | +For projects that need version-locked data, add this repository as a Git submodule: |
| 120 | + |
| 121 | +```bash |
| 122 | +git submodule add https://github.com/sablier-labs/price-data.git |
| 123 | +``` |
| 124 | + |
| 125 | +## Updating Data |
| 126 | + |
| 127 | +TODO |
0 commit comments