- Introduction
- Features
- Project Structure
- Setup Instructions
- Library Usage
- Usage Examples
- Testing
- Contribution and Contact
IG Client is a comprehensive Rust framework for interacting with the IG broker API. This versatile toolkit enables traders, developers, and financial professionals to:
- Order Execution: Execute orders on the IG platform programmatically.
- Order Management: Manage existing orders, including modifications and cancellations.
- Market Data: Retrieve real-time and historical market data for various instruments.
- Account Information: Access account details, balances, and trading history.
- Asynchronous Operations: Utilize async/await for efficient API interactions.
- Error Handling: Robust error handling with anyhow for clear and informative error messages.
- Logging and Tracing: Comprehensive logging and tracing with tracing and tracing-subscriber.
- Unit Testing: Extensive unit tests with pretty_assertions and assert-json-diff for clear test outputs.
The project is structured as follows:
-
Configuration (
src/config.rs
): Configuration settings for the IG Client. -
Application Layer (
src/application/
):- API (
src/application/api/
):- Client (
src/application/api/client.rs
): Main client interface for interacting with the IG API. - Endpoints (
src/application/api/endpoints.rs
): Definitions of API endpoints.
- Client (
- Models (
src/application/models/
):- Account (
src/application/models/account.rs
): Account-related data structures. - Market (
src/application/models/market.rs
): Market-related data structures. - Order (
src/application/models/order.rs
): Order-related data structures.
- Account (
- Services (
src/application/services/
):- Market Data (
src/application/services/market_data.rs
): Functions for retrieving and processing market data. - Order Execution (
src/application/services/order_execution.rs
): Functions for executing orders. - Order Management (
src/application/services/order_management.rs
): Functions for managing existing orders.
- Market Data (
- API (
-
Presentation Layer (
src/presentation/
):- Encryption (
src/presentation/encryption.rs
): Data encryption utilities. - Serialization (
src/presentation/serialization.rs
): Data serialization and deserialization utilities.
- Encryption (
-
Session Management (
src/session/
):- Authentication (
src/session/auth.rs
): Authentication and session management.
- Authentication (
-
Transport Layer (
src/transport/
):- HTTP Client (
src/transport/http_client.rs
): Core implementation of the HTTP client for interacting with the IG API.
- HTTP Client (
-
Utilities (
src/utils/
):- Error Handling (
src/utils/error.rs
): Custom error types and error handling utilities.
- Error Handling (
-
Tests (
tests/
): Directory containing all unit tests. -
Benchmarks (
benches/
): Directory containing benchmark tests. -
Examples (
examples/
): Directory containing usage examples.
- Clone the repository:
git clone https://github.com/joaquinbejar/ig-client.git
cd ig-client
- Build the project:
cargo build
- Run tests:
cargo test
- Format the code:
cargo fmt
- Run linting:
cargo clippy
To use the library in your project, add the following to your Cargo.toml
:
[dependencies]
ig-client = { git = "https://github.com/joaquinbejar/ig-client.git" }
Here are some examples of how to use the library for interacting with the IG broker:
use ig_client::IGHttpClient;
use ig_client::order::Order;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = IGHttpClient::new("YOUR_API_KEY", "YOUR_ACCOUNT_ID");
// Place a new order
let order = Order::new("EURUSD", "BUY", 1000);
let result = client.place_order(order).await?;
println!("Order placed: {:?}", result);
// Get account information
let account_info = client.get_account_info().await?;
println!("Account balance: {}", account_info.balance);
Ok(())
}
To run unit tests:
cargo test
To run tests with coverage:
cargo tarpaulin
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: [email protected]
- GitHub: joaquinbejar
We appreciate your interest and look forward to your contributions!