diff --git a/.gitignore b/.gitignore index da16e3c2..c47915a5 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,7 @@ tarpaulin-report.html *.local.toml # Node binding artifacts -bindings/node/node_modules/ +**/node_modules/ bindings/node/*.node bindings/node/index.d.ts bindings/node/npm-debug.log* diff --git a/README.md b/README.md index 41861645..ac94e1c8 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ inherit it automatically. | Binding | Install | Example | |-------------------|-----------------------------------------------|---------| | 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` | | Rust | `cargo add wickra` | `examples/rust/src/bin/backtest.rs` | @@ -186,12 +186,13 @@ wickra/ │ └── wickra-data/ CSV reader, tick aggregator, live exchange feeds ├── bindings/ │ ├── 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/ ├── examples/ examples/README.md indexes every language │ ├── data/ real BTCUSDT OHLCV datasets, one per timeframe │ ├── 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 ``` diff --git a/bindings/node/package.json b/bindings/node/package.json index a82efa8d..13dad6d7 100644 --- a/bindings/node/package.json +++ b/bindings/node/package.json @@ -63,7 +63,6 @@ "test": "node --test __tests__/" }, "devDependencies": { - "@napi-rs/cli": "^2.18.0", - "ws": "^8.18.0" + "@napi-rs/cli": "^2.18.0" } } diff --git a/examples/README.md b/examples/README.md index df354285..a17c134f 100644 --- a/examples/README.md +++ b/examples/README.md @@ -26,15 +26,20 @@ The Rust examples live in the `wickra-examples` workspace member crate. `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 | | --- | --- | --- | -| `streaming.js` | Feed a synthetic price series through several indicators tick by tick. | `node examples/streaming.js` | -| `backtest.js` | Basket of indicators over an OHLCV CSV; defaults to the bundled BTCUSDT daily dataset. | `node examples/backtest.js [ohlcv.csv]` | -| `live_trading.js` | Live Binance feed → RSI / MACD / Bollinger → signals. | `node examples/live_trading.js --symbol BTCUSDT --interval 1m` | +| `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 backtest.js [ohlcv.csv]` | +| `live_trading.js` | Live Binance feed → RSI / MACD / Bollinger → signals. | `node live_trading.js --symbol BTCUSDT --interval 1m` | ## WebAssembly — `bindings/wasm/examples/` diff --git a/bindings/node/examples/backtest.js b/examples/node/backtest.js similarity index 89% rename from bindings/node/examples/backtest.js rename to examples/node/backtest.js index 18a09a2b..103c373f 100644 --- a/bindings/node/examples/backtest.js +++ b/examples/node/backtest.js @@ -4,23 +4,19 @@ // (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 // 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 -// npm install -// npx napi build --platform --release -// node examples/backtest.js # uses the bundled BTCUSDT 1d data -// 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. +// cd bindings/node && npm install && npx napi build --platform --release +// cd ../../examples/node && npm install +// node backtest.js # uses the bundled BTCUSDT 1d data +// node backtest.js path/to/ohlcv.csv # or any OHLCV CSV const fs = require('node:fs'); const path = require('node:path'); -const wickra = require('..'); +const wickra = require('wickra'); // The OHLCV columns the default layout requires; the CSV header must name // 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 // `examples/data/` directory, resolved relative to this file. -const DEFAULT_CSV = path.join( - __dirname, - '..', - '..', - '..', - 'examples', - 'data', - 'btcusdt-1d.csv', -); +const DEFAULT_CSV = path.join(__dirname, '..', 'data', 'btcusdt-1d.csv'); // Parse an OHLCV CSV into column arrays of numbers. // diff --git a/bindings/node/examples/live_trading.js b/examples/node/live_trading.js similarity index 93% rename from bindings/node/examples/live_trading.js rename to examples/node/live_trading.js index f636d524..b24e26c5 100644 --- a/bindings/node/examples/live_trading.js +++ b/examples/node/live_trading.js @@ -7,22 +7,21 @@ // signal line is printed. No orders are placed. It is the Node counterpart of // 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 -// npm install # also installs the `ws` dev-dependency -// npx napi build --platform --release -// node examples/live_trading.js --symbol BTCUSDT --interval 1m +// cd bindings/node && npm install && npx napi build --platform --release +// cd ../../examples/node && npm install # pulls `ws` for this example +// node live_trading.js --symbol BTCUSDT --interval 1m // // Stop it with Ctrl+C. -const wickra = require('..'); +const wickra = require('wickra'); let WebSocket; try { WebSocket = require('ws'); } 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); } diff --git a/examples/node/package.json b/examples/node/package.json new file mode 100644 index 00000000..cb469cef --- /dev/null +++ b/examples/node/package.json @@ -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" + } +} diff --git a/bindings/node/examples/streaming.js b/examples/node/streaming.js similarity index 86% rename from bindings/node/examples/streaming.js rename to examples/node/streaming.js index eb4b3b92..ea439346 100644 --- a/bindings/node/examples/streaming.js +++ b/examples/node/streaming.js @@ -4,17 +4,13 @@ // the same O(1)-per-update model a live trading bot would use — and prints a // 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 -// npm install -// npx napi build --platform --release -// node examples/streaming.js -// -// In your own project, install the package and use `require('wickra')` -// instead of the relative `require('..')` below. +// cd bindings/node && npm install && npx napi build --platform --release +// cd ../../examples/node && npm install +// node streaming.js -const wickra = require('..'); +const wickra = require('wickra'); // 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).