Official SDK for the TradeWatch.io API.
TradeWatch.io is a market data platform and API for real-time and historical prices across crypto, stocks, indices, currencies, and commodities.
Want to test endpoints without writing code first? Use the TradeWatch Interactive API Playground to run requests directly in your browser.
- REST API reference: https://tradewatch.io/docs/api-reference/introduction
- WebSocket API reference: https://tradewatch.io/docs/websocket-api/introduction
- Support channels: https://tradewatch.io/docs/platform/support
- Create an API key in the TradeWatch Dashboard.
- Follow platform setup docs: Getting started.
API reference documentation is available here.
Add this to your Cargo.toml:
[dependencies]
tradewatch_api = "0.1.0"Or install via cargo:
cargo add tradewatch_apiA full reference for this library is available here.
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;
}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);
}
}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:
Use the max_retries method to configure this behavior.
let response = client.crypto.get_quote(
Some(RequestOptions::new().max_retries(3))
)?.await;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;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;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;| Method | Required Params | Summary | Description |
|---|---|---|---|
get_usage() |
- | Usage statistics | Get the usage statistics of your API account |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
