valr-typescript-client 1.0.25 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHECKSUMS.txt +14 -14
- package/README.md +257 -35
- package/dist/index.d.mts +74 -53
- package/dist/index.d.ts +74 -53
- package/dist/index.js +150 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +39 -16
package/CHECKSUMS.txt
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
1
|
# Package Checksums
|
|
2
2
|
|
|
3
|
-
Generated on: 2026-
|
|
4
|
-
Git commit:
|
|
5
|
-
Version: 1.0.
|
|
3
|
+
Generated on: 2026-02-11 12:21:44 UTC
|
|
4
|
+
Git commit: a006c6397ad1e8885042999423f37d8fcb7cd549
|
|
5
|
+
Version: 1.0.27
|
|
6
6
|
|
|
7
7
|
## Distribution Files (SHA256)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
4c56356d6d46f7061cb69196272a932c98b2664d0d63420834cb1335eb074667 dist/index.js.map
|
|
10
|
+
6535b8c4a4557ad6bb77aa7c330a92ca63b7f49a5e770e1fdc090f366c582b19 dist/index.d.mts
|
|
11
|
+
6535b8c4a4557ad6bb77aa7c330a92ca63b7f49a5e770e1fdc090f366c582b19 dist/index.d.ts
|
|
12
|
+
8bf4f137d4459b0b15039dacab1833448c112894ac66cd2d25a66db9eaf43077 dist/index.mjs.map
|
|
13
|
+
b0efcc098e3f3a8051349fdba6815896cf29fd536e849e355436cd67a63277fd dist/index.mjs
|
|
14
|
+
c3d911e9c094a2955e4e81805aa7a7ed929c7c5c091ba24725b4b91e4b102abc dist/index.js
|
|
15
15
|
|
|
16
16
|
## Source Files (SHA256)
|
|
17
17
|
|
|
18
|
-
05cf6e982fcbd24cebc6c1b4c6e366095859cdf503eb70f5faf4d9bb9844631a src/client/ValrClient.ts
|
|
19
18
|
0705454404aa0e0f2ce619615600d871c8052ac0afe495bb412219d9a6c032ac src/types/public.ts
|
|
20
19
|
07451545d78e896ab106b594151b4b9a3ae5ca4a2328914b2040a67cec403270 src/types/margin.ts
|
|
21
20
|
0b4530d458e0c3bbadb79566943ef466404215e545f25c4965c72d9bfeee86dc src/api/health.ts
|
|
21
|
+
0da8bec4137e840f560cc7b0bd8a66f282111bea693c99a750c496f5cbd07f35 src/client/TradeWebSocket.ts
|
|
22
22
|
13c4319ae883c96f779ea57f481c52f2298397e11950213f7d43a05290f42e8a src/api/trading.ts
|
|
23
23
|
15ef50a824d04e4466a4e34c29b54429c4d36e64d15eed1374c7165452da3abf src/api/loans.ts
|
|
24
24
|
174ffc46347008d3f473af1916e8b1b38fb9752e68a69776df831dca676a1342 src/api/public.ts
|
|
25
|
+
1877f970ead05ec2f776b2c1a373e22d6b1748cb8e16543d8422eb08b8737185 src/client/ValrClient.ts
|
|
25
26
|
1b2b9d2ae756384d9495e833dfa77d77f7b69da31a710dbb1bcdb7f688caace7 src/types/account.ts
|
|
26
27
|
392124cca58a1532bd57472ba574bc065052c552ea8f10b7c675c942310c67e8 src/api/wallets.ts
|
|
27
28
|
39fd4908c74bcca8c4e74a3a4e16de4439dfca781a7644ca9383c5f5096744cf src/types/futures.ts
|
|
28
29
|
3e5ff90a945e12f321b0e7a5bdef82f95e0b04f6ba794eeed9d4887d80d50323 src/api/pay.ts
|
|
29
|
-
40f2245b2685e634bd0f531367561c1c26d174cc083c496c1f914e8c6a9f948a src/client/ValrWebSocketClient.ts
|
|
30
30
|
4202fe777fda3e43ff944971783116f17031d124395e4a44cb2bf2bec5ff246c src/types/bundles.ts
|
|
31
31
|
43ce3b42153a2e1a2d290ea893507c820e4461eb2162b1ccfa0d832118468618 src/api/margin.ts
|
|
32
32
|
4e77e25219e1d4c7552ffc6b561493e33fb179c31fc9eaf456a304e7d7055552 src/api/account.ts
|
|
33
33
|
551aa287e635dad4d0209502a0410f09c169715a5bac95366a875038c3e50504 src/api/futures.ts
|
|
34
34
|
5572db3151cd4db275a7ac6e8a8859e3c9048e0bd873a113f445139c0db2017c src/api/bundles.ts
|
|
35
|
+
56848fb83b06ee2264c2a5197dc641d5b28513aee2c097cdcbf8ed1db3cdf271 src/client/AccountWebSocket.ts
|
|
35
36
|
593e9b1515cb7e1316feae0cf24a9300b879284677c5e790e650502b32c70706 src/types/websocket.ts
|
|
37
|
+
5a6cc3f289263a8d68c4dbe1d23be4c686676a81975b8eb3d49c4445903929e8 src/utils/http.ts
|
|
36
38
|
5f68ae1d81c72d13f5c4c2b16d6c45e89500b069b84f3cf788f97b313790e8cf src/types/index.ts
|
|
37
39
|
612b1e543d1bbd97b75e814fa7d9b4ff4b1786f6b3671a03019917049e38a96e src/types/stake.ts
|
|
40
|
+
63fcafb0d6345bf76bb677a12cb679b621e40bc148ef1865e77495fc49f0f9b3 src/client/ValrWebSocketClient.ts
|
|
38
41
|
6ec43e250aca38bc6a9dc4f16e5fe7e6ca25bd831270c5d02c1bc82d79f5731d src/types/loans.ts
|
|
39
42
|
70636220daed500243e5cd40d25748efcd401a9ff50f4237fa200bce1fe3be38 src/errors/ValrError.ts
|
|
40
43
|
a1227a733cc2ab864023614a826d8c174464d6dd5390eb8820ed616c596be0d1 src/types/trading.ts
|
|
41
44
|
a52c483def6de035f7fcf690b6102129ea22cb817bed5a106d3617c8edc7d849 src/api/stake.ts
|
|
42
|
-
c235e305ae167ebe7b97944fb50df66df428cf7b4776aacab57f6c4d6083cf40 src/utils/http.ts
|
|
43
45
|
dc9ef99ff3979f5dd0f0fc7231f9a6b9418dd13e0e8961511af1c9d54200576e src/types/pay.ts
|
|
44
46
|
e4cd666eff2f4223850198ca26912d310298291cfe0606a773350df3b3f58c59 src/types/common.ts
|
|
45
47
|
ec209b0ff8de8e662c2ea701feccee22b53e6ed684affb3eacd39e68c3aa725a src/index.ts
|
|
46
48
|
f67a6c69ed003a1606221e792de802592aedb7164cafb7d7d2eab4fac105807a src/utils/constants.ts
|
|
47
|
-
f819d431730bb51a23d2cad32cc6eee83dc9d917e5cb9efd3201ffeb64d76ec5 src/client/AccountWebSocket.ts
|
|
48
49
|
fadae797586481848494b79e9924ecc1e6fabc19a154d822579ffa2065d395fd src/auth/RequestSigner.ts
|
|
49
|
-
fe3ced400781e287f691c1262b48ea5005d21b45f69172a8a03b470e14c63a6e src/client/TradeWebSocket.ts
|
|
50
50
|
fe8bec28add01e200bd95ad326a0511334671b3a82a3990d2ee521adca7a7a8e src/types/wallets.ts
|
package/README.md
CHANGED
|
@@ -1,36 +1,114 @@
|
|
|
1
|
-
# VALR TypeScript Client
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
# VALR API TypeScript Client | Official SDK for VALR Cryptocurrency Exchange
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/valr-typescript-client)
|
|
4
|
+
[](https://www.npmjs.com/package/valr-typescript-client)
|
|
5
|
+
[](https://github.com/yashutanna/valr-typescript-client/blob/master/LICENSE)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
|
|
9
|
+
**Official TypeScript/JavaScript SDK for [VALR](https://www.valr.com) API** - South Africa's leading cryptocurrency exchange platform.
|
|
10
|
+
|
|
11
|
+
Complete, fully-typed REST API client for VALR cryptocurrency exchange. Build Bitcoin, Ethereum, and altcoin trading bots with comprehensive TypeScript support. Perfect for algorithmic trading, portfolio management, and crypto automation.
|
|
12
|
+
|
|
13
|
+
## 🚀 Perfect For
|
|
14
|
+
|
|
15
|
+
- **Trading Bots** - Automate your crypto trading strategies
|
|
16
|
+
- **Portfolio Management** - Track and manage multiple wallets
|
|
17
|
+
- **Algorithmic Trading** - Build sophisticated trading algorithms
|
|
18
|
+
- **Market Analysis** - Access real-time market data and order books
|
|
19
|
+
- **DeFi Integration** - Connect VALR to your DeFi applications
|
|
20
|
+
- **Crypto Automation** - Automate deposits, withdrawals, and transfers
|
|
21
|
+
|
|
22
|
+
## ✨ Features
|
|
23
|
+
|
|
24
|
+
### Trading & Markets
|
|
25
|
+
- ✅ **Spot Trading** - Buy/sell Bitcoin, Ethereum, and 50+ cryptocurrencies
|
|
26
|
+
- ✅ **Futures Trading** - Perpetual futures contracts with up to 60x leverage
|
|
27
|
+
- ✅ **Margin Trading** - Trade with borrowed funds
|
|
28
|
+
- ✅ **Batch Orders** - Submit up to 10 orders in a single request
|
|
29
|
+
- ✅ **Advanced Orders** - Stop-limit, post-only, reduce-only orders
|
|
30
|
+
- ✅ **Conditional Orders** - Take-profit and stop-loss automation
|
|
31
|
+
|
|
32
|
+
### TypeScript & Developer Experience
|
|
33
|
+
- ✅ **100% TypeScript** - Complete type definitions for all API endpoints
|
|
34
|
+
- ✅ **IntelliSense Support** - Auto-completion in VS Code and IDEs
|
|
35
|
+
- ✅ **Type-Safe Requests** - Compile-time validation of all API calls
|
|
36
|
+
- ✅ **ESM & CommonJS** - Works with modern and legacy Node.js projects
|
|
37
|
+
- ✅ **Zero Dependencies** - Minimal dependency footprint
|
|
38
|
+
|
|
39
|
+
### API Coverage
|
|
40
|
+
- ✅ **147+ REST Endpoints** - Complete VALR API implementation
|
|
41
|
+
- ✅ **WebSocket Support** - Real-time market data and account updates
|
|
42
|
+
- ✅ **Public APIs** - Market data, order books, trade history (no auth required)
|
|
43
|
+
- ✅ **Account APIs** - Balances, transaction history, API key management
|
|
44
|
+
- ✅ **Wallet APIs** - Crypto/fiat deposits and withdrawals
|
|
45
|
+
|
|
46
|
+
### Security & Reliability
|
|
47
|
+
- ✅ **HMAC SHA512 Authentication** - Industry-standard request signing
|
|
48
|
+
- ✅ **Automatic Signature Generation** - No manual crypto operations needed
|
|
49
|
+
- ✅ **Rate Limit Handling** - Built-in rate limit awareness
|
|
50
|
+
- ✅ **Error Types** - Typed error classes for all failure scenarios
|
|
51
|
+
- ✅ **Subaccount Support** - Manage multiple trading accounts
|
|
52
|
+
|
|
53
|
+
### Package Integrity
|
|
54
|
+
- ✅ **Cryptographic Checksums** - SHA256 verification for all builds
|
|
55
|
+
- ✅ **Reproducible Builds** - Build from source with verification
|
|
56
|
+
- ✅ **Supply Chain Security** - GitHub Actions provenance attestation
|
|
57
|
+
|
|
58
|
+
## 🪙 Supported Cryptocurrencies
|
|
59
|
+
|
|
60
|
+
Trade 50+ cryptocurrencies including:
|
|
61
|
+
- **Bitcoin (BTC)** - BTC/ZAR, BTC/USDC, BTC/USDT pairs
|
|
62
|
+
- **Ethereum (ETH)** - ETH/ZAR, ETH/USDC, ETH/BTC pairs
|
|
63
|
+
- **Major Altcoins** - XRP, ADA, DOT, LINK, MATIC, SOL, AVAX, UNI
|
|
64
|
+
- **Stablecoins** - USDC, USDT, DAI
|
|
65
|
+
- **DeFi Tokens** - AAVE, SNX, COMP, MKR, YFI
|
|
66
|
+
- **Meme Coins** - DOGE, SHIB
|
|
67
|
+
- **Perpetual Futures** - BTC-PERP, ETH-PERP, and more
|
|
68
|
+
|
|
69
|
+
Full list at [VALR Markets](https://www.valr.com/markets)
|
|
70
|
+
|
|
71
|
+
## 📦 Installation
|
|
72
|
+
|
|
73
|
+
### npm
|
|
18
74
|
```bash
|
|
19
75
|
npm install valr-typescript-client
|
|
20
76
|
```
|
|
21
77
|
|
|
22
|
-
|
|
23
|
-
|
|
78
|
+
### yarn
|
|
24
79
|
```bash
|
|
25
80
|
yarn add valr-typescript-client
|
|
26
81
|
```
|
|
27
82
|
|
|
28
|
-
|
|
29
|
-
|
|
83
|
+
### pnpm
|
|
30
84
|
```bash
|
|
31
85
|
pnpm add valr-typescript-client
|
|
32
86
|
```
|
|
33
87
|
|
|
88
|
+
### bun
|
|
89
|
+
```bash
|
|
90
|
+
bun add valr-typescript-client
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 📚 Table of Contents
|
|
94
|
+
|
|
95
|
+
- [Quick Start](#-quick-start)
|
|
96
|
+
- [Public API (No Authentication)](#public-api-no-authentication-required)
|
|
97
|
+
- [Authenticated Trading](#authenticated-api)
|
|
98
|
+
- [Advanced Trading Examples](#advanced-trading)
|
|
99
|
+
- [API Categories](#api-categories)
|
|
100
|
+
- [Authentication & Security](#authentication)
|
|
101
|
+
- [TypeScript Support](#typescript-support)
|
|
102
|
+
- [Error Handling](#error-handling)
|
|
103
|
+
- [Rate Limits](#rate-limits)
|
|
104
|
+
- [Examples](#examples)
|
|
105
|
+
- [Trading Bots](#trading-bot-example)
|
|
106
|
+
- [Portfolio Tracking](#portfolio-tracking-example)
|
|
107
|
+
- [Market Analysis](#market-analysis-example)
|
|
108
|
+
- [Package Verification](#package-integrity--verification)
|
|
109
|
+
- [Development](#development)
|
|
110
|
+
- [Contributing](#contributing)
|
|
111
|
+
|
|
34
112
|
## Quick Start
|
|
35
113
|
|
|
36
114
|
### Public API (No Authentication Required)
|
|
@@ -198,6 +276,122 @@ client.setSubaccountId('different-subaccount-id');
|
|
|
198
276
|
client.setSubaccountId(undefined); // Back to primary account
|
|
199
277
|
```
|
|
200
278
|
|
|
279
|
+
## 💡 Examples
|
|
280
|
+
|
|
281
|
+
### Trading Bot Example
|
|
282
|
+
|
|
283
|
+
Build a simple Bitcoin DCA (Dollar Cost Averaging) bot:
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import { ValrClient } from 'valr-typescript-client';
|
|
287
|
+
|
|
288
|
+
const client = new ValrClient({
|
|
289
|
+
apiKey: process.env.VALR_API_KEY!,
|
|
290
|
+
apiSecret: process.env.VALR_API_SECRET!,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// DCA Bot - Buy R1000 worth of BTC every day
|
|
294
|
+
async function dcaBot() {
|
|
295
|
+
try {
|
|
296
|
+
// Get current BTC price
|
|
297
|
+
const ticker = await client.public.getMarketSummary('BTCZAR');
|
|
298
|
+
console.log(`Current BTC price: R${ticker[0].lastTradedPrice}`);
|
|
299
|
+
|
|
300
|
+
// Place market buy order for R1000
|
|
301
|
+
const order = await client.trading.placeMarketOrder({
|
|
302
|
+
pair: 'BTCZAR',
|
|
303
|
+
side: 'BUY',
|
|
304
|
+
quoteAmount: '1000', // Spend R1000
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
console.log(`Bought BTC: Order ID ${order.id}`);
|
|
308
|
+
} catch (error) {
|
|
309
|
+
console.error('DCA bot error:', error);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Run daily at 9 AM
|
|
314
|
+
setInterval(dcaBot, 24 * 60 * 60 * 1000);
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Portfolio Tracking Example
|
|
318
|
+
|
|
319
|
+
Track your crypto portfolio value:
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
import { ValrClient } from 'valr-typescript-client';
|
|
323
|
+
|
|
324
|
+
const client = new ValrClient({
|
|
325
|
+
apiKey: process.env.VALR_API_KEY!,
|
|
326
|
+
apiSecret: process.env.VALR_API_SECRET!,
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
async function getPortfolioValue() {
|
|
330
|
+
// Get all balances
|
|
331
|
+
const balances = await client.account.getBalances();
|
|
332
|
+
|
|
333
|
+
// Get ZAR prices for all assets
|
|
334
|
+
const markets = await client.public.getMarketSummary();
|
|
335
|
+
|
|
336
|
+
let totalValue = 0;
|
|
337
|
+
|
|
338
|
+
for (const balance of balances) {
|
|
339
|
+
if (parseFloat(balance.total) === 0) continue;
|
|
340
|
+
|
|
341
|
+
if (balance.currency === 'ZAR') {
|
|
342
|
+
totalValue += parseFloat(balance.total);
|
|
343
|
+
} else {
|
|
344
|
+
// Find ZAR pair for this currency
|
|
345
|
+
const pair = `${balance.currency}ZAR`;
|
|
346
|
+
const market = markets.find(m => m.currencyPair === pair);
|
|
347
|
+
|
|
348
|
+
if (market) {
|
|
349
|
+
const value = parseFloat(balance.total) * parseFloat(market.lastTradedPrice);
|
|
350
|
+
totalValue += value;
|
|
351
|
+
console.log(`${balance.currency}: ${balance.total} = R${value.toFixed(2)}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
console.log(`\nTotal Portfolio Value: R${totalValue.toFixed(2)}`);
|
|
357
|
+
return totalValue;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
getPortfolioValue();
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Market Analysis Example
|
|
364
|
+
|
|
365
|
+
Analyze Bitcoin order book depth:
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
import { ValrClient } from 'valr-typescript-client';
|
|
369
|
+
|
|
370
|
+
const client = new ValrClient();
|
|
371
|
+
|
|
372
|
+
async function analyzeOrderBook() {
|
|
373
|
+
const orderBook = await client.public.getOrderBook('BTCZAR');
|
|
374
|
+
|
|
375
|
+
// Calculate bid/ask depth
|
|
376
|
+
const bidDepth = orderBook.Bids.reduce((sum, bid) =>
|
|
377
|
+
sum + parseFloat(bid.quantity), 0
|
|
378
|
+
);
|
|
379
|
+
const askDepth = orderBook.Asks.reduce((sum, ask) =>
|
|
380
|
+
sum + parseFloat(ask.quantity), 0
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
const bidAskRatio = bidDepth / askDepth;
|
|
384
|
+
|
|
385
|
+
console.log(`BTC/ZAR Order Book Analysis:`);
|
|
386
|
+
console.log(`Bid Depth: ${bidDepth.toFixed(4)} BTC`);
|
|
387
|
+
console.log(`Ask Depth: ${askDepth.toFixed(4)} BTC`);
|
|
388
|
+
console.log(`Bid/Ask Ratio: ${bidAskRatio.toFixed(2)}`);
|
|
389
|
+
console.log(`Market Sentiment: ${bidAskRatio > 1 ? 'Bullish' : 'Bearish'}`);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
analyzeOrderBook();
|
|
393
|
+
```
|
|
394
|
+
|
|
201
395
|
## API Categories
|
|
202
396
|
|
|
203
397
|
The client organizes endpoints into logical categories:
|
|
@@ -442,28 +636,56 @@ npm run test:watch
|
|
|
442
636
|
npm run type-check
|
|
443
637
|
```
|
|
444
638
|
|
|
445
|
-
## Contributing
|
|
639
|
+
## 🤝 Contributing
|
|
446
640
|
|
|
447
|
-
Contributions are welcome!
|
|
641
|
+
Contributions are welcome! We're looking for:
|
|
448
642
|
|
|
449
|
-
|
|
643
|
+
- 🐛 Bug fixes and issue reports
|
|
644
|
+
- 📝 Documentation improvements
|
|
645
|
+
- ✨ New feature implementations
|
|
646
|
+
- 🧪 Additional test coverage
|
|
647
|
+
- 🌍 Internationalization support
|
|
450
648
|
|
|
451
|
-
|
|
649
|
+
Please feel free to submit a Pull Request or open an issue.
|
|
452
650
|
|
|
453
|
-
|
|
651
|
+
### Development Setup
|
|
454
652
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
653
|
+
```bash
|
|
654
|
+
git clone https://github.com/yashutanna/valr-typescript-client.git
|
|
655
|
+
cd valr-typescript-client
|
|
656
|
+
npm install
|
|
657
|
+
npm run build
|
|
658
|
+
npm test
|
|
659
|
+
```
|
|
459
660
|
|
|
460
|
-
##
|
|
661
|
+
## 🔗 Links & Resources
|
|
461
662
|
|
|
462
|
-
|
|
663
|
+
- **📦 [NPM Package](https://www.npmjs.com/package/valr-typescript-client)** - Install from npm
|
|
664
|
+
- **💻 [GitHub Repository](https://github.com/yashutanna/valr-typescript-client)** - Source code and issues
|
|
665
|
+
- **📘 [VALR API Documentation](https://docs.valr.com)** - Official VALR API docs
|
|
666
|
+
- **🌐 [VALR Exchange](https://www.valr.com)** - Trade on VALR
|
|
667
|
+
- **📊 [VALR Markets](https://www.valr.com/markets)** - View all trading pairs
|
|
668
|
+
- **💬 [VALR Support](https://support.valr.com)** - Official VALR support
|
|
463
669
|
|
|
464
|
-
## Support
|
|
670
|
+
## 🆘 Support & Issues
|
|
465
671
|
|
|
466
672
|
For issues and questions:
|
|
467
673
|
|
|
468
|
-
- [
|
|
469
|
-
- [
|
|
674
|
+
- **🐛 [Report a Bug](https://github.com/yashutanna/valr-typescript-client/issues)** - GitHub Issues
|
|
675
|
+
- **💡 [Request a Feature](https://github.com/yashutanna/valr-typescript-client/issues)** - Feature requests
|
|
676
|
+
- **📖 [Documentation](https://github.com/yashutanna/valr-typescript-client#readme)** - Full documentation
|
|
677
|
+
- **💬 [VALR Support](https://support.valr.com)** - Official VALR help
|
|
678
|
+
|
|
679
|
+
## 📜 License
|
|
680
|
+
|
|
681
|
+
MIT License - see [LICENSE](LICENSE) file for details
|
|
682
|
+
|
|
683
|
+
## ⚠️ Disclaimer
|
|
684
|
+
|
|
685
|
+
This is an **unofficial** TypeScript client library for the VALR API. It is not affiliated with, endorsed by, or officially connected to VALR in any way. Use at your own risk.
|
|
686
|
+
|
|
687
|
+
**Trading cryptocurrencies carries risk.** Only trade with funds you can afford to lose. This software is provided "as is" without warranty of any kind.
|
|
688
|
+
|
|
689
|
+
## 🏷️ Keywords
|
|
690
|
+
|
|
691
|
+
`valr api` `valr typescript` `valr javascript` `valr sdk` `valr client` `cryptocurrency trading` `bitcoin api` `ethereum api` `crypto exchange api` `south africa crypto` `trading bot` `algorithmic trading` `crypto automation` `typescript trading bot` `valr rest api` `valr websocket`
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
|
|
2
1
|
import WebSocket from 'ws';
|
|
3
|
-
import EventEmitter from '
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* HTTP client configuration
|
|
@@ -11,31 +10,85 @@ interface HttpClientConfig {
|
|
|
11
10
|
headers?: Record<string, string>;
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
13
|
+
* Request configuration (similar to AxiosRequestConfig for compatibility)
|
|
14
|
+
*/
|
|
15
|
+
interface RequestConfig {
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
params?: Record<string, any>;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
/** Request body data (for DELETE with body) */
|
|
20
|
+
data?: any;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Internal request configuration used by interceptors
|
|
24
|
+
*/
|
|
25
|
+
interface InternalRequestConfig {
|
|
26
|
+
method: string;
|
|
27
|
+
url: string;
|
|
28
|
+
headers: Record<string, string>;
|
|
29
|
+
params?: Record<string, any>;
|
|
30
|
+
data?: any;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Request interceptor function type
|
|
34
|
+
*/
|
|
35
|
+
type RequestInterceptor = (config: InternalRequestConfig) => InternalRequestConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Response wrapper (similar to AxiosResponse for compatibility)
|
|
38
|
+
*/
|
|
39
|
+
interface HttpResponse<T = any> {
|
|
40
|
+
data: T;
|
|
41
|
+
status: number;
|
|
42
|
+
statusText: string;
|
|
43
|
+
headers: Headers;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* HTTP client wrapper for VALR API using native fetch
|
|
47
|
+
* Zero dependencies - uses Node.js built-in fetch (Node 18+)
|
|
15
48
|
*/
|
|
16
49
|
declare class HttpClient {
|
|
17
|
-
private
|
|
50
|
+
private baseURL;
|
|
51
|
+
private timeout;
|
|
52
|
+
private defaultHeaders;
|
|
53
|
+
private requestInterceptors;
|
|
18
54
|
constructor(config?: HttpClientConfig);
|
|
55
|
+
/**
|
|
56
|
+
* Add a request interceptor
|
|
57
|
+
* Interceptors are called in order before each request
|
|
58
|
+
*/
|
|
59
|
+
addRequestInterceptor(interceptor: RequestInterceptor): void;
|
|
60
|
+
/**
|
|
61
|
+
* Build full URL with query parameters
|
|
62
|
+
*/
|
|
63
|
+
private buildUrl;
|
|
64
|
+
/**
|
|
65
|
+
* Execute HTTP request with error handling
|
|
66
|
+
*/
|
|
67
|
+
private request;
|
|
68
|
+
/**
|
|
69
|
+
* Handle error responses and throw appropriate VALR errors
|
|
70
|
+
*/
|
|
71
|
+
private handleErrorResponse;
|
|
19
72
|
/**
|
|
20
73
|
* Perform GET request
|
|
21
74
|
*/
|
|
22
|
-
get<T = any>(url: string, config?:
|
|
75
|
+
get<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
23
76
|
/**
|
|
24
77
|
* Perform POST request
|
|
25
78
|
*/
|
|
26
|
-
post<T = any>(url: string, data?: any, config?:
|
|
79
|
+
post<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
27
80
|
/**
|
|
28
81
|
* Perform PUT request
|
|
29
82
|
*/
|
|
30
|
-
put<T = any>(url: string, data?: any, config?:
|
|
83
|
+
put<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
31
84
|
/**
|
|
32
85
|
* Perform PATCH request
|
|
33
86
|
*/
|
|
34
|
-
patch<T = any>(url: string, data?: any, config?:
|
|
87
|
+
patch<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
35
88
|
/**
|
|
36
89
|
* Perform DELETE request
|
|
37
90
|
*/
|
|
38
|
-
delete<T = any>(url: string, config?:
|
|
91
|
+
delete<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
39
92
|
/**
|
|
40
93
|
* Set default header
|
|
41
94
|
*/
|
|
@@ -44,10 +97,6 @@ declare class HttpClient {
|
|
|
44
97
|
* Remove default header
|
|
45
98
|
*/
|
|
46
99
|
removeHeader(key: string): void;
|
|
47
|
-
/**
|
|
48
|
-
* Get the underlying Axios instance
|
|
49
|
-
*/
|
|
50
|
-
getInstance(): AxiosInstance;
|
|
51
100
|
}
|
|
52
101
|
|
|
53
102
|
/**
|
|
@@ -3640,6 +3689,10 @@ interface ValrClientConfig {
|
|
|
3640
3689
|
* Subaccount ID for impersonating a subaccount (optional)
|
|
3641
3690
|
*/
|
|
3642
3691
|
subaccountId?: string;
|
|
3692
|
+
/**
|
|
3693
|
+
* enable debug logging for the client requests, responses and configs. (optional default=false)
|
|
3694
|
+
*/
|
|
3695
|
+
debug?: boolean;
|
|
3643
3696
|
}
|
|
3644
3697
|
/**
|
|
3645
3698
|
* Main VALR API client
|
|
@@ -3663,6 +3716,7 @@ declare class ValrClient {
|
|
|
3663
3716
|
private apiKey?;
|
|
3664
3717
|
private apiSecret?;
|
|
3665
3718
|
private subaccountId?;
|
|
3719
|
+
private debug?;
|
|
3666
3720
|
/**
|
|
3667
3721
|
* Public API methods (no authentication required)
|
|
3668
3722
|
*/
|
|
@@ -3745,23 +3799,14 @@ interface WebSocketClientConfig {
|
|
|
3745
3799
|
maxReconnectAttempts?: number;
|
|
3746
3800
|
/** Base URL for WS (defaults to wss://api.valr.com) */
|
|
3747
3801
|
baseURL?: string;
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
* WebSocket event types
|
|
3751
|
-
*/
|
|
3752
|
-
interface WebSocketEvents {
|
|
3753
|
-
connected: () => void;
|
|
3754
|
-
authenticated: () => void;
|
|
3755
|
-
message: (message: WebSocketMessage) => void;
|
|
3756
|
-
error: (error: Error) => void;
|
|
3757
|
-
close: (code: number, reason: string) => void;
|
|
3758
|
-
disconnected: () => void;
|
|
3759
|
-
reconnecting: (attempt: number) => void;
|
|
3802
|
+
/** Enable debug logging for the client requests, responses and configs. either defined as true or not passed in */
|
|
3803
|
+
debug?: boolean;
|
|
3760
3804
|
}
|
|
3761
3805
|
/**
|
|
3762
3806
|
* Base WebSocket client for VALR API
|
|
3807
|
+
* Uses Node.js native EventEmitter (zero dependencies)
|
|
3763
3808
|
*/
|
|
3764
|
-
declare abstract class ValrWebSocketClient
|
|
3809
|
+
declare abstract class ValrWebSocketClient extends EventEmitter {
|
|
3765
3810
|
protected ws?: WebSocket;
|
|
3766
3811
|
protected url: string;
|
|
3767
3812
|
protected path: string;
|
|
@@ -3771,6 +3816,7 @@ declare abstract class ValrWebSocketClient<TEvents extends WebSocketEvents = Web
|
|
|
3771
3816
|
protected isIntentionalClose: boolean;
|
|
3772
3817
|
protected isConnected: boolean;
|
|
3773
3818
|
protected isAuthenticated: boolean;
|
|
3819
|
+
protected debug?: true;
|
|
3774
3820
|
constructor(path: string, config?: WebSocketClientConfig);
|
|
3775
3821
|
/**
|
|
3776
3822
|
* Connect to WebSocket
|
|
@@ -3819,19 +3865,6 @@ declare abstract class ValrWebSocketClient<TEvents extends WebSocketEvents = Web
|
|
|
3819
3865
|
protected abstract onMessage(message: WebSocketMessage): void;
|
|
3820
3866
|
}
|
|
3821
3867
|
|
|
3822
|
-
/**
|
|
3823
|
-
* Account WebSocket events (in addition to base events)
|
|
3824
|
-
*/
|
|
3825
|
-
interface AccountWebSocketEvents {
|
|
3826
|
-
'order:processed': (data: OrderProcessed) => void;
|
|
3827
|
-
'order:statusUpdate': (data: OrderStatusUpdate) => void;
|
|
3828
|
-
'balance:update': (data: BalanceUpdate) => void;
|
|
3829
|
-
'trade:new': (data: AccountTrade) => void;
|
|
3830
|
-
}
|
|
3831
|
-
/**
|
|
3832
|
-
* Combined event types for AccountWebSocket
|
|
3833
|
-
*/
|
|
3834
|
-
type AccountWebSocketEventMap = WebSocketEvents & AccountWebSocketEvents;
|
|
3835
3868
|
/**
|
|
3836
3869
|
* Account WebSocket client for real-time account updates
|
|
3837
3870
|
*
|
|
@@ -3867,7 +3900,7 @@ type AccountWebSocketEventMap = WebSocketEvents & AccountWebSocketEvents;
|
|
|
3867
3900
|
* wsClient.connect();
|
|
3868
3901
|
* ```
|
|
3869
3902
|
*/
|
|
3870
|
-
declare class AccountWebSocket extends ValrWebSocketClient
|
|
3903
|
+
declare class AccountWebSocket extends ValrWebSocketClient {
|
|
3871
3904
|
constructor(config: WebSocketClientConfig);
|
|
3872
3905
|
/**
|
|
3873
3906
|
* Subscribe to specific events
|
|
@@ -3891,18 +3924,6 @@ declare class AccountWebSocket extends ValrWebSocketClient<AccountWebSocketEvent
|
|
|
3891
3924
|
protected onMessage(message: WebSocketMessage): void;
|
|
3892
3925
|
}
|
|
3893
3926
|
|
|
3894
|
-
/**
|
|
3895
|
-
* Trade WebSocket events (in addition to base events)
|
|
3896
|
-
*/
|
|
3897
|
-
interface TradeWebSocketEvents {
|
|
3898
|
-
'orderbook:update': (data: OrderBookUpdate) => void;
|
|
3899
|
-
'market:summary': (data: MarketSummaryUpdate) => void;
|
|
3900
|
-
'trade:new': (data: NewTrade) => void;
|
|
3901
|
-
}
|
|
3902
|
-
/**
|
|
3903
|
-
* Combined event types for TradeWebSocket
|
|
3904
|
-
*/
|
|
3905
|
-
type TradeWebSocketEventMap = WebSocketEvents & TradeWebSocketEvents;
|
|
3906
3927
|
/**
|
|
3907
3928
|
* Trade WebSocket client for real-time market data
|
|
3908
3929
|
*
|
|
@@ -3934,7 +3955,7 @@ type TradeWebSocketEventMap = WebSocketEvents & TradeWebSocketEvents;
|
|
|
3934
3955
|
* wsClient.connect();
|
|
3935
3956
|
* ```
|
|
3936
3957
|
*/
|
|
3937
|
-
declare class TradeWebSocket extends ValrWebSocketClient
|
|
3958
|
+
declare class TradeWebSocket extends ValrWebSocketClient {
|
|
3938
3959
|
constructor(config?: WebSocketClientConfig);
|
|
3939
3960
|
/**
|
|
3940
3961
|
* Subscribe to aggregated order book updates for currency pairs
|