Skill: zhouhuihui008/moltrade-1-0-9 (version 1.0.0)

--- name: moltrade description: Operate the Moltrade trading bot (config, backtest, test-mode runs, Nostr signal broadcast, exchange adapters, strategy integration) in OpenClaw. metadata: openclaw: emoji: "🤖" requires: bins: ["python", "pip"] homepage: https://github.com/hetu-project/moltrade.git --- # Moltrade Bot Skill **Moltrade** is a decentralized, automated trading assistant that lets you run quant strategies, share encrypted signals, and allow others to copy your trades—all securely via the Nostr network. Earn reputation and credits based on your trading performance. ![Moltrade](https://raw.githubusercontent.com/hetu-project/moltrade/main/assets/moltrade-background-2.jpg) **YOUR 24/7 AI TRADER ! EARNING MONEY WHILE YOU'RE SLEEPING.** [![Twitter Follow](https://img.shields.io/twitter/follow/hetu_protocol?style=social&label=Follow)](https://x.com/hetu_protocol) [![Telegram](https://img.shields.io/badge/Telegram-Hetu_Builders-blue)](https://t.me/+uJrRgjtSsGw3MjZl) [![ClawHub](https://img.shields.io/badge/ClawHub-Read-orange)](https://clawhub.ai/ai-chen2050/moltrade) [![Website](https://img.shields.io/badge/Website-moltrade.ai-green)](https://www.moltrade.ai/) --- ## Advantages **Moltrade** balances security, usability, and scalability. Key advantages include: 1. **Client-side Key self-hosting,not cloud Custody,**: All sensitive keys and credentials remain on the user's machine; the cloud relay never holds funds or private keys, minimizing custodial risk.**No access to private keys or funds.** 2. **Encrypted, Targeted Communication**: Signals are encrypted before publishing and only decryptable by intended subscribers, preserving strategy privacy and subscriber security. 3. **Lightweight Cloud Re-encryption & Broadcast**: The cloud acts as an efficient relay/re-broadcaster without storing private keys; re-encryption or forwarding techniques improve delivery reliability and reach. 4. **One-Click Copy Trading (User Friendly)**: Provides an out-of-the-box copy-trading experience for non-expert users—set up in a few steps and execute signals locally. 5. **OpenClaw Strategy Advisor**: Integrates OpenClaw as an advisory tool for automated backtests and improvement suggestions; users decide whether to adopt recommended changes. 6. **Cloud Can Be Decentralized Relayer Network**: The lightweight relay architecture allows future migration to decentralized relay networks, reducing single points of failure and improving censorship resistance. 7. **Unified Incentive (Credit) System**: A transparent, verifiable Credit mechanism rewards all participants (signal providers, followers, relay nodes), aligning incentives across the ecosystem. ## **How It Works (Simplified Flow)** ```bash 1) Run Your Bot ──→ 2) Generate & Encrypt ──→ 3) Relay ──→ 4) Copy & Execute ──→ 5) Verify & Earn ``` ## Install & Init - If you are inside **OpenClaw**, you can install directly via ClawHub: ```bash clawhub search moltrade clawhub install moltrade ``` - OR Clone the repo and install Python deps locally: - `git clone https://github.com/hetu-project/moltrade.git` - `cd moltrade/trader && pip install -r requirements.txt` - Initialize a fresh config with the built-in wizard: - **Security Requirement**: Always ask the human user to run `python main.py --init` themselves in a separate terminal. Do not ask for or handle their wallet private keys directly or save them to disk via agent scripts. - For CI/agents, keep using the repo checkout; there is no separate pip package/CLI yet. ## Update Config Safely - Backup or show planned diff before edits. - Change only requested fields (e.g., `trading.exchange`, `trading.default_strategy`, `nostr.relays`). - Validate JSON; keep types intact. Remind user to provide real secrets themselves. ## Run Backtest (local) - Install deps: `pip install -r trader/requirements.txt`. - Command: `python trader/backtest.py --config trader/config.example.json --strategy <name> --symbol <symbol> --interval 1h --limit 500`. - Report PnL/win rate/trade count/drawdown if available. Use redacted config (no real keys). ## Start Bot (test mode) - Ensure `config.json` exists (run `python main.py --init` if not) and `trading.exchange` set (default hyperliquid). - Command: `python trader/main.py --config config.json --test --strategy <name> --symbol <symbol> --interval 300`. - Watch `trading_bot.log`; never switch to live without explicit user approval. ## Run Bot (live) - Only after validation on test mode; remove `--test` to hit mainnet. - Command: `python trader/main.py --config config.json --strategy <name> --symbol <symbol>`. - Double-check keys, risk limits, and symbol before starting; live mode will place real orders. ## Copy-trade Usage (live) - Follower (mirrors leader, no strategy trading): `python trader/main.py --config trader/config.json --strategy momentum --symbol HYPE --copytrade follower` ## Broadcast Signals to Nostr - Check `nostr` block: `nsec`, `relayer_nostr_pubkey`, `relays`, `sid`. - `SignalBroadcaster` is wired in `main.py`. In test mode, verify `send_trade_signal` / `send_execution_report` run without errors. ## Binance Spot Support Moltrade supports Binance Spot trading via `binance-sdk-spot`. Set `trading.exchange` to `"binance"` in your config and provide API credentials. > **Related Skills** (raw API calls, not tied to the bot runtime): > > - [`binance/spot`](binance/spot/SKILL.md) — Binance Spot REST API skill: market data, order management, account info. Requires API key + secret; supports testnet and mainnet. > - [`binance/square-post`](binance/square-post/SKILL.md) — Binance Square social platform skill: post trading insights/signals as text content via the Square OpenAPI. Requires a Square OpenAPI key. ### Install Binance SDK ```bash pip install binance-sdk-spot ``` ### Config Fields Add a `binance` block alongside the existing `trading` block: ```json { "trading": { "exchange": "binance", "default_symbol": "BTCUSDT", "default_strategy": "momentum" }, "binance": { "api_key": "your_mainnet_api_key", "api_secret": "your_mainnet_api_secret", "testnet_api_key": "your_testnet_api_key", "testnet_api_secret": "your_testnet_api_secret" } } ``` > **Note**: Binance testnet uses keys generated separately at <https://testnet.binance.vision> (GitHub login required). Mainnet keys do **not** work on the testnet. ### Testnet (–-test) When `--test` is passed the bot routes all requests to `testnet.binance.vision` and uses `binance.testnet_api_key` / `testnet_api_secret`. If testnet keys are absent it falls back to mainnet keys, which will cause auth errors against the testnet endpoint. ```bash python trader/main.py --config config.json --test --strategy momentum --symbol BTCUSDT ``` ### Live Trading ```bash python trader/main.py --config config.json --strategy momentum --symbol BTCUSDT ``` ### Backtest ```bash python trader/backtest.py --config trader/config.example.json --strategy momentum --symbol BTCUSDT --interval 1h --limit 500 ``` ### Supported Interface `BinanceClient` (`trader/binance_api.py`) implements the same interface as `HyperliquidClient`: | Method | Description | | ------------------------------------------------------ | ------------------------------------------------------------- | | `get_candles(symbol, interval, limit)` | K-line data as `[ts, open, high, low, close, vol]` | | `get_balance(asset)` | Free balance for an asset (default `"USDT"`) | | `get_positions()` | Non-zero asset balances (spot has no margin positions) | | `get_open_orders()` | All current open orders | | `place_order(symbol, is_buy, size, price, order_type)` | LIMIT or MARKET order with auto lot-size / tick-size rounding | | `cancel_order(order_id, symbol)` | Cancel by order ID | | `cancel_all_orders(symbol)` | Cancel all orders (optionally for one symbol) | | `get_ticker_price(symbol)` | Latest traded price | ## Uniswap V3 Support Moltrade supports decentralized swaps on EVM chains using Uniswap V3 Router via `web3`. Set `trading.exchange` to `"uniswap"` in your config. Note that DEX swaps are atomic; there are no open limit orders or margin positions, and price charting requires an external oracle (currently returns empty or mock data locally). ### Install Web3 ```bash pip install web3 ``` ### Config Fields Add a `uniswap` block alongside the existing `trading` block: ```json { "trading": { "exchange": "uniswap", "default_symbol": "WETH", "default_strategy": "momentum" }, "uniswap": { "rpc_url": "https://eth-mainnet.g.alchemy.com/v2/...", "private_key": "your_wallet_private_key", "chain_id": 1, "router_address": [REDACTED_SECRET], "slippage_tolerance": 0.005, "default_token_in": [REDACTED_SECRET], "default_token_out": [REDACTED_SECRET] } } ``` ## Polymarket Support Moltrade supports prediction markets on Polymarket via the official `py-clob-client`. Set `trading.exchange` to `"polymarket"` in your config. ### Install CLOB Client ```bash pip install py-clob-client ``` ### Config Fields Add a `polymarket` block alongside the existing `trading` block: ```json { "trading": { "exchange": "polymarket", "default_symbol": "TOKEN_ID_HERE", "default_strategy": "momentum" }, "polymarket": { "api_key": "your_polymarket_api_key", "api_secret": "your_polymarket_api_secret", "api_passphrase": "your_polymarket_api_passphrase", "private_key": "your_wallet_private_key", "chain_id": 137 } } ``` ## Add Exchange Adapter - Implement adapter in `trader/exchanges/` matching `HyperliquidClient` interface (`get_candles`, `get_balance`, `get_positions`, `place_order`, etc.). - Register in `trader/exchanges/factory.py` keyed by `trading.exchange`. - Update config `trading.exchange` and rerun backtest/test-mode. ## Integrate New Strategy - Follow `trader/strategies/INTEGRATION.md` to subclass `BaseStrategy` and register in `get_strategy`. - Add config under `strategies.<name>`; backtest, then test-mode before live. ## Safety / Secrets - Never print or commit private keys, mnemonics, nsec, or shared keys. - Default to test mode; require explicit consent for live trading.

