Rust Client for trading on power.trade crypto exchange
Rust client for power.trade Fix protocol. Implements authentication and basic order management (add single order, cancel single order) and RFQ (Request For Quote) functionality.
- Establishes a TLS FIX session and performs logon to the Power.Trade exchange.
- Signs JWTs with your API keys to authenticate FIX connections.
- Provides utilities for building FIX messages including NewOrderSingle, OrderCancelRequest, and RFQ messages.
- Scenario-driven main executable that can place or cancel orders or send RFQ messages based on environment variables.
- Integration test validates the structure of generated FIX messages without connecting to the exchange.
See list of issues for the planned set of enhancements and features.
See here for Power.Trade Single Leg Order Fix message specification (Fix MsgType='D')
See here for Power.Trade Drop Copy Fix message specification (Fix MsgType='8')
Power.Trade API home page can be found here
-
Install Rust on device where client will be running.
See Rust installation instructions for instructions on installation using Rustup.
See alternative installation methods for other installation methods.
-
Check that Rustup has installed and configured 1.86 as the default version by typing the following command in a console/terminal window
rustc --version
the version displayed should be: "rustc 1.86.0 (default)"
-
Copy the sample env file (".env.example") to create a file for the Test environment
cp .env.example .env.test -
Open the new
.env.testfile and update the settings for your Test API environmentRequired environment variables include:
PT_API_KEY- Power.Trade API keyPT_WS_API_KEY- WebSocket API keyPT_WS_API_SECRET- WebSocket API secret in PEM formatPT_SERVER- FIX server hostnamePT_WS_SERVER- WebSocket endpointPT_PEM_FILE- path to your client PEM filePT_PUBKEY_FILE- path to your public certificatePT_SCENARIO- scenario to run (ORDER,ORDERS,RFQ_QUOTE,RFQ_LISTEN)PT_LISTEN_EPOCH- number of epochs to listen for responses (for RFQ_LISTEN)PT_PUBLISH_EPOCH- number of epochs to listen after publishing (for RFQ_QUOTE)PT_HEARTBEAT_COUNT- number of heartbeats to sendPT_HEARTBEAT_INTERVAL- seconds between heartbeatsPT_SYMBOL- trading symbol (e.g., "BTC-USD")PT_PRICE- order pricePT_QUANTITY- order quantityPT_SIDE- order side ("BUY" or "SELL")PT_ORDER_TYPE- order type ("LIMIT" or "MARKET")PT_CANCEL_ORDER- whether to cancel the order after placing it ("true" or "false")PT_LOG_FILE- path to log filePT_TARGET_COMP_ID- target company ID for FIX messages
-
Build the project
cargo build -
Run tests to ensure everything is configured correctly
cargo test -
Save the file and run the client on the Test environment (same process can be followed to create production env file '.env.prod')
n.b. Rust client runtime environment is set on command line as a parameter for the --env flag with value of 'development', 'test', 'production'
cargo run -- --env test -
Review console output and log files (see
app.login the same folder) to view client activity
The client supports several scenarios that can be configured using the PT_SCENARIO environment variable:
ORDER- Send a single order based on the configured parametersORDERS- Send multiple orders (currently sends a single order, but can be extended)RFQ_QUOTE- Send an RFQ quote request and listen for responsesRFQ_LISTEN- Subscribe to RFQ updates and listen for incoming quotes
The client supports the following command line arguments:
--env <ENVIRONMENT>- Set the runtime environment (development, test, production)
Example:
cargo run -- --env test
The client logs information to both the console and a log file specified by the PT_LOG_FILE environment variable. The log file contains detailed information about the client's operation, including sent and received FIX messages.
To contribute to the project, please follow these steps:
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting:
cargo test && cargo clippy - Submit a pull request
This project is licensed under the MIT License - see the LICENSE.md file for details.