Skip to content

Commit 4c770c8

Browse files
committed
Add support for cryptocurrencies
1 parent 312f3c3 commit 4c770c8

File tree

11 files changed

+1398
-108
lines changed

11 files changed

+1398
-108
lines changed

.env-example

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,25 @@ METALS_DEV_API_KEY="your_api_key_here"
1010
# Update Interval (in seconds)
1111
# How often to fetch new exchange rates from Metals.dev API
1212
# Default: 60 (1 minute)
13-
UPDATE_INTERVAL=60 # 1 minute
13+
UPDATE_INTERVAL=60
14+
15+
# Enable or disable fetching prices from crypto exchanges
16+
USE_KRAKEN=true
17+
USE_BINANCE=true
18+
USE_GATEIO=true
19+
USE_KUCOIN=true
20+
USE_BINGX=true
21+
USE_BYBIT=true
22+
USE_CRYPTOCOM=true
23+
USE_BITFINEX=true
24+
25+
# How often to fetch cryptocurrency prices from enabled crypto exchanges (in seconds)
26+
# Default: 30 (30 seconds)
27+
CRYPTO_UPDATE_INTERVAL=30
28+
29+
# Cryptocurrencies to monitor (comma-separated list)
30+
# Example: BTC,ETH,SOL,ADA,XRP
31+
ENABLED_CRYPTOS=AAVE,ADA,ALGO,ARB,ATOM,AVAX,BCH,BNB,BTC,CELO,CRO,DASH,DOGE,DOT,EGLD,EOS,ETC,ETH,FIL,FLOW,GRT,HNT,ICP,IMX,INJ,IOTA,KAS,LINK,LTC,MINA,NANO,NEAR,NEO,POL,QTUM,RUNE,RVN,S,SEI,SOL,STX,THETA,TIA,TON,TRX,VET,WAVES,XLM,XMR,XRP,XTZ,ZEC,ZIL
1432

1533
# Logging Configuration
1634
# 0 = ERROR, 1 = WARN, 2 = AUDIT, 3 = INFO, 4 = HTTP, 5 = DEBUG, 6 = VERBOSE, 7 = SILLY

README.md

Lines changed: 140 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# RabbitForexAPI 🐰💱
22

3-
A high-performance foreign exchange (Forex) and precious metals API built with Bun that fetches real-time exchange rate and metal price data from metals.dev and serves it through a REST API.
3+
A high-performance foreign exchange (Forex), precious metals, and cryptocurrency API built with Bun that fetches real-time exchange rate data from multiple sources and serves it through a REST API.
44

55
## Features
66

77
- 🚀 Blazing Fast - Built with Bun for optimal performance
88
- 💱 Real-time Forex Data - Automatically updates exchange rates at configurable intervals
9+
- ₿ Cryptocurrency Support - Real-time crypto prices from multiple exchanges (Binance, Kraken, Gate, KuCoin, BingX, ByBit, Crypto.com, Bitfinex)
910
- 🌍 Multi-currency Support - Convert between 150+ currencies with accurate cross-rates
1011
- 🥇 Precious & Base Metals - Gold, Silver, Platinum, Palladium, Copper, Aluminum, Lead, Nickel, Zinc
1112
- 📊 Metals.dev Data - Reliable source for both currency exchange rates and metal prices
13+
- 🔄 Smart Price Aggregation - Combines multiple crypto exchanges for optimal pricing with outlier detection
1214
- 🐳 Docker Ready - Easy deployment with Docker and Docker Compose
1315
- 🏥 Health Checks - Built-in monitoring and health endpoints
1416
- 🔄 Auto-restart - Automatic recovery on failures
@@ -37,7 +39,26 @@ METALS_DEV_API_KEY="your_api_key_here"
3739
# Update Interval (in seconds)
3840
# How often to fetch new exchange rates from Metals.dev API
3941
# Default: 60 (1 minute)
40-
UPDATE_INTERVAL=60 # 1 minute
42+
UPDATE_INTERVAL=60
43+
44+
# Crypto Exchange Configuration
45+
# Enable or disable fetching prices from crypto exchanges
46+
USE_KRAKEN=true
47+
USE_BINANCE=true
48+
USE_GATEIO=true
49+
USE_KUCOIN=true
50+
USE_BINGX=true
51+
USE_BYBIT=true
52+
USE_CRYPTOCOM=true
53+
USE_BITFINEX=true
54+
55+
# How often to fetch cryptocurrency prices from enabled crypto exchanges (in seconds)
56+
# Default: 30 (30 seconds)
57+
CRYPTO_UPDATE_INTERVAL=30
58+
59+
# Cryptocurrencies to monitor (comma-separated list)
60+
# Example: BTC,ETH,SOL,ADA,XRP
61+
ENABLED_CRYPTOS=AAVE,ADA,ALGO,ARB,ATOM,AVAX,BCH,BNB,BTC,CELO,CRO,DASH,DOGE,DOT,EGLD,EOS,ETC,ETH,FIL,FLOW,GRT,HNT,ICP,IMX,INJ,IOTA,KAS,LINK,LTC,MINA,NANO,NEAR,NEO,POL,QTUM,RUNE,RVN,S,SEI,SOL,STX,THETA,TIA,TON,TRX,VET,WAVES,XLM,XMR,XRP,XTZ,ZEC,ZIL
4162