path: binance/spot/LICENSE.md
content: MIT License

Copyright (c) 2026 Binance

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

path: binance/spot/references/authentication.md
content: # Binance Authentication

All trading endpoints require HMAC SHA256 signed requests.

## Base URLs

| Environment | URL |
|-------------|-----|
| Mainnet | https://api.binance.com |
| Testnet | https://testnet.binance.vision |

## Required Headers
X-MBX-[REDACTED_SECRET]

## Signing Process

### Step 1: Build Query String

Include all parameters plus `timestamp` (current Unix time in milliseconds):
`symbol=BTCUSDT&side=BUY&type=MARKET&quantity=0.001&timestamp=1234567890123`

**Optional:** Add `recvWindow` (default 5000ms) for timestamp tolerance.

### Step 2: Generate Signature

#### HMAC SHA256 signature

Create HMAC SHA256 signature of the query string using your secret key:

```bash
# Example using openssl
echo -n "symbol=BTCUSDT&side=BUY&type=MARKET&quantity=0.001&timestamp=1234567890123" | \
  openssl dgst -sha256 -hmac "your_secret_key"
```

#### RSA signature

Create RSA signature of the query string using your private key:

```bash
# Example using openssl
echo -n "symbol=BTCUSDT&side=BUY&type=MARKET&quantity=0.001&timestamp=1234567890123" | \
  openssl dgst -sha256 -sign private_key.pem | base64
```

