Skip to content

laisee/client-rust-ws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

client-rust-ws

VisitsRust[1.74.1, stable] Cargo Test Cargo ClippyLicense: MITMSRV

Rust client for Power.Trade WS endpoints

### Power.Trade WebSocket API documents

See here for WS API documents

Power.Trade Authentication

See here for an explanation of the WS API authentication process @ power.trade.

Content provided (see endpoint links below)

Sample Requests

See this page for sample data feed requests

Setup

  1. Download code from this repo

  2. Install Rust using instructions here OR here

  3. Cd to the folder containing the code downloaded from repo

  4. Run 'build' command:

    cargo build
    

    to update linked libraries and compile code. The version built by default is 'dev'

  5. To build the 'release' version which is more optimized reduced in size run this command

    cargo build --release
    
  6. Before running the code configuration should be added to files (one per env)

    => 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:
    * Api Key
    * Api Secret
    * WS Server address & port
    
    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
    

    image

    => 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 values for:
    * Api Key
    * Api Secret
    * WS Server address & port 
    
  7. Run the code by this command "cargo run --ENV" where ENV is either 'test' or 'production'

    cargo run -- --env test
    

    or

    cargo run -- --env production
    
  8. 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.

  9. App runs for XX cycles 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. The loop is to be replaced by event-driven code shortly. Check this repo for changes

  1. 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 "production" also as follows

./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 "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")

  1. 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 ennviroment variables named "PT_SERVER" to the URLs below in the relevant configurwtion file for 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.

Endpoint Links

Balances & Positions

see 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

Single Leg Orders/RFQs

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

Multi Leg orders/RFQs

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

Releases

No releases published

Packages

No packages published

Languages