Crates.io | tradier |
lib.rs | tradier |
version | 0.1.0 |
source | src |
created_at | 2024-09-24 18:38:33.685725 |
updated_at | 2024-09-24 18:38:33.685725 |
description | This project involves the development of a Rust library for managing trades and market data using the Tradier broker API. The main objective is to provide an efficient and secure interface for executing trades, retrieving real-time quotes, managing portfolios, and accessing historical market data. The library focuses on leveraging Rust's performance and concurrency advantages, enabling integration into high-frequency trading applications and data-intensive financial processing. |
homepage | https://github.com/joaquinbejar/tradier |
repository | https://github.com/joaquinbejar/tradier |
max_upload_size | |
id | 1385549 |
size | 121,202 |
tradier is a comprehensive Rust library for managing trades and market data using the Tradier broker API. This powerful toolkit enables developers, traders, and financial applications to:
The library leverages Rust's performance and concurrency advantages, making it suitable for high-frequency trading applications and data-intensive financial processing.
The project is structured as follows:
Root Directory:
Cargo.lock
and Cargo.toml
: Rust package manager files for dependency management.Docker
: Directory containing Docker-related files for containerization.LICENSE
: The license file for the project.Makefile
: Contains commands for common development tasks.README.md
: The main documentation file you're currently reading.coverage
: Directory for test coverage reports.rust-toolchain.toml
: Specifies the Rust toolchain version for the project.tarpaulin-report.html
: HTML report of test coverage generated by cargo-tarpaulin.Documentation (doc/
):
images/
: Directory for storing images used in documentation.Examples (examples/
):
auth_example.rs
: Example of how to use authentication in the library.auth_websocket_example.rs
: Example of using authenticated WebSocket connections.Source Code (src/
):
config/
):
base.rs
: Defines the base configuration structure for the library.mod.rs
: Module declaration file for the config module.constants.rs
: Defines constant values used throughout the library.lib.rs
: The main library file that exposes the public API.utils/
):
error.rs
: Defines custom error types for the library.logger.rs
: Sets up logging functionality.mod.rs
: Module declaration file for the utils module.tests.rs
: Contains tests for utility functions.wssession/
):
account.rs
: Handles account-related WebSocket sessions.market.rs
: Manages market data WebSocket sessions.mod.rs
: Module declaration file for the wssession module.session.rs
: Defines the base WebSocket session structure and functionality.Tests (tests/
):
unit/
):
mod.rs
: Module file for unit tests.This structure organizes the project into logical components:
examples
directory provides sample code for users to understand how to use the library.src
directory contains the main library code, divided into modules for configuration, utilities, and WebSocket session management.tests
directory is set up for containing unit tests, ensuring the reliability of the library's components.Each module and file has a specific purpose, contributing to a well-organized and maintainable codebase for the TradierRust library.
Add tradier to your Cargo.toml
:
[dependencies]
tradier = "0.1.0"
Set up your Tradier API credentials:
.env
file in your project root:
TRADIER_ACCESS_TOKEN=your_api_key_here
TRADIER_CLIENT_ID=your_account_id_here
Build your project:
cargo build
To use the library in your project:
use tradier::config::base::Config;
use tradier::utils::logger::setup_logger;
use tradier::wssession::market::MarketSession;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
setup_logger();
let config = Config::new();
let market_session = MarketSession::new(&config).await?;
// Use the market_session to interact with the Tradier API
Ok(())
}
Here's an example of how to use the library for streaming market data:
use std::error::Error;
use tracing::{error, info};
use tradier::config::base::Config;
use tradier::utils::logger::setup_logger;
use tradier::wssession::account::AccountSession;
use tradier::wssession::market::{MarketSession, MarketSessionFilter, MarketSessionPayload};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
setup_logger();
let config = Config::new();
loop {
match MarketSession::new(&config).await {
Ok(market_session) => {
info!(
"Market streaming session created with id: {}",
market_session.get_session_id()
);
let payload = MarketSessionPayload {
symbols: vec!["AAPL".to_string(), "MSFT".to_string()],
filter: Some(vec![MarketSessionFilter::QUOTE, MarketSessionFilter::TRADE]),
session_id: market_session.get_session_id().to_string(),
linebreak: Some(true),
valid_only: Some(true),
advanced_details: None,
};
if let Err(e) = market_session.ws_stream(payload).await {
error!("Streaming error: {}. Reconnecting...", e);
}
}
Err(e) => {
error!(
"Failed to create market streaming session: {}. Retrying...",
e
);
}
}
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
}
}
This project includes a Makefile for common development tasks:
make build
: Build the projectmake test
: Run testsmake fmt
: Format the codemake lint
: Run Clippy for lintingmake clean
: Clean the projectmake check
: Run pre-push checks (test, format check, lint)make coverage
: Generate test coverage reportmake doc
: Generate and open documentationTo run a specific task, use make <task_name>
. For example:
make test
We welcome contributions to this project! If you would like to contribute, please follow these steps:
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
We appreciate your interest and look forward to your contributions!