Skip to content

tradewatch-io/ruby-sdk

Repository files navigation

TradeWatch.io Ruby SDK

TradeWatch.io logo

Official SDK for the TradeWatch.io API.

Other SDKs

Python SDK TypeScript SDK .NET SDK PHP SDK Java SDK Go SDK Swift SDK Rust 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.

Reference

A full reference for this library is available here.

Usage

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
)

Environments

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.

Environments

require "tradewatch"

tradewatch = Tradewatch::Client.new(
    base_url: Tradewatch::Environment::DEFAULT
)

Custom URL

require "tradewatch"

client = Tradewatch::Client.new(
    base_url: "https://example.com"
)

Errors

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}"
end

Advanced

Retries

The 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:

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

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)
)

Timeouts

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
)

Additional Headers

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"
        }
    }
)

Additional Query Parameters

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"
        }
    }
)

Contributing

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!

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