4263
# Logging Configuration
4364
# 0 = ERROR, 1 = WARN, 2 = AUDIT, 3 = INFO, 4 = HTTP, 5 = DEBUG, 6 = VERBOSE, 7 = SILLY
@@ -67,6 +88,8 @@ docker run -d \
6788
-p 3000:3000 \
6889
-e METALS_DEV_API_KEY="your_api_key_here" \
6990
-e UPDATE_INTERVAL=60 \
91+
-e CRYPTO_UPDATE_INTERVAL=30 \
92+
-e ENABLED_CRYPTOS="BTC,ETH,SOL,ADA,XRP" \
7093
-e LOGGER_LEVEL=3 \
7194
-e PROXY=direct \
7295
rabbitcompany/rabbitforexapi:latest
@@ -81,12 +104,13 @@ Health Check and Statistics
81104
```json
82105
{
83106
"program": "RabbitForexAPI",
84-
"version": "2.0.0",
107+
"version": "3.0.0",
85108
"sourceCode": "https://github.com/Rabbit-Company/RabbitForexAPI",
86109
"monitorStats": {
87110
"currencyCount": 174,
88111
"metalCount": 9,
89-
"totalAssetCount": 183,
112+
"cryptoCount": 2885,
113+
"totalAssetCount": 3068,
90114
"updateInterval": "60s"
91115
},
92116
"httpStats": {
@@ -172,17 +196,87 @@ Example: `/v1/rates/EUR` - Euro as base
172196
}
173197
```
174198

199+
### GET `/v1/crypto/rates`
200+
201+
Get all cryptocurrency rates with USD as base (default)
202+
203+
```json
204+
{
205+
"base": "USD",
206+
"rates": {
207+
"BTC": 0.0000098082,
208+
"ETH": 0.00029232,
209+
"SOL": 0.0062949,
210+
"ADA": 1.7876,
211+
"XRP": 0.4379,
212+
"DOT": 0.32144,
213+
"...": "..."
214+
},
215+
"timestamps": {
216+
"currency": "2025-11-07T07:06:10.544Z",
217+
"metal": "2025-11-07T07:06:07.016Z",
218+
"crypto": "2025-11-07T07:06:05.123Z"
219+
}
220+
}
221+
```
222+
223+
### GET `/v1/crypto/rates/:asset`
224+
225+
Get all cryptocurrency rates with specified asset as base (currency, metal, or cryptocurrency)
226+
227+
Example: `/v1/crypto/rates/BTC` - Bitcoin as base
228+
229+
```json
230+
{
231+
"base": "BTC",
232+
"rates": {
233+
"USD": 101565.0019,
234+
"EUR": 87787.71,
235+
"...": "..."
236+
},
237+
"timestamps": {
238+
"currency": "2025-11-07T07:06:10.544Z",
239+
"metal": "2025-11-07T07:06:07.016Z",
240+
"crypto": "2025-11-07T07:06:05.123Z"
241+
}
242+
}
243+
```
244+
245+
Example: `/v1/crypto/rates/EUR` - Euro as base for crypto rates
246+
247+
```json
248+
{
249+
"base": "EUR",
250+
"rates": {
251+
"BTC": 0.000011571,
252+
"ETH": 0.00034673,
253+
"SOL": 0.0074452,
254+
"ADA": 2.1322,
255+
"XRP": 0.52006,
256+
"DOT": 0.38543,
257+
"...": "..."
258+
},
259+
"timestamps": {
260+
"currency": "2025-11-07T07:06:10.544Z",
261+
"metal": "2025-11-07T07:06:07.016Z",
262+
"crypto": "2025-11-07T07:06:05.123Z"
263+
}
264+
}
265+
```
266+
175267
### GET `/v1/assets`
176268

177-
Get lists of all supported currencies and metals
269+
Get lists of all supported currencies, metals and cryptocurrencies
178270

179271
```json
180272
{
181273
"currencies": ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "EUR", "USD", "GBP", "JPY", "CHF", "CAD", "..."],
182274
"metals": ["ALUMINUM", "COPPER", "GOLD", "LEAD", "NICKEL", "PALLADIUM", "PLATINUM", "SILVER", "ZINC"],
275+
"cryptocurrencies": ["BTC", "ETH", "SOL", "ADA", "XRP", "DOT", "DOGE", "AVAX", "LINK", "..."],
183276
"timestamps": {
277+
"currency": "2025-11-07T07:06:10.544Z",
184278
"metal": "2025-11-07T07:06:07.016Z",
185-
"currency": "2025-11-07T07:06:10.544Z"
279+
"crypto": "2025-11-07T07:06:05.123Z"
186280
}
187281
}
188282
```
@@ -207,21 +301,36 @@ The API supports 150+ currencies, including:
207301

