Skip to content

Commit 488fe13

Browse files
committed
feat: enhance documentation and configuration for Docker setup, add subscription endpoint by ETH address, and improve error handling in API
1 parent 2de94c0 commit 488fe13

File tree

14 files changed

+452
-79
lines changed

14 files changed

+452
-79
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@
9898
```
9999
The bot will start, generate a Nostr key pair for communication, and await configuration via its local API or admin panel.
100100

101+
## **Docker Setup**
102+
103+
**For Relayer:**
104+
```bash
105+
cd docker && docker compose -f docker-compose.relayer.yml up --build
106+
```
107+
108+
**For Trader:**
109+
```bash
110+
cd docker && docker compose -f docker-compose.trader.yml up
111+
```
112+
101113
## **Architecture & Integration with Your Ecosystem**
102114

103115
- **Core (MVP)**: This `moltrade-bot` and the cloud relay form the self-sustaining MVP.

docker/docker-compose.relayer.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: "3.9"
2+
3+
services:
4+
postgres:
5+
image: postgres:15
6+
environment:
7+
POSTGRES_DB: moltrade
8+
POSTGRES_USER: postgres
9+
POSTGRES_PASSWORD: postgres
10+
volumes:
11+
- postgres_data:/var/lib/postgresql/data
12+
ports:
13+
- "5432:5432"
14+
healthcheck:
15+
test: ["CMD-SHELL", "pg_isready -U postgres"]
16+
interval: 10s
17+
timeout: 5s
18+
retries: 5
19+
20+
relayer:
21+
build: ../relayer
22+
depends_on:
23+
postgres:
24+
condition: service_healthy
25+
command: ["moltrade-relayer", "--config", "/etc/moltrade-relayer/config.toml"]
26+
environment:
27+
RUST_LOG: moltrade_relayer=info
28+
volumes:
29+
- ./relayer.config.toml:/etc/moltrade-relayer/config.toml:ro
30+
ports:
31+
- "8080:8080" # REST + WebSocket
32+
- "9090:9090" # Prometheus metrics
33+
34+
volumes:
35+
postgres_data:
36+
driver: local

docker/docker-compose.trader.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: "3.9"
2+
3+
services:
4+
trader:
5+
image: python:3.11-slim
6+
working_dir: /app
7+
volumes:
8+
- ../trader:/app:ro
9+
- ./trader.config.json:/app/config.json:ro
10+
environment:
11+
PYTHONUNBUFFERED: "1"
12+
command: >-
13+
bash -c "pip install --no-cache-dir -r requirements.txt && \
14+
python main.py --config /app/config.json --test --strategy momentum --symbol HYPE"

docker/relayer.config.toml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Relayer config for docker-compose
2+
[relay]
3+
bootstrap_relays = ["ws://62.72.41.239:8000"]
4+
max_connections = 10_000
5+
health_check_interval = 30
6+
7+
[deduplication]
8+
hotset_size = 1_000_000
9+
bloom_capacity = 10_000_000
10+
lru_size = 100_000
11+
rocksdb_path = "./data/rocksdb"
12+
13+
[filters]
14+
allowed_kinds = [30931, 30932, 30933, 30934]
15+
16+
[output]
17+
websocket_enabled = true
18+
websocket_port = 8080
19+
batch_size = 100
20+
max_latency_ms = 50
21+
22+
[postgres]
23+
dsn = "postgres://postgres:postgres@postgres:5432/moltrade"
24+
max_connections = 5
25+
26+
[nostr]
27+
secret_key = "nsec1..."
28+
29+
[settlement]
30+
explorer_base = "https://app.hyperliquid.xyz/explorer/transaction"
31+
poll_secs = 30
32+
batch_limit = 50
33+
token = ""
34+
35+
[settlement.credit]
36+
leader_rate = 0.002
37+
follower_rate = 0.001
38+
min_credit = 0.5
39+
profit_multiplier = 1.2
40+
enable = true
41+
42+
[subscriptions]
43+
daily_limit = 1000
44+
45+
[monitoring]
46+
prometheus_port = 9090
47+
log_level = "info"

docker/trader.config.json

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"wallet_address": "0x_your_wallet",
3+
"private_key": "your_private_key_here",
4+
"telegram": {
5+
"enabled": false,
6+
"bot_token": "",
7+
"chat_id": "",
8+
"notify_startup": true,
9+
"notify_signals": true,
10+
"notify_trades": true,
11+
"notify_closures": true,
12+
"notify_errors": true,
13+
"notify_daily_summary": true
14+
},
15+
"trading": {
16+
"exchange": "hyperliquid",
17+
"default_symbol": "HYPE",
18+
"default_strategy": "test",
19+
"position_size": 0.08,
20+
"max_position_size": 0.2,
21+
"stop_loss_percent": 0.03,
22+
"take_profit_percent": 0.08
23+
},
24+
"strategies": {
25+
"momentum": {
26+
"rsi_period": 14,
27+
"rsi_oversold": 30,
28+
"rsi_overbought": 70,
29+
"macd_fast": 12,
30+
"macd_slow": 26,
31+
"macd_signal": 9
32+
},
33+
"mean_reversion": {
34+
"bollinger_period": 20,
35+
"bollinger_std": 2,
36+
"rsi_period": 14,
37+
"rsi_oversold": 30,
38+
"rsi_overbought": 70
39+
},
40+
"grid": {
41+
"grid_levels": 10,
42+
"grid_range_percent": 0.1,
43+
"order_size_percent": 0.05
44+
},
45+
"trend_following": {
46+
"min_trade_interval": 14400,
47+
"min_adx": 30
48+
}
49+
},
50+
"risk_management": {
51+
"max_daily_loss": 0.05,
52+
"max_trades_per_day": 8,
53+
"cool_down_seconds": 300
54+
},
55+
"nostr": {
56+
"nsec": "nsec1yourprivatekey",
57+
"platform_shared_key": "64_hex_shared_key_from_platform",
58+
"relays": [
59+
"wss://nostr.parallel.hetu.org:8443"
60+
],
61+
"sid": "subspace_op",
62+
"role": "bot"
63+
},
64+
"copytrade": {
65+
"enabled": false,
66+
"follow_pubkeys": [
67+
"npub_of_leader"
68+
],
69+
"symbols": [
70+
"HYPE"
71+
],
72+
"size_pct": 0.05,
73+
"min_order_value": 10.0
74+
}
75+
}

docs/API.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ List subscriptions for a bot:
8484
curl http://localhost:8080/api/subscriptions/<bot_pubkey>
8585
```
8686

