dxlink
dxlink
dxlink is a Rust client library for the DXLink WebSocket protocol used by tastytrade
for real-time market data. This library provides a clean and type-safe API for connecting
to DXLink servers, subscribing to market events, and processing real-time market data.
Features
- Full implementation of the DXLink WebSocket protocol (AsyncAPI 2.4.0)
- Strongly typed event definitions for Quote, Trade, Greeks, and more
- Async/await based API for efficient resource usage
- Automatic handling of authentication and connection maintenance
- Support for multiple subscription channels
- Callback and stream-based APIs for event processing
- Robust error handling and reconnection logic
ref: https://raw.githubusercontent.com/dxFeed/dxLink/refs/heads/main/dxlink-specification/asyncapi.yml
Example
Here's a basic example of using the library to connect to a DXLink server and subscribe to market data:
use Error;
use ;
use sleep;
use Duration;
async
Working with historical data
DXLink supports subscribing to historical data through Candle events. When subscribing to candle events, you need to specify the period, type, and a timestamp from which to fetch the data:
use FeedSubscription;
use ;
// Get current timestamp in milliseconds
let now = now
.duration_since
.unwrap
.as_millis as i64;
// Timestamp for 24 hours ago
let one_day_ago = now - ;
// Subscribe to 5-minute candles for SPY for the last 24 hours
let candle_subscription = FeedSubscription ;
Error Handling
The library uses a custom error type DXLinkError that encompasses
various error cases that can occur when interacting with the DXLink API:
use ;
use ;
async
Available Event Types
The library supports the following event types:
Quote- Current bid/ask prices and sizesTrade- Last trade informationGreeks- Option greeks data (delta, gamma, theta, etc.)Summary- Daily summary informationProfile- Instrument profile informationCandle- OHLC (Open, High, Low, Close) data for time periods- And more!
License
This project is licensed under the MIT License. See the LICENSE file for details.
Setup Instructions
- Clone the repository:
git clone https://github.com/joaquinbejar/DXlink
cd DXlink
- Build the project:
make build
- Run tests:
make test
- Format the code:
make fmt
- Run linting:
make lint
- Clean the project:
make clean
- Run the project:
make run
- Fix issues:
make fix
- Run pre-push checks:
make pre-push
- Generate documentation:
make doc
- Publish the package:
make publish
- Generate coverage report:
make coverage
Testing
To run unit tests:
make test
To run tests with coverage:
make coverage
Contribution and Contact
We welcome contributions to this project! If you would like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and ensure that the project still builds and all tests pass.
- Commit your changes and push your branch to your forked repository.
- Submit a pull request to the main repository.
If you have any questions, issues, or would like to provide feedback, please feel free to contact the project maintainer:
Joaquín Béjar García
- Email: jb@taunais.com
- GitHub: joaquinbejar
We appreciate your interest and look forward to your contributions!
License: MIT