208302
**Precious Metals**:
209303

210-
- GOLD - Gold (per gram)
211-
- SILVER - Silver (per gram)
212-
- PLATINUM - Platinum (per gram)
213-
- PALLADIUM - Palladium (per gram)
304+
- **GOLD** - Gold (per gram)
305+
- **SILVER** - Silver (per gram)
306+
- **PLATINUM** - Platinum (per gram)
307+
- **PALLADIUM** - Palladium (per gram)
214308

215309
**Base Metals**:
216310

217-
- COPPER - Copper (per gram)
218-
- ALUMINUM - Aluminum (per gram)
219-
- LEAD - Lead (per gram)
220-
- NICKEL - Nickel (per gram)
221-
- ZINC - Zinc (per gram)
311+
- **COPPER** - Copper (per gram)
312+
- **ALUMINUM** - Aluminum (per gram)
313+
- **LEAD** - Lead (per gram)
314+
- **NICKEL** - Nickel (per gram)
315+
- **ZINC** - Zinc (per gram)
316+
317+
### Cryptocurrencies (2500+)
318+
319+
The API supports 2500+ major cryptocurrencies, including:
320+
321+
- **Major Cryptocurrencies**: BTC, ETH, BNB, SOL, XRP, ADA, DOGE, AVAX, DOT, TRX
322+
- **DeFi Tokens**: AAVE, UNI, LINK, MKR, COMP, SUSHI
323+
- **Layer 2 & Scaling**: ARB, OP, POL, IMX
324+
- **Interoperability**: ATOM, DOT, NEAR
325+
- **Meme Coins**: DOGE, SHIB
326+
- **Privacy Coins**: XMR, ZEC
327+
- **Gaming & Metaverse**: SAND, MANA, AXS
328+
- And many more...
222329

223330
## Rate Calculation
224331

332+
### Forex & Metals Rates
333+
225334
Exchange rates are calculated using USD as the reference currency from metals.dev data:
226335

227336
- **USD to X**: Inverse of metals.dev rate (1 / rate)
@@ -234,3 +343,19 @@ Rates are rounded intelligently based on their magnitude:
234343
- **Rates 0.1-1**: 5 decimal places
235344
- **Rates 0.01-0.1**: 6 decimal places
236345
- And progressively more precision for smaller rates
346+
347+
### Cryptocurrency Rates
348+
349+
Cryptocurrency prices are aggregated from multiple exchanges for optimal pricing:
350+
351+
- **Supported Exchanges**: Binance, Kraken, Gate, KuCoin, BingX, ByBit, Crypto.com, Bitfinex
352+
- **Smart Aggregation**: Combines prices from multiple sources with outlier detection
353+
- **Optimal Pricing**: Uses average of filtered prices (removing outliers beyond 20% deviation)
354+
- **Fallback Logic**: Falls back to median if all prices are outliers
355+
356+
Rates are rounded intelligently based on their magnitude:
357+
358+
- **Rates ≥ 1**: 4 decimal places
359+
- **Rates 0.1-1**: 5 decimal places
360+
- **Rates 0.01-0.1**: 6 decimal places
361+
- And progressively more precision for smaller rates

bun.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.override.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ services:
99
environment:
1010
- METALS_DEV_API_KEY
1111
- UPDATE_INTERVAL
12+
- USE_KRAKEN
13+
- USE_BINANCE
14+
- USE_GATEIO
15+
- USE_KUCOIN
16+
- USE_BINGX
17+
- USE_BYBIT
18+
- USE_CRYPTOCOM
19+
- USE_BITFINEX
20+
- CRYPTO_UPDATE_INTERVAL
21+
- ENABLED_CRYPTOS
1222
- LOGGER_LEVEL
1323
- PROXY
1424
healthcheck:

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ services:
88
environment:
99
- METALS_DEV_API_KEY
1010
- UPDATE_INTERVAL
11+
- USE_KRAKEN
12+
- USE_BINANCE
13+
- USE_GATEIO
14+
- USE_KUCOIN
15+
- USE_BINGX
16+
- USE_BYBIT
17+
- USE_CRYPTOCOM
18+
- USE_BITFINEX
19+
- CRYPTO_UPDATE_INTERVAL
20+
- ENABLED_CRYPTOS
1121
- LOGGER_LEVEL
1222
- PROXY
1323
healthcheck:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rabbitforexapi",
3-
"version": "2.1.0",
3+
"version": "3.0.0",
44
"module": "src/index.ts",
55
"type": "module",
66
"private": true,

0 commit comments

Comments
 (0)