This project provides a client implementation for interacting with a FIX protocol-based API over a secure connection.
The client is capable of:
- Connecting to Power Trade Fix server
- Submitting new order(s)
- Cancelling orders
- Handling responses (e.g. heartbeat) from the server. A heartbeat message can be sent every XX seconds where XX can be configured
- JWT Generation: Generates JSON Web Tokens (JWT) for authenticating requests.
- FIX Message Handling: Constructs and sends FIX messages to the server.
- Secure Communication: Establishes a secure WebSocket connection to send and receive messages.
- Message Validation: Validates the presence of necessary fields in messages.
- Environment Configuration: Uses environment variables loaded from a .env file for configuration.
- Python 3.x
- Required Python packages (can be installed via
pip
):python-dotenv
pyjwt
simplefix
socket
ssl
Implement logging with configurable names including yymmddhhssLint the code using common tools e.g. black, ruff, isortPerform security checksGenerate reqular heartbeat signal messages to server sideAdd sample code for sending & cancelling Single Leg orders- Add sample code for sending & cancelling multi-leg orders
- Add sample code for listening to and processing RFQs
- Handle switching environments (test, prod) using command line args and multiple .env files
- Clone the repository:
git clone https://github.com/laisee/client-python-fix.git cd 'client-python-fix'
- Install required python libraries:
pip install -r requirements.txt
- Generate API Keys This is done at Power Trade UI under URL 'https://app.power.trade/api-keys' N.B. make sure to select "Fix API" as the API key Type and select "Order Entry/Cancel on Disconnect" if orders should be automatically cancelled when Fix session is closed or network disconnect happens.
-
Configure the runtime environment using .env file
touch .env
open .env file with nano or vi editors update settings for API Key and other values
-
**Configure a certificate for PowerTrade API endpoint"
Generate a certificate for the API endpoint by inspecting & downloading public key cert from API Url e.g. api.wss.test.power.trade
Copy the certificate contents to a file which is typically named as "cert.crt", but can be called anything.
The cert file name can be added to the .env file using the CERTFILE_NAME variable, see example below.
# Cert File location CERTFILE_LOCATION='cert.crt'
-
Execute the client
Execute sample client with Python at command line:
python client.py
Review client actions as it executes logon to server, adds a new order, cancels the order while awaiting response(s).
A sleep action allows time to review the new order on system via API or UI before it's cancelled.