This is a repository of example on how to use the Python and Pytest framework for validating Kraken Websockets API 1.9.0.
It covers the folloiwng:
- Connection to Kraken Websockets API.
- Assert details on Public Channel messages (Request and Reponse).
- Run Test in parallel mode.
- Provide Docker endpoints for ease of installations and execution via container.
- Generate HTML and XML reports of Test run results.
Public Channel Name | Test Scenario | Status |
---|---|---|
Book | 1. Validate Publication Payload elements | Completed |
2. Validate whether Book publication has Ask price updates in the last t seconds (configurable) | Completed | |
3. Validate whether Book publication has Bid price updates in the last t seconds (configurable) | Completed | |
4. Validate Response Schema- subscriptionStatus | Completed | |
5. Validate Response Schema- book publication snapshot | Completed | |
6. Validate Response Schema- book publication update | Completed | |
7. Validate Invalid Request | Completed | |
8. Validate Server heartbeat sent more than once within the last 2 seconds | Completed | |
ohlc | 1. Validate Response Schema- publication | In Progress, Connection Timeout to be resolved |
trade | 1. Validate Response Schema- publication | Completed |
spread | 1. Validate Response Schema- publication | Completed |
General Message | 1. Validate payload elements of Status sent on connection or system status changes. | Completed |
2. Validate system status Response Schema | Completed | |
3. Validate server Ping Response with or without optional request fields | Completed | |
4. Validate server Ping Response Schema | Completed | |
5. Validate server Ping for various Invalid Requests | Completed, see Notes 1 below |
Notes 1: Requires further evaluation for an unexpected observation. Details are noted in test_kraken_websocket_api.py: test_ping_response_error_reqid
Pre-requisite:
- Install Docker for the end user Operating System.
- Clone this repository.
- Launch the terminal/command prompt and navigate to the folder for this repository.
After that, follow these steps:
-
Image: Template for running Containers. Run the following on the terminal to build image:
docker build -t pytest-kraken-ws .
-
Container: Actual running process where we have our package. Run the following on the terminal to start the container:
docker run pytest-kraken-ws
Configured in pytest.ini
The folloiwng options can be used:
-
Let Pytest decide the number of Parallel runs using the following command line flag
This option is built into the Docker Image by default.-n auto
-
Specify number of Parallel runs, e.g. use the following command line flag:
To use this option, make changes in the pytest.ini file.-n 10
Note: Docker image would require to be re-built if parallel run change are made.
JUnit style XML Report: Test_Run_Report.xml
Pytest HTML Report: Test_Run_Report.html
Example:
Command to generate: python -m pytest
tests folder has:
- conftest.py has basic Pytest Fixture for Websockets connection.
- helper_function.py has functions that provide abstraction of simple actions for the test cases.
- schema.py is a schema store to be used durign the validations.
- test_kraken_websocket_api.py has Test Cases related to Websockets Connection and Ping.
- test_kraken_websocket_api_Public_Book_Channel.py has Test Cases related to Public Channel 'Book'.
- test_kraken_websocket_api_Public_Channel_schema_validations.py has test cases related to Publication schema validation for other Public Channels.
Other than that:
- Dockerfile has Docker Blueprint for building images.
- pytest.ini has properties related to Commandline options, Markers, and Testpath.
- requirements.txt has Python environment package versions for Docker Image creation.