Client

Trading strategy client.

A Python client class to downlaod different datasets from Trading Strategy oracle.

For usage see

class tradingstrategy.client.Client

An API client for querying the Trading Strategy datasets from a server.

  • The client will download datasets.

  • In-built disk cache is offered, so that large datasets are not redownloaded unnecessarily.

  • There is protection against network errors: dataset downloads are retries in the case of data corruption errors.

  • Nice download progress bar will be displayed (when possible)

You can Client either in

Python application usage:

import os

trading_strategy_api_key = os.environ["TRADING_STRATEGY_API_KEY"]
client = Client.create_live_client(api_key)
exchanges = client.fetch_exchange_universe()
print(f"Dataset contains {len(exchange_universe.exchanges)} exchanges")
__init__(env: tradingstrategy.environment.base.Environment, transport: tradingstrategy.transport.cache.CachedHTTPTransport)

Do not call constructor directly, but use one of create methods.

clear_caches()

Remove any cached data.

Cache is specific to the current transport.

fetch_pair_universe() pyarrow.lib.Table

Fetch pair universe from local cache or the candle server.

The compressed file size is around 5 megabytes.

If the download seems to be corrupted, it will be attempted 3 times.

fetch_exchange_universe() tradingstrategy.exchange.ExchangeUniverse

Fetch list of all exchanges form the dataset server.

fetch_all_candles(bucket: tradingstrategy.timebucket.TimeBucket) pyarrow.lib.Table

Get cached blob of candle data of a certain candle width.

The returned data can be between several hundreds of megabytes to several gigabytes and is cached locally.

The returned data is saved in PyArrow Parquet format.

For more information see tradingstrategy.candle.Candle.

If the download seems to be corrupted, it will be attempted 3 times.

fetch_all_liquidity_samples(bucket: tradingstrategy.timebucket.TimeBucket) pyarrow.lib.Table

Get cached blob of liquidity events of a certain time window.

The returned data can be between several hundreds of megabytes to several gigabytes and is cached locally.

The returned data is saved in PyArrow Parquet format.

For more information see tradingstrategy.liquidity.XYLiquidity.

If the download seems to be corrupted, it will be attempted 3 times.

fetch_chain_status(chain_id: tradingstrategy.chain.ChainId) dict

Get live information about how a certain blockchain indexing and candle creation is doing.

classmethod preflight_check()

Checks that everything is in ok to run the notebook

classmethod setup_notebook()

Setup diagram rendering and such.

Force high DPI output for all images.

classmethod create_jupyter_client(cache_path: Optional[str] = None, api_key: Optional[str] = None) tradingstrategy.client.Client

Create a new API client.

Parameters

cache_path – Where downloaded datasets are stored. Defaults to ~/.cache.

classmethod create_test_client(cache_path=None) tradingstrategy.client.Client

Create a new Capitalgram clienet to be used with automated test suites.

Reads the API key from the environment variable TRADING_STRATEGY_API_KEY. A temporary folder is used as a cache path.

By default, the test client caches data under /tmp folder. Tests do not clear this folder between test runs, to make tests faster.

classmethod create_live_client(api_key: Optional[str] = None, cache_path: Optional[pathlib.Path] = None) tradingstrategy.client.Client

Create a live trading instance of the client.

The live client is non-interactive and logs using Python logger.

Parameters
  • api_key – Trading Strategy oracle API key, starts with secret-token:tradingstrategy-…

  • cache_path – Where downloaded datasets are stored. Defaults to ~/.cache.