examples: move Node examples into a top-level examples/node/

Continue the per-language `examples/<lang>/` restructure: move the three
Node example files (streaming.js, backtest.js, live_trading.js) out of
bindings/node/examples/ and into a top-level examples/node/ directory.

* `examples/node/package.json` is a `private` package that pulls the
  native binding via `file:../../bindings/node` and lists `ws` as a
  dev-dependency for the live-trading example. `require('..')` in each
  file becomes `require('wickra')` — exactly what a downstream user would
  write — and the file-header run instructions are updated to the new
  two-step workflow (`npm install` in bindings/node, then in
  examples/node).
* `backtest.js`'s default-CSV path becomes the much shorter
  `__dirname/../data/btcusdt-1d.csv` from the new location.
* `bindings/node/package.json` drops the now-unused `ws` devDependency.
* `.gitignore` is broadened from `bindings/node/node_modules/` to
  `**/node_modules/` so the new `examples/node/node_modules/` directory is
  not tracked.
* The README "Languages" table, project-layout block and
  `examples/README.md` Node section are updated for the new paths and run
  commands.

Verified by running `node backtest.js` (3200 BTCUSDT daily bars, matching
output), `node streaming.js`, and `node --check live_trading.js` from the
new location.
This commit is contained in:
kingchenc
2026-05-23 00:10:06 +02:00
parent 747d1a5b1b
commit 8b9e8e30b9
8 changed files with 48 additions and 47 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ tarpaulin-report.html
*.local.toml *.local.toml
# Node binding artifacts # Node binding artifacts
bindings/node/node_modules/ **/node_modules/
bindings/node/*.node bindings/node/*.node
bindings/node/index.d.ts bindings/node/index.d.ts
bindings/node/npm-debug.log* bindings/node/npm-debug.log*
+4 -3
View File
@@ -118,7 +118,7 @@ inherit it automatically.
| Binding | Install | Example | | Binding | Install | Example |
|-------------------|-----------------------------------------------|---------| |-------------------|-----------------------------------------------|---------|
| Python (PyO3) | `pip install wickra` | `examples/python/backtest.py` | | Python (PyO3) | `pip install wickra` | `examples/python/backtest.py` |
| Node.js (napi-rs) | `npm install wickra` | `bindings/node/examples/backtest.js` | | Node.js (napi-rs) | `npm install wickra` | `examples/node/backtest.js` |
| Browser / WASM | `npm install wickra-wasm` | `bindings/wasm/examples/index.html` | | Browser / WASM | `npm install wickra-wasm` | `bindings/wasm/examples/index.html` |
| Rust | `cargo add wickra` | `examples/rust/src/bin/backtest.rs` | | Rust | `cargo add wickra` | `examples/rust/src/bin/backtest.rs` |
@@ -186,12 +186,13 @@ wickra/
│ └── wickra-data/ CSV reader, tick aggregator, live exchange feeds │ └── wickra-data/ CSV reader, tick aggregator, live exchange feeds
├── bindings/ ├── bindings/
│ ├── python/ PyO3 + maturin (publishes on PyPI) │ ├── python/ PyO3 + maturin (publishes on PyPI)
│ ├── node/ napi-rs (publishes on npm) + examples/ │ ├── node/ napi-rs (publishes on npm)
│ └── wasm/ wasm-bindgen (browsers, bundlers, Node) + examples/ │ └── wasm/ wasm-bindgen (browsers, bundlers, Node) + examples/
├── examples/ examples/README.md indexes every language ├── examples/ examples/README.md indexes every language
│ ├── data/ real BTCUSDT OHLCV datasets, one per timeframe │ ├── data/ real BTCUSDT OHLCV datasets, one per timeframe
│ ├── rust/ Rust workspace member (`wickra-examples`) │ ├── rust/ Rust workspace member (`wickra-examples`)
── python/ backtest, live trading, parallel assets, multi-tf ── python/ backtest, live trading, parallel assets, multi-tf
│ └── node/ streaming, backtest, live trading (load `wickra`)
└── .github/workflows/ CI and release pipelines └── .github/workflows/ CI and release pipelines
``` ```
+1 -2
View File
@@ -63,7 +63,6 @@
"test": "node --test __tests__/" "test": "node --test __tests__/"
}, },
"devDependencies": { "devDependencies": {
"@napi-rs/cli": "^2.18.0", "@napi-rs/cli": "^2.18.0"
"ws": "^8.18.0"
} }
} }
+10 -5
View File
@@ -26,15 +26,20 @@ The Rust examples live in the `wickra-examples` workspace member crate.
`live_trading.py` additionally needs `pip install websockets`. `live_trading.py` additionally needs `pip install websockets`.
## Node.js — `bindings/node/examples/` ## Node.js — `examples/node/`
Build the native module first: `cd bindings/node && npm install && npx napi build --platform --release`. Build the native binding once, then link it into the examples directory:
```bash
cd bindings/node && npm install && npx napi build --platform --release
cd ../../examples/node && npm install # links wickra + installs `ws`
```
| Example | What it does | Run | | Example | What it does | Run |
| --- | --- | --- | | --- | --- | --- |
| `streaming.js` | Feed a synthetic price series through several indicators tick by tick. | `node examples/streaming.js` | | `streaming.js` | Feed a synthetic price series through several indicators tick by tick. | `node streaming.js` |
| `backtest.js` | Basket of indicators over an OHLCV CSV; defaults to the bundled BTCUSDT daily dataset. | `node examples/backtest.js [ohlcv.csv]` | | `backtest.js` | Basket of indicators over an OHLCV CSV; defaults to the bundled BTCUSDT daily dataset. | `node backtest.js [ohlcv.csv]` |
| `live_trading.js` | Live Binance feed → RSI / MACD / Bollinger → signals. | `node examples/live_trading.js --symbol BTCUSDT --interval 1m` | | `live_trading.js` | Live Binance feed → RSI / MACD / Bollinger → signals. | `node live_trading.js --symbol BTCUSDT --interval 1m` |
## WebAssembly — `bindings/wasm/examples/` ## WebAssembly — `bindings/wasm/examples/`
@@ -4,23 +4,19 @@
// (SMA, EMA, RSI, MACD, Bollinger Bands, ATR, ADX, OBV) with the O(1) // (SMA, EMA, RSI, MACD, Bollinger Bands, ATR, ADX, OBV) with the O(1)
// `update` call, and prints a summary of each resulting series. It is the // `update` call, and prints a summary of each resulting series. It is the
// Node counterpart of `examples/python/backtest.py` and the Rust // Node counterpart of `examples/python/backtest.py` and the Rust
// `crates/wickra/examples/backtest.rs`. // `examples/rust/src/bin/backtest.rs`.
// //
// Run it from the repository after building the native module: // Run it from the repository after building the native binding:
// //
// cd bindings/node // cd bindings/node && npm install && npx napi build --platform --release
// npm install // cd ../../examples/node && npm install
// npx napi build --platform --release // node backtest.js # uses the bundled BTCUSDT 1d data
// node examples/backtest.js # uses the bundled BTCUSDT 1d data // node backtest.js path/to/ohlcv.csv # or any OHLCV CSV
// node examples/backtest.js path/to/ohlcv.csv # or any OHLCV CSV
//
// In your own project, install the package and use `require('wickra')`
// instead of the relative `require('..')` below.
const fs = require('node:fs'); const fs = require('node:fs');
const path = require('node:path'); const path = require('node:path');
const wickra = require('..'); const wickra = require('wickra');
// The OHLCV columns the default layout requires; the CSV header must name // The OHLCV columns the default layout requires; the CSV header must name
// every one of them (any extra columns are ignored). // every one of them (any extra columns are ignored).
@@ -28,15 +24,7 @@ const REQUIRED_COLUMNS = ['timestamp', 'open', 'high', 'low', 'close', 'volume']
// Default dataset: the checked-in BTCUSDT daily candles under the workspace // Default dataset: the checked-in BTCUSDT daily candles under the workspace
// `examples/data/` directory, resolved relative to this file. // `examples/data/` directory, resolved relative to this file.
const DEFAULT_CSV = path.join( const DEFAULT_CSV = path.join(__dirname, '..', 'data', 'btcusdt-1d.csv');
__dirname,
'..',
'..',
'..',
'examples',
'data',
'btcusdt-1d.csv',
);
// Parse an OHLCV CSV into column arrays of numbers. // Parse an OHLCV CSV into column arrays of numbers.
// //
@@ -7,22 +7,21 @@
// signal line is printed. No orders are placed. It is the Node counterpart of // signal line is printed. No orders are placed. It is the Node counterpart of
// examples/python/live_trading.py. // examples/python/live_trading.py.
// //
// Run it from the repository after building the native module: // Run it from the repository after building the native binding:
// //
// cd bindings/node // cd bindings/node && npm install && npx napi build --platform --release
// npm install # also installs the `ws` dev-dependency // cd ../../examples/node && npm install # pulls `ws` for this example
// npx napi build --platform --release // node live_trading.js --symbol BTCUSDT --interval 1m
// node examples/live_trading.js --symbol BTCUSDT --interval 1m
// //
// Stop it with Ctrl+C. // Stop it with Ctrl+C.
const wickra = require('..'); const wickra = require('wickra');
let WebSocket; let WebSocket;
try { try {
WebSocket = require('ws'); WebSocket = require('ws');
} catch (err) { } catch (err) {
console.error('This example needs the `ws` package — run `npm install` in bindings/node.'); console.error('This example needs the `ws` package — run `npm install` in examples/node.');
process.exit(1); process.exit(1);
} }
+13
View File
@@ -0,0 +1,13 @@
{
"name": "wickra-examples-node",
"version": "0.0.0",
"private": true,
"description": "Runnable Node.js examples for the Wickra technical-analysis library.",
"license": "SEE LICENSE IN ../../LICENSE",
"dependencies": {
"wickra": "file:../../bindings/node"
},
"devDependencies": {
"ws": "^8.18.0"
}
}
@@ -4,17 +4,13 @@
// the same O(1)-per-update model a live trading bot would use — and prints a // the same O(1)-per-update model a live trading bot would use — and prints a
// status line whenever every indicator has warmed up. // status line whenever every indicator has warmed up.
// //
// Run it from the repository after building the native module: // Run it from the repository after building the native binding:
// //
// cd bindings/node // cd bindings/node && npm install && npx napi build --platform --release
// npm install // cd ../../examples/node && npm install
// npx napi build --platform --release // node streaming.js
// node examples/streaming.js
//
// In your own project, install the package and use `require('wickra')`
// instead of the relative `require('..')` below.
const wickra = require('..'); const wickra = require('wickra');
// A deterministic synthetic series: a slow trend with two oscillations and a // A deterministic synthetic series: a slow trend with two oscillations and a
// little noise from a seeded generator (so every run prints the same thing). // little noise from a seeded generator (so every run prints the same thing).