87+
List subscriptions for a bot by eth address (bot_pubkey == eth_address for EVM bots):
88+
89+
```bash
90+
curl http://localhost:8080/api/subscriptions/by-eth/<eth_address>
91+
```
92+
8793
Notes: subscription POSTs are rate-limited per bot `eth_address` via `[subscriptions].daily_limit` (default 1000; set to 0 to disable). GET is unrestricted. Exceeding the limit returns HTTP 429.
8894

8995
### Trades

relayer/Makefile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,18 @@ update: ## Update all dependencies to latest compatible version
107107
# ============================================================================
108108
# Run targets
109109
# ============================================================================
110-
run: build ## Run release version
111-
@echo "🚀 Running release version..."
112-
@$(RELEASE_BINARY)
113-
114-
debug: dev ## Run development version (debug mode)
115-
@echo "🚀 Running development version..."
116-
@$(DEBUG_BINARY) --config config.template.toml
117-
118-
run-with-config: build ## Run release version using config file
110+
run: build ## Run release version using config file
119111
@echo "🚀 Running with config file..."
120112
@if [ ! -f config.toml ]; then \
121113
echo "⚠️ config.toml not found, using default config"; \
122114
fi
123115
@$(RELEASE_BINARY) --config config.toml
124116

117+
118+
debug: dev ## Run development version (debug mode)
119+
@echo "🚀 Running development version..."
120+
@$(DEBUG_BINARY) --config config.template.toml
121+
125122
# ============================================================================
126123
# Test and check targets
127124
# ============================================================================

relayer/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ Rust service that ingests Nostr events, deduplicates, forwards to downstreams, a
5959

6060
3. **Compile and run**
6161
```bash
62-
make build # Build the project
63-
make run # Run the project
62+
make build # Build the project
63+
make run # Run the project with config.toml
6464
# Or
65-
make dev # Development mode (debug build)
65+
make dev # Dev mode (debug build) with config.template.toml
6666
```
6767

6868
### Using Makefile
@@ -154,6 +154,7 @@ lru_size = 50000 # LRU cache size
154154
# Output configuration
155155
websocket_enabled = true # Enable WebSocket
156156
websocket_port = 8080 # WebSocket port
157+
bind_address = "127.0.0.1" # Bind address for REST/WebSocket
157158
batch_size = 100 # Batch processing size
158159
max_latency_ms = 100 # Maximum latency (milliseconds)
159160

relayer/config.template.toml

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,52 @@
1-
# Relay configuration
2-
[relay]
3-
bootstrap_relays = [
4-
"ws://62.72.41.239:8000",
5-
# "wss://relay.damus.io",
6-
# "wss://nostr.wine",
7-
# "wss://relay.snort.social",
8-
]
9-
max_connections = 10000
10-
health_check_interval = 30
11-
12-
# Deduplication configuration
131
[deduplication]
14-
hotset_size = 1_000_000
15-
bloom_capacity = 10_000_000
16-
lru_size = 100_000
2+
bloom_capacity = 10000000
3+
hotset_size = 1000000
4+
lru_size = 100000
175
rocksdb_path = "./data/rocksdb"
186

19-
# Nostr filtering configuration
207
[filters]
21-
allowed_kinds = [30931, 30932, 30933, 30934]
8+
allowed_kinds = [
9+
30931,
10+
30932,
11+
30933,
12+
30934,
13+
]
14+
15+
[monitoring]
16+
log_level = "debug"
17+
prometheus_port = 9090
18+
19+
[nostr]
20+
secret_key = "nsec1kk97xcsmpdnh9e009f5987gtwh2jm0p3syvcva55ua98hvv3sk5sw2rt7k"
2221

23-
# Output configuration
2422
[output]
25-
websocket_enabled = false
26-
websocket_port = 8080
2723
batch_size = 100
24+
bind_address = "127.0.0.1"
2825
max_latency_ms = 50
26+
websocket_enabled = false
27+
websocket_port = 8080
2928

30-
# Postgres configuration (used for subscriptions/fanout)
3129
[postgres]
3230
dsn = "postgres://postgres:postgres@localhost:5432/moltrade"
3331
max_connections = 5
3432

35-
# Nostr platform key (used to decrypt inbound and encrypt outbound)
36-
[nostr]
37-
# nsec... or hex sk
38-
secret_key = "nsec1..."
33+
[relay]
34+
bootstrap_relays = ["ws://62.72.41.239:8000"]
35+
health_check_interval = 30
36+
max_connections = 10000
3937

40-
# Settlement worker (Hyperliquid tx hash polling)
4138
[settlement]
42-
# Base URL for tx lookup (defaults to Hyperliquid explorer tx endpoint)
39+
batch_limit = 50
4340
explorer_base = "https://app.hyperliquid.xyz/explorer/transaction"
44-
# Polling interval seconds
4541
poll_secs = 30
46-
# Max pending trades to check per tick
47-
batch_limit = 50
48-
# Optional shared token for settlement/reporting endpoints
4942
token = ""
5043

51-
# Credit issuance config
5244
[settlement.credit]
53-
# Applied to leader trades (uses notional size * price * rate)
54-
leader_rate = 0.002
55-
# Applied to follower trades
45+
enable = true
5646
follower_rate = 0.001
57-
# Floor credit per confirmed trade
47+
leader_rate = 0.002
5848
min_credit = 0.5
59-
# Multiplier when pnl_usd > 0 (profit-making trades)
6049
profit_multiplier = 1.2
61-
enable = true
6250

63-
# Subscription limits
6451
[subscriptions]
65-
# Daily POST limit for subscription endpoints (per bot eth_address). 0 disables limiting.
6652
daily_limit = 1000
67-
68-
# Monitoring configuration
69-
[monitoring]
70-
prometheus_port = 9090
71-
log_level = "debug"

0 commit comments

Comments
 (0)