See here for WS API documents
See here for an explanation of the WS API authentication process @ power.trade.
-
Balance and Position data
See here for power.trade API docs on balances & positions
-
Single Leg Orders/RFQs (streaming quotes)
See here for power.trade API docs on streaming data.
The WS message format can be found at new order order deleted order executed order update
-
Multi Leg orders/RFQs (streaming quotes)
See here for power.trade API docs on streaming data.
The WS message format for multi-leg orders can be found at: new order order deleted order executed order updated
See this page for sample data feed requests
-
Download code from this repo
-
Cd to the folder containing the code downloaded from repo
-
Run 'build' command:
cargo buildto update linked libraries and compile code. The version built by default is 'dev'
-
To build the 'release' version which is more optimized reduced in size run this command
cargo build --release -
Before running the code configuration should be added to files (one per env)
=> Running app on Development env requires env file in root folder named ".env.dev". Can be created by copying "env.example" sample file and renaming to ".env.dev" to setup dev env
``` cp .env.example .env.dev ```=> Running app on Test env requires env file in root folder named ".env.test". Can be created by copying "env.example" sample file and renaming to ".env.test" to setup test env
``` cp .env.example .env.test ``` Once the env file is created add values for: * PT_API_KEY - API Key for authentication * PT_API_SECRET - API Secret for authentication * PT_SERVER_URL - WebSocket server address & port * PT_EPOCH_COUNT - Number of cycles the app will run * PT_WS_SLEEP - Sleep duration between message checks (in seconds) API key to be used must be one of the Read-Only ones issued under '' dropdown for API type. See example of UI fopr generating API Key below with correct settings for the WS Balance/Position API=> Running app on Prod env requires a .env file in root folder named ".env.prod". This file can be created by copying "env.example" sample file and and renaming to ".env.prod"
``` cp .env.example .env.prod ``` Once the env file is created add the same values as mentioned above. -
Run the code by this command "cargo run -- --env ENV" where ENV is either 'development', 'test' or 'production'
cargo run -- --env developmentor
cargo run -- --env testor
cargo run -- --env production -
Some debug messages are printed at console, but most are copied to a logging file named "app.log" which is located in the root folder.
-
App runs for the number of cycles specified in PT_EPOCH_COUNT environment variable as it runs a loop sleeping and checking messages.
Change the 'PT_EPOCH_COUNT' environment value in .env files to make the app run longer or shorter duration.
- Step 8 above can be replaced by running the generated binary which will be copied to the "target" folder under project root/home folder.
There will be a "debug" folder generated by running "cargo build" command and a "release" folder created when "cargo build --release" command is run
To run "debug" version execute command
./target/debug/client-rust-ws --env test
in the project root/home folder. The environment can be changed to "development" or "production" also as follows
./target/debug/client-rust-ws --env development
or
./target/debug/client-rust-ws --env production
To run "release" version: execute command
./target/release/client-rust-ws --env test
in project root/home folder. The environment can be changed to "development" or "production" also.
n.b. to view command line options e.g. available settings for environment ("--env") flag run the command without any settings ("./target/debug/client-rust-ws") or with no value added for environment flag ("./target/debug/client-rust-ws --env")
- Running the Rust WS Client against various power.trade endpoints
The rust client can be configured to listen for any of the three content types below by setting the environment variable named "PT_SERVER_URL" to the URLs below in the relevant configuration file for development (".env.dev"), test (".env.test") or production (".env.prod").
N.B. Current Rust client only supports one of the three content types per installed Rust code (under /target/release/ folder). Listening for more than one set of content from list below requires multiple copies of the Rust runtime files and a custom configuration per instance.
The project includes comprehensive unit tests with 19.18% code coverage (47/245 lines covered).
Run all tests with proper test isolation:
cargo test -- --test-threads=1Run tests with verbose output:
cargo test -- --test-threads=1 --nocaptureRun a specific test:
cargo test test_from_env_success -- --nocaptureRun tests for a specific module:
cargo test config::tests -- --test-threads=1Generate a detailed coverage report using cargo-tarpaulin:
-
Install cargo-tarpaulin (one-time setup):
cargo install cargo-tarpaulin
-
Generate coverage report:
cargo tarpaulin --verbose --timeout 120 -- --test-threads=1
-
Generate HTML coverage report:
cargo tarpaulin --out Html --output-dir coverage -- --test-threads=1
Then open
coverage/index.htmlin your browser.
| Module | Coverage | Lines Covered |
|---|---|---|
src/config.rs |
96.7% | 29/30 |
src/utils/mod.rs |
22.2% | 4/18 |
src/websocket.rs |
23.3% | 14/60 |
src/error.rs |
0% | 0/13 |
src/logging.rs |
0% | 0/17 |
src/main.rs |
0% | 0/107 |
| Overall | 19.18% | 47/245 |
Configuration Tests (13 tests)
- Environment variable parsing and validation
- Credential masking for security
- Default value handling
- Error handling for missing/invalid configuration
JWT Generation Tests (3 tests)
- Invalid private key handling
- Empty key validation
- Malformed PEM format detection
WebSocket Client Tests (8 tests)
- Configuration validation
- URL format validation
- Parameter validation (epoch count, sleep duration)
Run linting checks:
cargo clippy --all-targets --all-features -- -D warningsFormat code:
cargo fmtCheck formatting without making changes:
cargo fmt -- --checksee here for power.trade API docs on balance and position data available from the following test & production API endpoints
see here for details on power.trade's balance & positions response message
| Env | Link | Notes |
|---|---|---|
| Test | wss://api.wss.test.power.trade/v1/position_summary | both balances & positions returned in one response |
| Production | wss://api.wss.prod.power.trade/v1/position_summary | both balances & positions returned in one response |
n.b. to customize or filter the data feed content see parameters documented at this page
| Env | Link | Notes |
|---|---|---|
| Test | wss://api.wss.test.power.trade/v1/feeds/?type[]=mbp_snapshot&tradeable_type[]=all_single_leg&mbp_period=1&mbo_period=0 | link returns all tradeable types with full price book snapshot sent but no order book snapshot |
| Production | wss://api.wss.prod.power.trade/v1/feeds/?type[]=mbp_snapshot&tradeable_type[]=all_single_leg&mbp_period=1&mbo_period=0 | link returns all tradeable types with full price book snapshot sent but no order book snapshot |
n.b. to customize or filter the data feed content see parameters documented at this page
| Env | Link | Notes |
|---|---|---|
| Test | wss://api.wss.test.power.trade/v1/feeds/multi_leg?type[]=all_multi_leg,multi_leg_mbp_snapshot&mbp_period=1&mbo_period=0 | all multi-leg showing price book snapshot but not order book snapshot. add "market_id[]=none" to retireve RFQs |
| Production | wss://api.wss.prod.power.trade/v1/feeds/multi_leg?type[]=all_multi_leg,multi_leg_mbp_snapshot&mbp_period=1&mbo_period=0 | all multi-leg showing price book snapshot but not order book snapshot. add "market_id[]=none" to retireve RFQs |
