@usherlabs/cex-broker 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/dist/commands/cli.js +19230 -746
- package/dist/index.d.ts +4 -1
- package/dist/index.js +8519 -115
- package/dist/index.js.map +177 -9
- package/dist/proto/node.descriptor.ts +2 -1
- package/dist/proto/node.proto +1 -0
- package/dist/server.d.ts +2 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -65,10 +65,21 @@ CEX_BROKER_BINANCE_API_KEY_1=your_secondary_binance_api_key
|
|
|
65
65
|
CEX_BROKER_BINANCE_API_SECRET_1=your_secondary_binance_api_secret
|
|
66
66
|
CEX_BROKER_BINANCE_API_KEY_2=your_tertiary_binance_api_key
|
|
67
67
|
CEX_BROKER_BINANCE_API_SECRET_2=your_tertiary_binance_api_secret
|
|
68
|
+
|
|
69
|
+
# OpenTelemetry Metrics (Optional)
|
|
70
|
+
# Send metrics via OTLP to a collector
|
|
71
|
+
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318
|
|
72
|
+
OTEL_SERVICE_NAME=cex-broker
|
|
73
|
+
# Or use CEX_BROKER_OTEL_* (default port 4318). Legacy: CEX_BROKER_CLICKHOUSE_* also supported.
|
|
74
|
+
# CEX_BROKER_OTEL_HOST=otel-collector
|
|
75
|
+
# CEX_BROKER_OTEL_PORT=4318
|
|
76
|
+
# CEX_BROKER_OTEL_PROTOCOL=http
|
|
68
77
|
```
|
|
69
78
|
|
|
70
79
|
**Note**: Only configure API keys for exchanges you plan to use. The system will automatically detect and initialize configured exchanges.
|
|
71
80
|
|
|
81
|
+
**Metrics (OpenTelemetry)**: Metrics are exported via OTLP. If neither `OTEL_EXPORTER_OTLP_ENDPOINT` nor `CEX_BROKER_OTEL_HOST` (or legacy `CEX_BROKER_CLICKHOUSE_HOST`) is set, metrics are disabled. When enabled, the broker sends metrics to the configured OTLP endpoint (e.g. an OpenTelemetry Collector).
|
|
82
|
+
|
|
72
83
|
### Policy Configuration
|
|
73
84
|
|
|
74
85
|
Configure trading policies in `policy/policy.json`:
|
|
@@ -394,6 +405,45 @@ const response = await client.ExecuteAction(request, metadata);
|
|
|
394
405
|
- Monitor API usage and set appropriate rate limits
|
|
395
406
|
- Use secondary brokers for redundancy and load distribution
|
|
396
407
|
|
|
408
|
+
## 📊 OpenTelemetry Metrics
|
|
409
|
+
|
|
410
|
+
The broker exports metrics via **OpenTelemetry (OTLP)** for monitoring and analytics. Metrics are collected for:
|
|
411
|
+
|
|
412
|
+
- **ExecuteAction requests**: Request counts, success/failure rates, latency histograms
|
|
413
|
+
- **Subscribe streams**: Subscription counts, duration, error rates
|
|
414
|
+
- **Action-specific metrics**: Tagged by action type, CEX, and symbol
|
|
415
|
+
|
|
416
|
+
### Metrics (OTLP)
|
|
417
|
+
|
|
418
|
+
The following metrics are exported as OTLP counters and histograms:
|
|
419
|
+
|
|
420
|
+
- `execute_action_requests_total` (counter): Total ExecuteAction requests
|
|
421
|
+
- `execute_action_success_total` (counter): Successful ExecuteAction requests
|
|
422
|
+
- `execute_action_errors_total` (counter): Failed ExecuteAction requests
|
|
423
|
+
- `execute_action_duration_ms` (histogram): ExecuteAction latency
|
|
424
|
+
- `subscribe_requests_total` (counter): Total Subscribe requests
|
|
425
|
+
- `subscribe_errors_total` (counter): Failed Subscribe requests
|
|
426
|
+
- `subscribe_duration_ms` (histogram): Subscribe stream duration
|
|
427
|
+
|
|
428
|
+
All metrics include attributes: `action`, `cex`, `symbol`, `error_type`, `service`.
|
|
429
|
+
|
|
430
|
+
### Setting Up Metrics
|
|
431
|
+
|
|
432
|
+
1. **Run an OTLP receiver** (e.g. [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/)):
|
|
433
|
+
- Default endpoint: `http://localhost:4318/v1/metrics`
|
|
434
|
+
- To store in ClickHouse or other backends, use the appropriate exporter in the collector pipeline (e.g. [ClickHouse exporter](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/clickhouseexporter)).
|
|
435
|
+
|
|
436
|
+
2. **Configure the broker**:
|
|
437
|
+
- Set `OTEL_EXPORTER_OTLP_ENDPOINT` (e.g. `http://localhost:4318`) or use `CEX_BROKER_OTEL_HOST` (and optional `CEX_BROKER_OTEL_PORT`, `CEX_BROKER_OTEL_PROTOCOL`). Legacy `CEX_BROKER_CLICKHOUSE_*` env vars are also supported.
|
|
438
|
+
|
|
439
|
+
3. Metrics are pushed periodically to the configured endpoint; no database schema is created by the broker (handled by the collector/backend).
|
|
440
|
+
|
|
441
|
+
**Local or Docker: OTLP → ClickHouse (no Prometheus)**
|
|
442
|
+
Use the included OpenTelemetry + ClickHouse stack so metrics go only to ClickHouse (no Prometheus exporter):
|
|
443
|
+
|
|
444
|
+
- **Docker**: `docker compose -f docker-compose.otel.yaml up -d`, then set `OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318` and start the broker.
|
|
445
|
+
- **Config**: `otel/collector-config.yaml` (OTLP receiver → batch → ClickHouse exporter). See [otel/README.md](otel/README.md) for full instructions (Docker and local).
|
|
446
|
+
|
|
397
447
|
## 🏗️ Architecture
|
|
398
448
|
|
|
399
449
|
### Project Structure
|
|
@@ -572,6 +622,7 @@ bun run check
|
|
|
572
622
|
|
|
573
623
|
### Core Dependencies
|
|
574
624
|
|
|
625
|
+
- `@opentelemetry/*`: OpenTelemetry API, SDK metrics, OTLP HTTP exporter for metrics
|
|
575
626
|
- `@grpc/grpc-js`: gRPC server implementation
|
|
576
627
|
- `@grpc/proto-loader`: Protocol buffer loading
|
|
577
628
|
- `@usherlabs/ccxt`: Enhanced CCXT library with Verity support
|