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.
This SDK requires PHP ^8.1.
composer require tradewatch-io/sdkInstantiate and use the client with the following:
<?php
namespace Example;
use Tradewatch\TradewatchClient;
use Tradewatch\Crypto\Requests\CryptoGetQuoteRequest;
$client = new TradewatchClient(
apiKey: '<value>',
);
$client->crypto->getQuote(
new CryptoGetQuoteRequest([
'symbol' => 'BTCUSD',
'precision' => 2,
]),
);When the API returns a non-success status code (4xx or 5xx response), an exception will be thrown.
use Tradewatch\Exceptions\TradewatchApiException;
use Tradewatch\Exceptions\TradewatchException;
try {
$response = $client->crypto->getQuote(...);
} catch (TradewatchApiException $e) {
echo 'API Exception occurred: ' . $e->getMessage() . "\n";
echo 'Status Code: ' . $e->getCode() . "\n";
echo 'Response Body: ' . $e->getBody() . "\n";
// Optionally, rethrow the exception or handle accordingly.
}This SDK is built to work with any HTTP client that implements the PSR-18 ClientInterface.
By default, if no client is provided, the SDK will use php-http/discovery to find an installed HTTP client.
However, you can pass your own client that adheres to ClientInterface:
use Tradewatch\TradewatchClient;
// Pass any PSR-18 compatible HTTP client implementation.
// For example, using Guzzle:
$customClient = new \GuzzleHttp\Client([
'timeout' => 5.0,
]);
$client = new TradewatchClient(options: [
'client' => $customClient
]);
// Or using Symfony HttpClient:
// $customClient = (new \Symfony\Component\HttpClient\Psr18Client())
// ->withOptions(['timeout' => 5.0]);
//
// $client = new TradewatchClient(options: [
// 'client' => $customClient
// ]);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 maxRetries request option to configure this behavior.
$response = $client->crypto->getQuote(
...,
options: [
'maxRetries' => 0 // Override maxRetries at the request level
]
);The SDK defaults to a 30 second timeout. Use the timeout option to configure this behavior.
$response = $client->crypto->getQuote(
...,
options: [
'timeout' => 3.0 // Override timeout at the request level
]
);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 |
|---|---|---|---|
getUsage() |
- | 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 |
getHistoricalOhlc(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. |
getHistoricalTicks(symbol, start, end) |
symbol, start, end | Get Historical Ticks | Get raw historical ticks for a symbol in a selected time range using cursor pagination. |
getInsights() |
- | Get Insights | Get recent currencies insights. |
getQuote(symbol) |
symbol | Last Quote | Get the last quote tick for the provided symbol. |
getQuotes(symbols) |
symbols | Last Quotes | Get the last quote tick for the provided symbols. |
getSymbols() |
- | Available Symbols | Get list of available symbols |
| Method | Required Params | Summary | Description |
|---|---|---|---|
convert(from, to) |
from, to | Conversion | Convert one symbol to another |
getExchanges() |
- | Available Exchanges | Get list of available cryptocurrency exchanges |
getHistoricalOhlc(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. |
getHistoricalTicks(symbol, start, end) |
symbol, start, end | Get Historical Ticks | Get raw historical ticks for a symbol in a selected time range using cursor pagination. |
getInsights() |
- | Get Insights | Get recent crypto insights. |
getQuote(symbol) |
symbol | Last Quote | Get the last quote tick for the provided symbol. |
getQuotes(symbols) |
symbols | Last Quotes | Get the last quote tick for the provided symbols. |
getSymbols() |
- | Available Symbols | Get list of available symbols |
| Method | Required Params | Summary | Description |
|---|---|---|---|
getHistoricalOhlc(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. |
getHistoricalTicks(symbol, start, end) |
symbol, start, end | Get Historical Ticks | Get raw historical ticks for a symbol in a selected time range using cursor pagination. |
getInsights() |
- | Get Insights | Get recent indices insights. |
getQuote(symbol) |
symbol | Last Quote | Get the last quote tick for the provided symbol. |
getQuotes(symbols) |
symbols | Last Quotes | Get the last quote tick for the provided symbols. |
getSymbols() |
- | Available Symbols | Get list of available symbols |
| Method | Required Params | Summary | Description |
|---|---|---|---|
getHistoricalOhlc(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. |
getHistoricalTicks(symbol, start, end) |
symbol, start, end | Get Historical Ticks | Get raw historical ticks for a symbol in a selected time range using cursor pagination. |
getInsights() |
- | Get Insights | Get recent stocks insights. |
getMarketHolidays(start, end) |
start, end | Get Market Holidays | Get market holidays. It takes half-days into account. |
getMarketStatus() |
- | 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. |
getMarkets() |
- | Get Markets | Get details about the markets available in this API. |
getQuote(symbol) |
symbol | Last Quote | Get the last quote tick for the provided symbol. |
getQuotes(symbols) |
symbols | Last Quotes | Get the last quote tick for the provided symbols. |
getStockData(symbol) |
symbol | Get Stock Data | Get Stock Data |
getSymbols() |
- | Available Symbols | Get list of available symbols |
getTradingHours(start, end) |
start, end | Get Trading Hours | Get trading hours. It takes half-days into account. |
stockGetCountries() |
- | Available Countries | Get list of available countries |
| Method | Required Params | Summary | Description |
|---|---|---|---|
getHistoricalOhlc(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. |
getHistoricalTicks(symbol, start, end) |
symbol, start, end | Get Historical Ticks | Get raw historical ticks for a symbol in a selected time range using cursor pagination. |
getInsights() |
- | Get Insights | Get recent commodities insights. |
getQuote(symbol) |
symbol | Last Quote | Get the last quote tick for the provided symbol. |
getQuotes(symbols) |
symbols | Last Quotes | Get the last quote tick for the provided symbols. |
getSymbols() |
- | Available Symbols | Get list of available symbols |
getTypes() |
- | Available Types | Get list of available commodity types |
