Skip to content

tradewatch-io/rust-sdk

Repository files navigation

TradeWatch.io Rust SDK

crates.io shield

TradeWatch.io logo

Official SDK for the TradeWatch.io API.

Other SDKs

Python SDK TypeScript SDK .NET SDK PHP SDK Java SDK Go SDK Ruby SDK Swift SDK

What is TradeWatch.io?

TradeWatch.io is a market data platform and API for real-time and historical prices across crypto, stocks, indices, currencies, and commodities.

Try the Interactive API Playground

Want to test endpoints without writing code first? Use the TradeWatch Interactive API Playground to run requests directly in your browser.

TradeWatch Interactive API Playground

Resources

Quick Start

  1. Create an API key in the TradeWatch Dashboard.
  2. Follow platform setup docs: Getting started.

Table of Contents

Documentation

API reference documentation is available here.

Installation

Add this to your Cargo.toml:

[dependencies]
tradewatch_api = "0.1.0"

Or install via cargo:

cargo add tradewatch_api

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

use tradewatch_api::prelude::*;

#[tokio::main]
async fn main() {
    let config = ClientConfig {
        api_key: Some("<value>".to_string()),
        ..Default::default()
    };
    let client = ApiClient::new(config).expect("Failed to build client");
    client
        .crypto
        .get_quote(
            &GetQuoteQueryRequest5 {
                symbol: "BTC-USD".to_string(),
                precision: Some(2),
            },
            None,
        )
        .await;
}

Errors

When the API returns a non-success status code (4xx or 5xx response), an error will be returned.

match client.crypto.get_quote(None)?.await {
    Ok(response) => {
        println!("Success: {:?}", response);
    },
    Err(ApiError::HTTP { status, message }) => {
        println!("API Error {}: {:?}", status, message);
    },
    Err(e) => {
        println!("Other error: {:?}", e);
    }
}

Advanced

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries method to configure this behavior.

let response = client.crypto.get_quote(
    Some(RequestOptions::new().max_retries(3))
)?.await;

Timeouts

The SDK defaults to a 30 second timeout. Use the timeout method to configure this behavior.

let response = client.crypto.get_quote(
    Some(RequestOptions::new().timeout_seconds(30))
)?.await;

Additional Headers

You can add custom headers to requests using RequestOptions.

let response = client.crypto.get_quote(
    Some(
        RequestOptions::new()
            .additional_header("X-Custom-Header", "custom-value")
            .additional_header("X-Another-Header", "another-value")
    )
)?
.await;

Additional Query String Parameters

You can add custom query parameters to requests using RequestOptions.

let response = client.crypto.get_quote(
    Some(
        RequestOptions::new()
            .additional_query_param("filter", "active")
            .additional_query_param("sort", "desc")
    )
)?
.await;

Available Methods

account

Method Required Params Summary Description
get_usage() - Usage statistics Get the usage statistics of your API account

currencies

Method Required Params Summary Description
convert(from, to) from, to Conversion Convert one symbol to another
get_insights() - Get Insights Get recent currencies insights.
get_quote(symbol) symbol Last Quote Get the last quote tick for the provided symbol.
get_quotes(symbols) symbols Last Quotes Get the last quote tick for the provided symbols.
get_symbols() - Available Symbols Get list of available symbols

crypto

Method Required Params Summary Description
convert(from, to) from, to Conversion Convert one symbol to another
get_exchanges() - Available Exchanges Get list of available cryptocurrency exchanges
get_insights() - Get Insights Get recent crypto insights.
get_quote(symbol) symbol Last Quote Get the last quote tick for the provided symbol.
get_quotes(symbols) symbols Last Quotes Get the last quote tick for the provided symbols.
get_symbols() - Available Symbols Get list of available symbols

indices

Method Required Params Summary Description
get_insights() - Get Insights Get recent indices insights.
get_quote(symbol) symbol Last Quote Get the last quote tick for the provided symbol.
get_quotes(symbols) symbols Last Quotes Get the last quote tick for the provided symbols.
get_symbols() - Available Symbols Get list of available symbols

stocks

Method Required Params Summary Description
get_historical_ohlc(symbol, resolution, start, end) symbol, resolution, start, end Get Historical Ohlc Get historical OHLC candles for a symbol in a selected resolution and time range.
get_historical_ticks(symbol, start, end) symbol, start, end Get Historical Ticks Get raw historical ticks for a symbol in a selected time range using cursor pagination.
get_insights() - Get Insights Get recent stocks insights.
get_market_holidays(start, end) start, end Get Market Holidays Get market holidays. It takes half-days into account.
get_market_status() - Get Market Status Get the current status (open or closed) of a market. It takes holidays and half-days into account but does not factor in circuit breakers or halts.
get_markets() - Get Markets Get details about the markets available in this API.
get_quote(symbol) symbol Last Quote Get the last quote tick for the provided symbol.
get_quotes(symbols) symbols Last Quotes Get the last quote tick for the provided symbols.
get_stock_data(symbol) symbol Get Stock Data Get Stock Data
get_symbols() - Available Symbols Get list of available symbols
get_trading_hours(start, end) start, end Get Trading Hours Get trading hours. It takes half-days into account.
stock_get_countries() - Available Countries Get list of available countries

commodities

Method Required Params Summary Description
get_insights() - Get Insights Get recent commodities insights.
get_quote(symbol) symbol Last Quote Get the last quote tick for the provided symbol.
get_quotes(symbols) symbols Last Quotes Get the last quote tick for the provided symbols.
get_symbols() - Available Symbols Get list of available symbols
get_types() - Available Types Get list of available commodity types

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages