tickwire 0.1.0 β†’ 0.1.1

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/README.md CHANGED
@@ -2,208 +2,33 @@
2
2
 
3
3
  <a href="https://github.com/Mathieu2301/tickwire"><img src="https://trendshift.io/api/badge/repositories/26416" alt="Mathieu2301/tickwire" width="250" height="55"/></a>
4
4
 
5
- **The market toolkit for AI agents that write code.** Candle series you can trust, with a local cache, watchers that run around the clock, indicators and backtests, all from official exchange and broker APIs and running on your own machine.
5
+ Market prices, alerts and backtests for your trading, from official exchange and broker APIs! πŸ“ˆ
6
6
 
7
- > [!NOTE]
8
- > This repository was previously known as TradingView-API. The TradingView integration has been removed at TradingView's request, and TickWire does not access TradingView's services in any way. Previous versions are no longer distributed.
9
-
10
- - **Series you can trust:** history and live feed joined without gap or overlap, closed and forming candles told apart, gaps and duplicates detected, a local cache that only fetches what is new.
11
- - **Watchers:** a condition in plain TypeScript, checked on every candle, for as many instruments as you like; an event when it triggers.
12
- - **Official sources only:** public, documented exchange and broker APIs (Binance, Coinbase Exchange, Kraken, Alpaca), used within their limits.
13
- - **One interface for every source:** the same `Candle`, `Quote` and `Trade` types, whichever provider you plug in.
14
- - **Live streams that stay up:** WebSocket feeds as async iterables, with reconnection, backoff and re-subscription.
15
- - **Local indicators and backtests:** SMA, EMA, RSI, MACD, Bollinger Bands, ATR and VWAP (incremental or batch), and an event-driven backtester with fees and slippage.
16
- - **Small:** ESM, typed, no runtime dependencies. Node 20+ or Bun (streams need Node 22+, Bun, or a `WebSocket` you pass in). A small `tickwire` command for quick lookups.
17
-
18
- ```sh
19
- npm install tickwire # or: bun add tickwire
20
- ```
21
-
22
- ## Quick start
23
-
24
- ```ts
25
- import { BinanceProvider, rsi } from 'tickwire';
26
-
27
- const binance = new BinanceProvider();
28
-
29
- // The latest 200 hourly candles, oldest first
30
- const candles = await binance.getCandles('BTC/USDT', '1h', { limit: 200 });
31
- console.log(rsi(candles.map((c) => c.close), 14).at(-1));
32
-
33
- // Best bid/ask and last price
34
- const quote = await binance.getQuote('BTC/USDT');
35
- ```
36
-
37
- Instruments are written `BASE/QUOTE` for crypto pairs (`BTC/USD`, `ETH/USDT`) and by ticker for stocks (`AAPL`). Each provider translates them into its own symbols. Timeframes are `1m`, `5m`, `1h`, `4h`, `1d`, `1w`, `1M`… (each provider lists what it supports in `provider.capabilities`).
38
-
39
- ### Series and cache
40
-
41
- ```ts
42
- import { BinanceProvider, FileStore, loadCandles, checkCandles } from 'tickwire';
43
-
44
- const store = new FileStore('.tickwire'); // JSON Lines files, readable by DuckDB, Polars or jq
45
- const candles = await loadCandles({
46
- provider: new BinanceProvider(),
47
- instrument: 'ETH/USDT',
48
- timeframe: '1h',
49
- from: '6mo', // or a date
50
- store, // the next call only fetches the hours that closed since
51
- });
52
- checkCandles(candles, '1h'); // { gaps, duplicates, unordered, misaligned, … }
53
- ```
54
-
55
- `liveCandles({ provider, instrument, timeframe, history: 200, store })` gives one continuous stream: the closed history first, then live updates. If the connection drops and periods are missed, they are fetched from the history API and emitted in order before going on.
56
-
57
- ### Watchers
58
-
59
- ```ts
60
- import { BinanceProvider, watch, rsi, appendJsonl } from 'tickwire';
61
-
62
- const log = appendJsonl('alerts.jsonl');
63
- for await (const event of watch({
64
- provider: new BinanceProvider(),
65
- instruments: ['BTC/USDT', 'ETH/USDT', 'SOL/USDT'],
66
- timeframe: '15m',
67
- name: 'oversold',
68
- when: ({ closes, candle }) => (rsi(closes, 14).at(-1) ?? 50) < 30 && { rsi: rsi(closes, 14).at(-1), price: candle.close },
69
- })) {
70
- await log(event); // or postJson(webhookUrl)
71
- }
72
- ```
73
-
74
- A watcher fires when its condition becomes true and waits for it to turn false before firing again (`mode: 'every'` to change that, `cooldownMs` to space triggers). It checks closed candles by default, or every live update with `on: 'update'`. It uses next to no CPU, so one process can watch dozens of markets around the clock.
75
-
76
- ### Command line
77
-
78
- ```sh
79
- tickwire candles binance BTC/USDT 1h --since 7d # JSON summary + candles
80
- tickwire candles alpaca AAPL 1d --since 1y --format csv
81
- tickwire check coinbase ETH/USD 1h --since 30d # gaps and duplicates
82
- tickwire quote kraken BTC/USD
83
- ```
84
-
85
- Output is JSON on stdout, errors are JSON on stderr. Candles go through the same cache (`$TICKWIRE_CACHE`, default `~/.cache/tickwire`).
86
-
87
- ### History over a range
88
-
89
- ```ts
90
- import { CoinbaseProvider } from 'tickwire';
91
-
92
- const coinbase = new CoinbaseProvider();
93
- const november = await coinbase.getCandles('ETH/USD', '1h', {
94
- from: '2026-11-01T00:00:00Z',
95
- to: '2026-11-30T23:00:00Z',
96
- }); // paged for you, within the provider's rate limit
97
- ```
98
-
99
- ### Live trades
100
-
101
- ```ts
102
- import { KrakenProvider } from 'tickwire';
103
-
104
- const kraken = new KrakenProvider();
105
- const trades = kraken.streamTrades('BTC/USD', {
106
- onStatus: (s) => console.log(s.type), // connecting, open, reconnecting, closed
107
- });
108
-
109
- for await (const trade of trades) {
110
- console.log(trade.time, trade.side, trade.size, trade.price);
111
- if (trade.size > 1) break; // breaking out of the loop closes the connection
112
- }
113
- ```
114
-
115
- `streamCandles(instrument, timeframe)` works the same way: you get the running candle on every update, then the same candle with `closed: true` when its period ends. Stop a stream with `break`, `stream.close()`, or an `AbortSignal` (`{ signal }`).
116
-
117
- ### Indicators
7
+ ## 🟒 Want an AI agent that trades your way?
118
8
 
119
- Every indicator exists in two forms: a batch function over an array, and a class you feed one value at a time.
9
+ ### πŸš€ [It learns your strategy, watches the markets 24/7 and keeps you to your rules](https://molted.studio/dreams/ai-agent-for-day-traders?utm_source=github&utm_medium=readme&utm_campaign=tickwire&utm_content=need-help)
120
10
 
121
- ```ts
122
- import { EMA, macd, bollinger, ATR } from 'tickwire';
11
+ ## ✨ Features
123
12
 
124
- const closes = candles.map((c) => c.close);
125
- macd(closes); // [undefined, …, { macd, signal, histogram }]
126
- bollinger(closes, { period: 20, stdDev: 2 });
13
+ - βœ… Realtime prices, candles and trades
14
+ - βœ… Full history, cached on your machine
15
+ - βœ… Alerts that watch dozens of markets around the clock
16
+ - βœ… Indicators: RSI, MACD, moving averages, Bollinger Bands, ATR, VWAP
17
+ - βœ… Backtests with fees and slippage
18
+ - βœ… Crypto (Binance, Coinbase, Kraken) and US stocks (Alpaca)
19
+ - βœ… Official APIs only, with your own access
20
+ - βœ… Made for AI agents that write code
127
21
 
128
- const ema = new EMA(21);
129
- for await (const candle of binance.streamCandles('BTC/USDT', '1m')) {
130
- if (candle.closed) console.log(ema.next(candle.close));
131
- }
132
- ```
133
-
134
- Available: `SMA`, `EMA`, `RSI` (Wilder), `MACD`, `BollingerBands`, `ATR` (Wilder), `VWAP` (daily or unanchored). Values are `undefined` while an indicator warms up.
135
-
136
- ### Backtest
137
-
138
- ```ts
139
- import { backtest, SMA } from 'tickwire';
140
-
141
- const fast = new SMA(10);
142
- const slow = new SMA(40);
143
-
144
- const { metrics, trades } = backtest({
145
- candles, // closed candles, oldest first
146
- initialCash: 10_000,
147
- feeRate: 0.001, // 0.1 % per fill
148
- slippage: 0.0005,
149
- strategy: (ctx) => {
150
- const f = fast.next(ctx.candle.close);
151
- const s = slow.next(ctx.candle.close);
152
- if (f === undefined || s === undefined) return;
153
- if (f > s && ctx.position === 0) ctx.buy();
154
- if (f < s && ctx.position > 0) ctx.sell();
155
- },
156
- });
157
-
158
- console.log(metrics); // totalReturn, maxDrawdown, sharpe, winRate, trades, totalFees, exposure…
159
- ```
160
-
161
- The strategy runs after each candle closes, and its orders fill at the **next** candle's open: a strategy cannot trade on a price it has not seen. `ctx.lookback(n)` returns past candles only. Positions are long only in 0.1.
162
-
163
- More in [`examples/`](examples).
164
-
165
- ## Providers
166
-
167
- | Provider | Key needed | Markets | Streams |
168
- |---|---|---|---|
169
- | `BinanceProvider` | no | crypto spot | trades, candles |
170
- | `CoinbaseProvider` | no | crypto spot | trades, candles (built from trades) |
171
- | `KrakenProvider` | no | crypto spot (latest 720 candles per timeframe) | trades, candles |
172
- | `AlpacaProvider` | free Alpaca key (`APCA_API_KEY_ID`, `APCA_API_SECRET_KEY`) | US stocks, IEX feed on the free plan | trades, 1-minute bars |
173
-
174
- **Your use of each source is governed by that provider's terms, not by TickWire.** Most of them limit market data to personal, research or internal use, forbid redistributing it, and are not available in every country. TickWire hosts and redistributes no data, and is not affiliated with or endorsed by any provider. Read [docs/providers.md](docs/providers.md) for each provider's endpoints, rate limits and terms before you use it.
175
-
176
- ## Use it with an agent
177
-
178
- TickWire is built for agents that write and run code: plain TypeScript (Node or Bun), typed results, typed errors. [docs/agents.md](docs/agents.md) is a short guide written for them. To have an agent that learns your trading strategy and watches the markets for you around the clock, start from the [day trader agent dream on molted.studio](https://molted.studio/dreams/ai-agent-for-day-traders). See [docs/positioning.md](docs/positioning.md) for where the project is heading.
179
-
180
- ## Errors
181
-
182
- Everything thrown by TickWire extends `TickwireError`:
183
-
184
- | Error | When |
185
- |---|---|
186
- | `InvalidArgumentError` | bad timeframe, instrument or range |
187
- | `NotSupportedError` | the provider does not offer this timeframe or market |
188
- | `AuthenticationError` | missing or rejected API key |
189
- | `RateLimitError` | the provider rate-limited you (`retryAfterMs` when known) |
190
- | `NetworkError` | the provider could not be reached or timed out |
191
- | `ProviderError` | the provider returned an error (`status`, `code`) or an unexpected payload |
192
-
193
- Requests are retried on network errors, 5xx and 429 answers (twice by default, `retries` option), honouring `Retry-After`.
194
-
195
- ## Development
22
+ ## πŸ“¦ Installation
196
23
 
197
24
  ```sh
198
- npm install
199
- npm run typecheck && npm run lint && npm test && npm run build
25
+ npm i tickwire
200
26
  ```
201
27
 
202
- Tests run offline against responses recorded from the real APIs (`tests/fixtures`, refreshed with `npm run fixtures:record`). Live checks are opt-in: `npm run test:live`.
28
+ πŸ“– [Getting started](docs/getting-started.md) Β· πŸ€– [Guide for AI agents](docs/agents.md) Β· πŸ”Œ [Providers and their terms](docs/providers.md) Β· 🧭 [Where the project is heading](docs/positioning.md)
203
29
 
204
- ## Need help with a project?
205
-
206
- Tell us about it through [this form](https://forms.gle/qPp5RKo8L55C5oJE7).
30
+ > [!NOTE]
31
+ > This repository was previously known as TradingView-API. The TradingView integration has been removed at TradingView's request, and TickWire does not access TradingView's services in any way. Previous versions are no longer distributed.
207
32
 
208
33
  ## License
209
34
 
@@ -0,0 +1,185 @@
1
+ # Getting started
2
+
3
+ ```sh
4
+ npm install tickwire # or: bun add tickwire
5
+ ```
6
+
7
+ TickWire is ESM, typed, with no runtime dependencies. It runs on Node 20+ or Bun (streams need Node 22+, Bun, or a `WebSocket` you pass in). If an AI agent writes the code, give it [agents.md](agents.md).
8
+
9
+ ## Quick start
10
+
11
+ ```ts
12
+ import { BinanceProvider, rsi } from 'tickwire';
13
+
14
+ const binance = new BinanceProvider();
15
+
16
+ // The latest 200 hourly candles, oldest first
17
+ const candles = await binance.getCandles('BTC/USDT', '1h', { limit: 200 });
18
+ console.log(rsi(candles.map((c) => c.close), 14).at(-1));
19
+
20
+ // Best bid/ask and last price
21
+ const quote = await binance.getQuote('BTC/USDT');
22
+ ```
23
+
24
+ Instruments are written `BASE/QUOTE` for crypto pairs (`BTC/USD`, `ETH/USDT`) and by ticker for stocks (`AAPL`). Each provider translates them into its own symbols. Timeframes are `1m`, `5m`, `1h`, `4h`, `1d`, `1w`, `1M`… (each provider lists what it supports in `provider.capabilities`).
25
+
26
+ ## Series and cache
27
+
28
+ ```ts
29
+ import { BinanceProvider, FileStore, loadCandles, checkCandles } from 'tickwire';
30
+
31
+ const store = new FileStore('.tickwire'); // JSON Lines files, readable by DuckDB, Polars or jq
32
+ const candles = await loadCandles({
33
+ provider: new BinanceProvider(),
34
+ instrument: 'ETH/USDT',
35
+ timeframe: '1h',
36
+ from: '6mo', // or a date
37
+ store, // the next call only fetches the hours that closed since
38
+ });
39
+ checkCandles(candles, '1h'); // { gaps, duplicates, unordered, misaligned, … }
40
+ ```
41
+
42
+ `liveCandles({ provider, instrument, timeframe, history: 200, store })` gives one continuous stream: the closed history first, then live updates. If the connection drops and periods are missed, they are fetched from the history API and emitted in order before going on.
43
+
44
+ ## Watchers
45
+
46
+ ```ts
47
+ import { BinanceProvider, watch, rsi, appendJsonl } from 'tickwire';
48
+
49
+ const log = appendJsonl('alerts.jsonl');
50
+ for await (const event of watch({
51
+ provider: new BinanceProvider(),
52
+ instruments: ['BTC/USDT', 'ETH/USDT', 'SOL/USDT'],
53
+ timeframe: '15m',
54
+ name: 'oversold',
55
+ when: ({ closes, candle }) => (rsi(closes, 14).at(-1) ?? 50) < 30 && { rsi: rsi(closes, 14).at(-1), price: candle.close },
56
+ })) {
57
+ await log(event); // or postJson(webhookUrl)
58
+ }
59
+ ```
60
+
61
+ A watcher fires when its condition becomes true and waits for it to turn false before firing again (`mode: 'every'` to change that, `cooldownMs` to space triggers). It checks closed candles by default, or every live update with `on: 'update'`. It uses next to no CPU, so one process can watch dozens of markets around the clock.
62
+
63
+ ## Command line
64
+
65
+ ```sh
66
+ tickwire candles binance BTC/USDT 1h --since 7d # JSON summary + candles
67
+ tickwire candles alpaca AAPL 1d --since 1y --format csv
68
+ tickwire check coinbase ETH/USD 1h --since 30d # gaps and duplicates
69
+ tickwire quote kraken BTC/USD
70
+ ```
71
+
72
+ Output is JSON on stdout, errors are JSON on stderr. Candles go through the same cache (`$TICKWIRE_CACHE`, default `~/.cache/tickwire`).
73
+
74
+ ## History over a range
75
+
76
+ ```ts
77
+ import { CoinbaseProvider } from 'tickwire';
78
+
79
+ const coinbase = new CoinbaseProvider();
80
+ const november = await coinbase.getCandles('ETH/USD', '1h', {
81
+ from: '2026-11-01T00:00:00Z',
82
+ to: '2026-11-30T23:00:00Z',
83
+ }); // paged for you, within the provider's rate limit
84
+ ```
85
+
86
+ ## Live trades
87
+
88
+ ```ts
89
+ import { KrakenProvider } from 'tickwire';
90
+
91
+ const kraken = new KrakenProvider();
92
+ const trades = kraken.streamTrades('BTC/USD', {
93
+ onStatus: (s) => console.log(s.type), // connecting, open, reconnecting, closed
94
+ });
95
+
96
+ for await (const trade of trades) {
97
+ console.log(trade.time, trade.side, trade.size, trade.price);
98
+ if (trade.size > 1) break; // breaking out of the loop closes the connection
99
+ }
100
+ ```
101
+
102
+ `streamCandles(instrument, timeframe)` works the same way: you get the running candle on every update, then the same candle with `closed: true` when its period ends. Stop a stream with `break`, `stream.close()`, or an `AbortSignal` (`{ signal }`).
103
+
104
+ ## Indicators
105
+
106
+ Every indicator exists in two forms: a batch function over an array, and a class you feed one value at a time.
107
+
108
+ ```ts
109
+ import { EMA, macd, bollinger, ATR } from 'tickwire';
110
+
111
+ const closes = candles.map((c) => c.close);
112
+ macd(closes); // [undefined, …, { macd, signal, histogram }]
113
+ bollinger(closes, { period: 20, stdDev: 2 });
114
+
115
+ const ema = new EMA(21);
116
+ for await (const candle of binance.streamCandles('BTC/USDT', '1m')) {
117
+ if (candle.closed) console.log(ema.next(candle.close));
118
+ }
119
+ ```
120
+
121
+ Available: `SMA`, `EMA`, `RSI` (Wilder), `MACD`, `BollingerBands`, `ATR` (Wilder), `VWAP` (daily or unanchored). Values are `undefined` while an indicator warms up.
122
+
123
+ ## Backtest
124
+
125
+ ```ts
126
+ import { backtest, SMA } from 'tickwire';
127
+
128
+ const fast = new SMA(10);
129
+ const slow = new SMA(40);
130
+
131
+ const { metrics, trades } = backtest({
132
+ candles, // closed candles, oldest first
133
+ initialCash: 10_000,
134
+ feeRate: 0.001, // 0.1 % per fill
135
+ slippage: 0.0005,
136
+ strategy: (ctx) => {
137
+ const f = fast.next(ctx.candle.close);
138
+ const s = slow.next(ctx.candle.close);
139
+ if (f === undefined || s === undefined) return;
140
+ if (f > s && ctx.position === 0) ctx.buy();
141
+ if (f < s && ctx.position > 0) ctx.sell();
142
+ },
143
+ });
144
+
145
+ console.log(metrics); // totalReturn, maxDrawdown, sharpe, winRate, trades, totalFees, exposure…
146
+ ```
147
+
148
+ The strategy runs after each candle closes, and its orders fill at the **next** candle's open: a strategy cannot trade on a price it has not seen. `ctx.lookback(n)` returns past candles only. Positions are long only in 0.1.
149
+
150
+ More in [`examples/`](../examples).
151
+
152
+ ## Providers
153
+
154
+ | Provider | Key needed | Markets | Streams |
155
+ |---|---|---|---|
156
+ | `BinanceProvider` | no | crypto spot | trades, candles |
157
+ | `CoinbaseProvider` | no | crypto spot | trades, candles (built from trades) |
158
+ | `KrakenProvider` | no | crypto spot (latest 720 candles per timeframe) | trades, candles |
159
+ | `AlpacaProvider` | free Alpaca key (`APCA_API_KEY_ID`, `APCA_API_SECRET_KEY`) | US stocks, IEX feed on the free plan | trades, 1-minute bars |
160
+
161
+ **Your use of each source is governed by that provider's terms, not by TickWire.** Most of them limit market data to personal, research or internal use, forbid redistributing it, and are not available in every country. TickWire hosts and redistributes no data, and is not affiliated with or endorsed by any provider. Read [docs/providers.md](providers.md) for each provider's endpoints, rate limits and terms before you use it.
162
+
163
+ ## Errors
164
+
165
+ Everything thrown by TickWire extends `TickwireError`:
166
+
167
+ | Error | When |
168
+ |---|---|
169
+ | `InvalidArgumentError` | bad timeframe, instrument or range |
170
+ | `NotSupportedError` | the provider does not offer this timeframe or market |
171
+ | `AuthenticationError` | missing or rejected API key |
172
+ | `RateLimitError` | the provider rate-limited you (`retryAfterMs` when known) |
173
+ | `NetworkError` | the provider could not be reached or timed out |
174
+ | `ProviderError` | the provider returned an error (`status`, `code`) or an unexpected payload |
175
+
176
+ Requests are retried on network errors, 5xx and 429 answers (twice by default, `retries` option), honouring `Retry-After`.
177
+
178
+ ## Development
179
+
180
+ ```sh
181
+ npm install
182
+ npm run typecheck && npm run lint && npm test && npm run build
183
+ ```
184
+
185
+ Tests run offline against responses recorded from the real APIs (`tests/fixtures`, refreshed with `npm run fixtures:record`). Live checks are opt-in: `npm run test:live`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tickwire",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Market toolkit for AI agents that write code: reliable candle series with a local cache, 24/7 watchers, indicators and backtests on official exchange and broker APIs.",
5
5
  "license": "ISC",
6
6
  "author": "Mathieu Colmon",