mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 01:08:07 +00:00
feat: 在文档中添加 CLI 参数说明,支持通过命令行临时指定交易所
This commit is contained in:
@@ -72,6 +72,12 @@ curl -fsSL https://github.com/discountry/ritmex-bot/raw/refs/heads/main/setup.sh
|
|||||||
|
|
||||||
切换到 GRVT 时,将 `EXCHANGE=grvt` 并补齐 `GRVT_API_KEY`、`GRVT_API_SECRET`、`GRVT_SUB_ACCOUNT_ID` 等变量;详情见 `.env.example`。
|
切换到 GRVT 时,将 `EXCHANGE=grvt` 并补齐 `GRVT_API_KEY`、`GRVT_API_SECRET`、`GRVT_SUB_ACCOUNT_ID` 等变量;详情见 `.env.example`。
|
||||||
|
|
||||||
|
> 提示:你也可以通过命令行参数临时指定交易所(优先级高于环境变量):
|
||||||
|
> ```bash
|
||||||
|
> bun run index.ts --exchange grvt
|
||||||
|
> bun run index.ts -e lighter
|
||||||
|
> ```
|
||||||
|
|
||||||
## 常用命令
|
## 常用命令
|
||||||
```bash
|
```bash
|
||||||
bun run index.ts # 启动 CLI(默认)
|
bun run index.ts # 启动 CLI(默认)
|
||||||
@@ -90,6 +96,13 @@ bun run index.ts --strategy maker --silent # 启动做市策略
|
|||||||
bun run index.ts --strategy offset-maker --silent # 启动偏移做市策略
|
bun run index.ts --strategy offset-maker --silent # 启动偏移做市策略
|
||||||
```
|
```
|
||||||
|
|
||||||
|
如需同时指定交易所,可叠加 `--exchange/-e`(将覆盖 `.env` 中的 `EXCHANGE`/`TRADE_EXCHANGE`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun run index.ts --exchange grvt --strategy maker --silent
|
||||||
|
bun run index.ts -e lighter -s offset-maker --silent
|
||||||
|
```
|
||||||
|
|
||||||
### 项目内置脚本
|
### 项目内置脚本
|
||||||
`package.json` 提供了便捷脚本:
|
`package.json` 提供了便捷脚本:
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,12 @@ The most important settings shipped in `.env.example` are summarised below:
|
|||||||
|
|
||||||
To trade on GRVT, set `EXCHANGE=grvt` and populate `GRVT_API_KEY`, `GRVT_API_SECRET`, `GRVT_SUB_ACCOUNT_ID`, plus any optional overrides documented in `.env.example`.
|
To trade on GRVT, set `EXCHANGE=grvt` and populate `GRVT_API_KEY`, `GRVT_API_SECRET`, `GRVT_SUB_ACCOUNT_ID`, plus any optional overrides documented in `.env.example`.
|
||||||
|
|
||||||
|
> Tip: you can temporarily override the exchange via CLI flags (takes precedence over environment):
|
||||||
|
> ```bash
|
||||||
|
> bun run index.ts --exchange grvt
|
||||||
|
> bun run index.ts -e lighter
|
||||||
|
> ```
|
||||||
|
|
||||||
## Common Commands
|
## Common Commands
|
||||||
```bash
|
```bash
|
||||||
bun run index.ts # Launch the CLI
|
bun run index.ts # Launch the CLI
|
||||||
@@ -87,6 +93,13 @@ bun run index.ts --strategy maker --silent # Maker engine
|
|||||||
bun run index.ts --strategy offset-maker --silent # Offset maker engine
|
bun run index.ts --strategy offset-maker --silent # Offset maker engine
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Combine with `--exchange/-e` to explicitly choose the venue (overrides `EXCHANGE`/`TRADE_EXCHANGE` from `.env`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun run index.ts --exchange grvt --strategy maker --silent
|
||||||
|
bun run index.ts -e lighter -s offset-maker --silent
|
||||||
|
```
|
||||||
|
|
||||||
### Package scripts
|
### Package scripts
|
||||||
Convenience aliases are exposed in `package.json`:
|
Convenience aliases are exposed in `package.json`:
|
||||||
|
|
||||||
|
|||||||
+26
-1
@@ -4,6 +4,7 @@ export interface CliOptions {
|
|||||||
strategy?: StrategyId;
|
strategy?: StrategyId;
|
||||||
silent: boolean;
|
silent: boolean;
|
||||||
help: boolean;
|
help: boolean;
|
||||||
|
exchange?: "aster" | "grvt" | "lighter";
|
||||||
}
|
}
|
||||||
|
|
||||||
const STRATEGY_VALUES = new Set<StrategyId>(["trend", "maker", "offset-maker"]);
|
const STRATEGY_VALUES = new Set<StrategyId>(["trend", "maker", "offset-maker"]);
|
||||||
@@ -36,6 +37,19 @@ export function parseCliArgs(argv: string[] = process.argv.slice(2)): CliOptions
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (arg.startsWith("--exchange=")) {
|
||||||
|
const value = arg.split("=", 2)[1] ?? "";
|
||||||
|
assignExchange(options, value);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (arg === "--exchange" || arg === "-e") {
|
||||||
|
const value = argv[i + 1];
|
||||||
|
if (value) {
|
||||||
|
assignExchange(options, value);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
@@ -51,12 +65,23 @@ function assignStrategy(options: CliOptions, raw: string): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function assignExchange(options: CliOptions, raw: string): void {
|
||||||
|
const normalized = raw.trim().toLowerCase();
|
||||||
|
if (!normalized) return;
|
||||||
|
if (normalized === "aster" || normalized === "grvt" || normalized === "lighter") {
|
||||||
|
options.exchange = normalized as CliOptions["exchange"];
|
||||||
|
} else if (normalized === "gravity" || normalized === "grav" || normalized === "grv") {
|
||||||
|
options.exchange = "grvt";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function printCliHelp(): void {
|
export function printCliHelp(): void {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(`Usage: bun run index.ts [--strategy <trend|maker|offset-maker>] [--silent]\n\n` +
|
console.log(`Usage: bun run index.ts [--strategy <trend|maker|offset-maker>] [--exchange <aster|grvt|lighter>] [--silent]\n\n` +
|
||||||
`Options:\n` +
|
`Options:\n` +
|
||||||
` --strategy, -s Automatically start the specified strategy without the interactive menu.\n` +
|
` --strategy, -s Automatically start the specified strategy without the interactive menu.\n` +
|
||||||
` Aliases: offset, offset-maker for the offset maker engine.\n` +
|
` Aliases: offset, offset-maker for the offset maker engine.\n` +
|
||||||
|
` --exchange, -e Choose exchange. Overrides EXCHANGE/TRADE_EXCHANGE environment variables.\n` +
|
||||||
` --silent, -q Reduce console output. When used with --strategy, runs in silent daemon mode.\n` +
|
` --silent, -q Reduce console output. When used with --strategy, runs in silent daemon mode.\n` +
|
||||||
` --help, -h Show this help message.\n`);
|
` --help, -h Show this help message.\n`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,17 @@ import { App } from "./ui/App";
|
|||||||
import { setupGlobalErrorHandlers } from "./runtime-errors";
|
import { setupGlobalErrorHandlers } from "./runtime-errors";
|
||||||
import { parseCliArgs, printCliHelp } from "./cli/args";
|
import { parseCliArgs, printCliHelp } from "./cli/args";
|
||||||
import { startStrategy } from "./cli/strategy-runner";
|
import { startStrategy } from "./cli/strategy-runner";
|
||||||
|
import { resolveExchangeId } from "./exchanges/create-adapter";
|
||||||
|
|
||||||
setupGlobalErrorHandlers();
|
setupGlobalErrorHandlers();
|
||||||
const options = parseCliArgs();
|
const options = parseCliArgs();
|
||||||
|
// If user specifies --exchange, override environment-based resolution for this process
|
||||||
|
if (options.exchange) {
|
||||||
|
// Ensure downstream calls to resolveExchangeId() pick the CLI value.
|
||||||
|
// We set both common env keys respected by resolveExchangeId.
|
||||||
|
process.env.EXCHANGE = options.exchange;
|
||||||
|
process.env.TRADE_EXCHANGE = options.exchange;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.help) {
|
if (options.help) {
|
||||||
printCliHelp();
|
printCliHelp();
|
||||||
|
|||||||
+12
-4
@@ -4,6 +4,7 @@ import { TrendApp } from "./TrendApp";
|
|||||||
import { MakerApp } from "./MakerApp";
|
import { MakerApp } from "./MakerApp";
|
||||||
import { OffsetMakerApp } from "./OffsetMakerApp";
|
import { OffsetMakerApp } from "./OffsetMakerApp";
|
||||||
import { loadCopyrightFragments, verifyCopyrightIntegrity } from "../utils/copyright";
|
import { loadCopyrightFragments, verifyCopyrightIntegrity } from "../utils/copyright";
|
||||||
|
import { resolveExchangeId } from "../exchanges/create-adapter";
|
||||||
|
|
||||||
interface StrategyOption {
|
interface StrategyOption {
|
||||||
id: "trend" | "maker" | "offset-maker";
|
id: "trend" | "maker" | "offset-maker";
|
||||||
@@ -40,16 +41,23 @@ export function App() {
|
|||||||
const [selected, setSelected] = useState<StrategyOption | null>(null);
|
const [selected, setSelected] = useState<StrategyOption | null>(null);
|
||||||
const copyright = useMemo(() => loadCopyrightFragments(), []);
|
const copyright = useMemo(() => loadCopyrightFragments(), []);
|
||||||
const integrityOk = useMemo(() => verifyCopyrightIntegrity(), []);
|
const integrityOk = useMemo(() => verifyCopyrightIntegrity(), []);
|
||||||
|
const exchangeId = useMemo(() => resolveExchangeId(), []);
|
||||||
|
const strategies = useMemo(() => {
|
||||||
|
if (exchangeId === "lighter") {
|
||||||
|
return STRATEGIES.filter((s) => s.id !== "trend");
|
||||||
|
}
|
||||||
|
return STRATEGIES;
|
||||||
|
}, [exchangeId]);
|
||||||
|
|
||||||
useInput(
|
useInput(
|
||||||
(input, key) => {
|
(input, key) => {
|
||||||
if (selected) return;
|
if (selected) return;
|
||||||
if (key.upArrow) {
|
if (key.upArrow) {
|
||||||
setCursor((prev) => (prev - 1 + STRATEGIES.length) % STRATEGIES.length);
|
setCursor((prev) => (prev - 1 + strategies.length) % strategies.length);
|
||||||
} else if (key.downArrow) {
|
} else if (key.downArrow) {
|
||||||
setCursor((prev) => (prev + 1) % STRATEGIES.length);
|
setCursor((prev) => (prev + 1) % strategies.length);
|
||||||
} else if (key.return) {
|
} else if (key.return) {
|
||||||
const strategy = STRATEGIES[cursor];
|
const strategy = strategies[cursor];
|
||||||
if (strategy) {
|
if (strategy) {
|
||||||
setSelected(strategy);
|
setSelected(strategy);
|
||||||
}
|
}
|
||||||
@@ -75,7 +83,7 @@ export function App() {
|
|||||||
<Text color="cyanBright">请选择要运行的策略</Text>
|
<Text color="cyanBright">请选择要运行的策略</Text>
|
||||||
<Text color="gray">使用 ↑/↓ 选择,回车开始,Ctrl+C 退出。</Text>
|
<Text color="gray">使用 ↑/↓ 选择,回车开始,Ctrl+C 退出。</Text>
|
||||||
<Box flexDirection="column" marginTop={1}>
|
<Box flexDirection="column" marginTop={1}>
|
||||||
{STRATEGIES.map((strategy, index) => {
|
{strategies.map((strategy, index) => {
|
||||||
const active = index === cursor;
|
const active = index === cursor;
|
||||||
return (
|
return (
|
||||||
<Box key={strategy.id} flexDirection="column" marginBottom={1}>
|
<Box key={strategy.id} flexDirection="column" marginBottom={1}>
|
||||||
|
|||||||
Reference in New Issue
Block a user