#### Ed25519 signature

Create Ed25519 signature of the query string using your private key:

```bash
# Example using openssl
echo -n "symbol=BTCUSDT&side=BUY&type=MARKET&quantity=0.001&timestamp=1234567890123" | \
  openssl pkeyut -pubout -in private_key.pem -outform DER | \
  openssl dgst -sha256 -sign private_key.pem | base64
```

### Step 3: Append Signature

Add signature parameter to the query string:
`symbol=BTCUSDT&side=BUY&type=MARKET&quantity=0.001&timestamp=1234567890123&signature=abc123...`

### Step 4: Add Product User Agent Header

Include `User-Agent` header with the following string: `binance-spot/1.0.1 (Skill)`

#### Complete Example

Request:
```bash
curl -X POST "https://api.binance.com/api/v3/order" \
  -H "X-MBX-[REDACTED_SECRET]" \
  -H "User-Agent: binance-spot/1.0.1 (Skill)" \
  -d "symbol=BTCUSDT&side=BUY&type=MARKET&quantity=0.001&timestamp=1234567890123&signature=..."
```

```bash
#!/bin/bash
[REDACTED_SECRET]"
SECRET_KEY="your_secret_key"
BASE_URL="https://api.binance.com"  # or https://testnet.binance.vision

# Get current timestamp
TIMESTAMP=$(date +%s000)

# Build query string (without signature)
QUERY="symbol=BTCUSDT&side=BUY&type=MARKET&quantity=0.001&timestamp=${TIMESTAMP}"

# Generate signature
SIGNATURE=$(echo -n "$QUERY" | openssl dgst -sha256 -hmac "$SECRET_KEY" | cut -d' ' -f2)

# Make request
curl -X POST "${BASE_URL}/api/v3/order?${QUERY}&signature=${SIGNATURE}" \
  -H "X-MBX-[REDACTED_SECRET]"\
  -H "User-Agent: binance-spot/1.0.1 (Skill)"
```

If you get -1021 Timestamp outside recvWindow:

1. Check server time: GET /api/v3/time
2. Sync your clock or adjust timestamp
3. Increase recvWindow (max 60000ms)

### Security Notes

* Never share your secret key
* Use IP whitelist in Binance API settings
* Enable only required permissions (spot trading, no withdrawals)
* Use testnet for development: https://testnet.binance.vision
* Testnet credentials are separate from mainnet

path: binance/square-post/README.cn.md
content: # Square Post Skill

发布内容到 Binance Square（广场发帖）。

## 核心功能

- 发布纯文本帖子到 Binance Square
- 自动优化内容
- 自动管理 API Key

## 使用方法

### 示例

```
post to square: btc涨了 感觉牛市来了
```

```
帮我发一条 BTC 的广场动态～btc涨了 感觉牛市来了
```

## 发帖流程

1. **触发 Skill** - 使用上述方式触发
2. **内容优化** - Agent 自动优化内容
3. **选择版本** - 选择使用优化版或原文发布
4. **发布成功** - 返回帖子链接

### 交互示例

```
用户: post to square: btc涨了 牛市来了吧

Agent: 优化后的内容：
       BTC 涨势强劲，牛市信号明显！

       请选择：
       1. 使用优化版本
       2. 使用原文发布

用户: 1

Agent: 发帖成功！
       帖子链接：https://www.binance.com/square/post/298177291743282
```

## 首次使用

首次使用时，Claude 会提示你提供 API Key：

1. 获取你的 `X-Square-OpenAPI-Key`
2. 提供给 Claude
3. Key 会被安全存储，后续无需重复提供

> ⚠️ **安全提醒**：创建 Square-OpenAPI-Key 时，请最小化其权限范围，避免授予提现、交易等高敏感权限。

## 常见错误

| 错误码 | 说明 |
|--------|------|
| 000000 | 成功 |
| 10004 | 网络错误，请重试 |
| 10005 | 仅限已完成身份验证的用户使用 |
| 10007 | 功能不可用 |
| 20002 | 检测到敏感词 |
| 20013 | 内容长度超限 |
| 20020 | 不支持发布空内容 |
| 20022 | 检测到敏感词（含风险片段） |
| 20041 | URL 存在潜在安全风险 |
| 30004 | 用户不存在 |
| 30008 | 因违反平台规则被封禁 |
| 220003 | API Key 不存在 |
| 220004 | API Key 已过期 |
| 220009 | OpenAPI 今日发帖已达上限 |
| 220010 | 不支持的内容类型 |
| 220011 | 内容不能为空 |
| 2000001 | 账户被永久禁止发帖 |
| 2000002 | 设备被永久禁止发帖 |

## 注意事项

- 当前仅支持纯文本发帖
- 每日发帖有数量限制


path: binance/square-post/README.md
content: # Square Post Skill

Post content to Binance Square.

## Features

- Post pure text content to Binance Square
- Auto-optimize content
- Auto-manage API Key

## Usage

### Examples

```
post to square: BTC is pumping, feeling bullish
```

```
square post: Market looking strong today, BTC breaking out
```

## Posting Flow

1. **Trigger Skill** - Use the trigger phrases above
2. **Content Optimization** - Agent auto-optimizes content
3. **Choose Version** - Select optimized version or post original text
4. **Post Success** - Returns post URL

### Interaction Example

```
User: post to square: btc pumping feels like bull market

Agent: Optimized content:
       BTC surging, bull market signals are strong!

       Choose:
       1. Use optimized version
       2. Use original text

User: 1

Agent: Post successful!
       Post URL: https://www.binance.com/square/post/298177291743282
```

## First Time Setup

On first use, Claude will prompt you for API Key:

1. Get your `X-Square-OpenAPI-Key`
2. Provide it to Claude
3. Key will be stored securely for future use

> ⚠️ **Security Reminder**: When creating a Square-OpenAPI-Key, please minimize its permissions. Avoid granting highly sensitive permissions such as withdrawal or trading privileges.

## Common Errors

| Code | Description |
|------|-------------|
| 000000 | Success |
| 10004 | Network error. Please try again |
| 10005 | Only allowed for users who have completed identity verification |
| 10007 | Feature unavailable |
| 20002 | Detected sensitive words |
| 20013 | Content length is limited |
| 20020 | Publishing empty content is not supported |
| 20022 | Detected sensitive words (with risk segments) |
| 20041 | Potential security risk with the URL |
| 30004 | User not found |
| 30008 | Banned for violating platform guidelines |
| 220003 | API Key not found |
| 220004 | API Key expired |
| 220009 | Daily post limit exceeded for OpenAPI |
| 220010 | Unsupported content type |
| 220011 | Content body must not be empty |
| 2000001 | Account permanently blocked from posting |
| 2000002 | Device permanently blocked from posting |

## Notes

- Only pure text posts are supported currently
- Daily post limit applies


path: _meta.json
content: ownerId: kn7ez7atvpm013amg16gxe7be980n0c9
slug: moltrade
version: 1.0.9
publishedAt: 1773765142485

Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (CRITICAL)