Skip to content

Commit ce15575

Browse files
maxgfrclaude
andcommitted
feat: add CLI arguments and binary compilation
- Add CLI flags: --pair, --interval, --start, --end, --output - Support non-interactive mode when all arguments provided - Support hybrid mode with partial arguments - Add input validation (dates, intervals) - Configure pkg for binary compilation (macOS, Linux, Windows) - Add GitHub workflow to build and release binaries - Update README with new CLI usage examples Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 83a6c7f commit ce15575

File tree

6 files changed

+855
-40
lines changed

6 files changed

+855
-40
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Build and Release Binaries
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: 'Release tag to attach binaries to'
10+
required: true
11+
type: string
12+
13+
permissions:
14+
contents: write
15+
16+
jobs:
17+
build-binaries:
18+
strategy:
19+
matrix:
20+
include:
21+
- os: ubuntu-latest
22+
target: node20-linux-x64
23+
output: binance-historical-linux-x64
24+
- os: macos-latest
25+
target: node20-macos-x64
26+
output: binance-historical-macos-x64
27+
- os: macos-latest
28+
target: node20-macos-arm64
29+
output: binance-historical-macos-arm64
30+
- os: windows-latest
31+
target: node20-win-x64
32+
output: binance-historical-win-x64.exe
33+
34+
runs-on: ${{ matrix.os }}
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v6
38+
39+
- name: Set up Node.js
40+
uses: actions/setup-node@v6
41+
with:
42+
node-version: '20'
43+
cache: 'yarn'
44+
45+
- name: Install dependencies
46+
run: yarn install --frozen-lockfile
47+
48+
- name: Build TypeScript
49+
run: yarn build
50+
51+
- name: Build binary
52+
run: yarn pkg . --target ${{ matrix.target }} --output dist/${{ matrix.output }}
53+
54+
- name: Upload artifact
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: ${{ matrix.output }}
58+
path: dist/${{ matrix.output }}
59+
60+
upload-to-release:
61+
needs: build-binaries
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Download all artifacts
65+
uses: actions/download-artifact@v4
66+
with:
67+
path: dist
68+
69+
- name: Display structure of downloaded files
70+
run: ls -la dist/
71+
72+
- name: Get release tag
73+
id: get_tag
74+
run: |
75+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
76+
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
77+
else
78+
echo "tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
79+
fi
80+
81+
- name: Create checksums
82+
run: |
83+
cd dist
84+
for dir in */; do
85+
for file in "$dir"*; do
86+
if [ -f "$file" ]; then
87+
sha256sum "$file" >> checksums.txt
88+
fi
89+
done
90+
done
91+
cat checksums.txt
92+
93+
- name: Upload binaries to release
94+
uses: softprops/action-gh-release@v2
95+
with:
96+
tag_name: ${{ steps.get_tag.outputs.tag }}
97+
files: |
98+
dist/binance-historical-linux-x64/binance-historical-linux-x64
99+
dist/binance-historical-macos-x64/binance-historical-macos-x64
100+
dist/binance-historical-macos-arm64/binance-historical-macos-arm64
101+
dist/binance-historical-win-x64.exe/binance-historical-win-x64.exe
102+
dist/checksums.txt
103+
env:
104+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ node_modules/
2121
# Transpiled files
2222
build/
2323

24+
# Binary distribution
25+
dist/
26+
2427
# .env you know
2528
.env
2629

README.md

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,70 @@ Utility to retrieve historical data from Binance
44

55
![Alt Text](https://raw.githubusercontent.com/maxgfr/binance-historical/main/.github/assets/main.gif)
66

7-
## Usage
7+
## Installation
88

9-
### With the cli
9+
### Via Homebrew (macOS/Linux)
10+
11+
```sh
12+
brew tap maxgfr/tap
13+
brew install binance-historical
14+
```
15+
16+
### Via npm
1017

1118
```sh
1219
npm install -g binance-historical
20+
```
21+
22+
### Download binary
23+
24+
Download the latest binary for your platform from the [releases page](https://github.com/maxgfr/binance-historical/releases).
25+
26+
## Usage
27+
28+
### CLI
29+
30+
#### Interactive mode
31+
32+
```sh
1333
binance-historical download
34+
```
35+
36+
#### Non-interactive mode
37+
38+
Pass all options as arguments:
39+
40+
```sh
41+
binance-historical download \
42+
--pair BTCUSDT \
43+
--interval 4h \
44+
--start 2024-01-01 \
45+
--end 2024-12-31 \
46+
--output ./data/
47+
```
48+
49+
#### CLI Options
50+
51+
| Option | Alias | Description |
52+
|--------|-------|-------------|
53+
| `--pair <symbol>` | `-p` | Trading pair (e.g., BTCUSDT, ETHUSDT) |
54+
| `--interval <interval>` | `-i` | Kline interval (1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w) |
55+
| `--start <date>` | `-s` | Start date (YYYY-MM-DD or ISO 8601) |
56+
| `--end <date>` | `-e` | End date (YYYY-MM-DD or ISO 8601) |
57+
| `--output <path>` | `-o` | Output directory path (filename is auto-generated) |
58+
| `--help` | `-h` | Display help |
59+
| `--version` | `-V` | Display version |
1460

15-
# or by using npx
16-
npx binance-historical download
61+
#### Hybrid mode
62+
63+
You can also provide some options and be prompted for the rest:
64+
65+
```sh
66+
binance-historical download --pair ETHUSDT --interval 1h
67+
# You will be prompted for start date, end date, and output path
1768
```
1869

19-
### With the library
70+
### Library
2071

2172
```ts
2273
import { getKline, Kline } from 'binance-historical';

package.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
"bin": {
2020
"binance-historical": "./build/index.js"
2121
},
22+
"pkg": {
23+
"scripts": "build/**/*.js",
24+
"assets": [
25+
"node_modules/axios/dist/node/axios.cjs"
26+
],
27+
"targets": [
28+
"node20-macos-x64",
29+
"node20-macos-arm64",
30+
"node20-linux-x64",
31+
"node20-win-x64"
32+
],
33+
"outputPath": "dist"
34+
},
2235
"keywords": [
2336
"node",
2437
"typescript",
@@ -42,14 +55,20 @@
4255
"build:swc:watch": "npm run build:swc -- -w",
4356
"lint": "eslint ./src --ext .ts",
4457
"prettier": "prettier --write './src/**/*.{ts,js,json}'",
45-
"release": "semantic-release"
58+
"release": "semantic-release",
59+
"build:binaries": "pkg . --out-path dist",
60+
"build:binary:macos": "pkg . --target node20-macos-x64 --output dist/binance-historical-macos-x64",
61+
"build:binary:macos-arm": "pkg . --target node20-macos-arm64 --output dist/binance-historical-macos-arm64",
62+
"build:binary:linux": "pkg . --target node20-linux-x64 --output dist/binance-historical-linux-x64",
63+
"build:binary:win": "pkg . --target node20-win-x64 --output dist/binance-historical-win-x64.exe"
4664
},
4765
"dependencies": {
4866
"axios": "1.13.2",
4967
"commander": "^12.0.0",
5068
"prompts": "2.4.2"
5169
},
5270
"devDependencies": {
71+
"@yao-pkg/pkg": "^6.3.0",
5372
"@semantic-release/commit-analyzer": "^12.0.0",
5473
"@semantic-release/git": "^10.0.1",
5574
"@semantic-release/github": "10.3.5",

0 commit comments

Comments
 (0)