Feat/support binance (#22)

* add docs

* Add Binance exchange support

- Updated the environment configuration to include Binance as a selectable exchange option.
- Enhanced the README documentation to reflect the addition of Binance.
- Implemented the Binance exchange adapter and integrated it into the existing exchange framework.
- Modified the basis arbitrage strategy to support Binance alongside existing exchanges.
- Added tests to ensure proper functionality and integration of Binance within the trading system.

* Enhance README with detailed Binance exchange configuration

- Added comprehensive instructions for setting up Binance as an exchange option.
- Included environment variable specifications for API keys, market types, and trading symbols.
- Provided examples for both perpetual and spot trading strategies.
- Clarified the use of WebSocket and REST for the Binance adapter.

* Enhance exchange support and testing framework

- Added a new test suite for exchange contracts to ensure consistency and functionality across supported exchanges.
- Refactored exchange ID handling to utilize a centralized list of supported exchanges, improving maintainability.
- Updated CLI argument parsing and help documentation to reflect the new exchange structure.
- Introduced utility functions for validating supported exchanges and their display names.
- Enhanced the BasisApp and strategy runner to leverage the new exchange validation logic.
- Added a new test command for running exchange-related tests.

* Refactor exchange contract tests and update CLI commands

- Removed the trailing supported exchanges set and simplified the logic for trailing stop support in the exchange contract tests.
- Updated the test command for exchange contracts to exclude unnecessary tests, streamlining the testing process.
- Enhanced test descriptions for clarity and improved understanding of the functionality being tested.
This commit is contained in:
Disney
2026-02-27 11:37:44 +08:00
committed by GitHub
parent 422ee6f465
commit d6399b92aa
588 changed files with 96879 additions and 106 deletions
+33 -1
View File
@@ -86,7 +86,7 @@ curl -fsSL https://github.com/discountry/ritmex-bot/raw/refs/heads/main/setup.sh
| 变量 | 说明 |
| --- | --- |
| `EXCHANGE` | 选择交易所(`aster`/`standx`/`grvt`/`lighter`/`backpack`/`paradex`/`nado` |
| `EXCHANGE` | 选择交易所(`aster`/`binance`/`standx`/`grvt`/`lighter`/`backpack`/`paradex`/`nado` |
| `TRADE_SYMBOL` | 交易对(默认 `BTCUSDT` |
| `TRADE_AMOUNT` | 单笔下单数量(标的资产计) |
| `LOSS_LIMIT` | 单笔最大亏损触发的强平额度(USDT) |
@@ -111,6 +111,38 @@ curl -fsSL https://github.com/discountry/ritmex-bot/raw/refs/heads/main/setup.sh
3. 根据交易对调整 `TRADE_SYMBOL`、`PRICE_TICK`、`QTY_STEP` 等精度参数。
4. 一键脚本会自动写入这些变量,手动部署时需自行维护。
### Binance
1. 设置 `EXCHANGE=binance`。
2. 填写 `BINANCE_API_KEY`、`BINANCE_API_SECRET`。
3. 设置市场模式 `BINANCE_MARKET_TYPE`
- `perp`:永续(默认)
- `spot`:现货
- `auto`:按符号自动匹配(同名现货/永续并存时建议不要使用)
4. 设置交易符号 `BINANCE_SYMBOL`(或使用 `TRADE_SYMBOL`):
- 永续建议写 `BTCUSDT_PERP`(或直接 `BTCUSDT` + `BINANCE_MARKET_TYPE=perp`
- 现货建议写 `BTCUSDT`(也支持 `BTCUSDT_SPOT`
5. 需要做期现套利(Basis)时,建议显式拆分:
- `BASIS_FUTURES_SYMBOL=BTCUSDT_PERP`
- `BASIS_SPOT_SYMBOL=BTCUSDT`
6. 可选测试网/自定义端点:
- `BINANCE_SANDBOX=true`
- `BINANCE_SPOT_REST_URL` / `BINANCE_FUTURES_REST_URL`
- `BINANCE_SPOT_WS_URL` / `BINANCE_FUTURES_WS_URL`
> Binance 适配器默认优先使用 WebSocket(盘口、ticker、kline、账户/订单用户流),仅在必要时使用 REST 补偿与兜底。
>
> 若使用现货模式,部分“仅合约可用”的保护单能力会受交易所限制,策略会按交易所能力自动降级。
**示例(永续做市)**
```bash
EXCHANGE=binance BINANCE_MARKET_TYPE=perp BINANCE_SYMBOL=BTCUSDT_PERP bun run index.ts --strategy maker
```
**示例(现货网格)**
```bash
EXCHANGE=binance BINANCE_MARKET_TYPE=spot BINANCE_SYMBOL=BTCUSDT bun run index.ts --strategy grid
```
### StandX
* [StandX 做市策略教程](docs/standx/maker-points-guide.md)