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.
A full reference for this library is available here.
Instantiate and use the client with the following:
require "tradewatch"
client = Tradewatch::Client.new(api_key: "<value>")
client.crypto.get_quote(
symbol: "BTC-USD",
precision: 2
)This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.
require "tradewatch"
tradewatch = Tradewatch::Client.new(
base_url: Tradewatch::Environment::DEFAULT
)require "tradewatch"
client = Tradewatch::Client.new(
base_url: "https://example.com"
)Failed API calls will raise errors that can be rescued from granularly.
require "tradewatch"
client = Tradewatch::Client.new(
base_url: "https://example.com"
)
begin
result = client.crypto.get_quote
rescue Tradewatch::Errors::TimeoutError
puts "API didn't respond before our timeout elapsed"
rescue Tradewatch::Errors::ServiceUnavailableError
puts "API returned status 503, is probably overloaded, try again later"
rescue Tradewatch::Errors::ServerError
puts "API returned some other 5xx status, this is probably a bug"
rescue Tradewatch::Errors::ResponseError => e
puts "API returned an unexpected status other than 5xx: #{e.code} #{e.message}"
rescue Tradewatch::Errors::ApiError => e
puts "Some other error occurred when calling the API: #{e.message}"
endThe SDK is instrumented with automatic retries. 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 option to configure this behavior.
require "tradewatch"
client = Tradewatch::Client.new(
base_url: "https://example.com",
max_retries: 3 # Configure max retries (default is 2)
)The SDK defaults to a 60 second timeout. Use the timeout option to configure this behavior.
require "tradewatch"
response = client.crypto.get_quote(
...,
timeout: 30 # 30 second timeout
)If you would like to send additional headers as part of the request, use the additional_headers request option.
require "tradewatch"
response = client.crypto.get_quote(
...,
request_options: {
additional_headers: {
"X-Custom-Header" => "custom-value"
}
}
)If you would like to send additional query parameters as part of the request, use the additional_query_parameters request option.
require "tradewatch"
response = client.crypto.get_quote(
...,
request_options: {
additional_query_parameters: {
"custom_param" => "custom-value"
}
}
)While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
| 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 |
