Market Data

The following provide information on obtaining market data from crypto-currency exchanges and market APIs.

class crypto_history.stock_market.stock_market_factory.StockMarketFactory

Abstract factory to generate factories per exchange

static create_data_homogenizer() → crypto_history.stock_market.stock_market_factory.AbstractMarketHomogenizer

Create an instance of a market homogenizer which is the interface to the market from the outside. It should ensure that the market data from various markets/exchanges which might have different low-level APIs is available in a uniform format.

static create_market_operations() → crypto_history.stock_market.stock_market_factory.AbstractMarketOperations

Create the instance of the class to channel the right requests to the low level market requester.

static create_market_requester() → crypto_history.stock_market.request.AbstractMarketRequester

Create the low-level market requester instance per exchange

static create_ohlcv_field_types() → crypto_history.stock_market.stock_market_factory.AbstractOHLCVFieldTypes
static create_time_interval_chunks() → crypto_history.stock_market.stock_market_factory.AbstractTimeIntervalChunks
class crypto_history.stock_market.stock_market_factory.ConcreteBinanceFactory

Binance’s factory for creating factories

create_data_homogenizer() → crypto_history.stock_market.stock_market_factory.BinanceHomogenizer

Creates the instance of the Binance Market Homogenizer

Returns:Instance of BinanceHomogenizer
Return type:BinanceHomogenizer
create_market_operations() → crypto_history.stock_market.stock_market_factory.BinanceMarketOperations

Creates the instance of the Binance Market Operator

Returns:Instance of BinanceMarketOperator
Return type:BinanceMarketOperations
class crypto_history.stock_market.stock_market_factory.AbstractMarketHomogenizer

Synthesizes the information obtained from various different market operator to a consistent format

OHLCVFields = None
get_all_base_assets()
get_all_coins_ticker_objects() → crypto_history.stock_market.tickers.TickerPool

Generates the standard/uniform TickerPool object which should be consistent no matter which exchange it is coming from

Returns:TickerPool which contains all the different tickers and holds it in one
Return type:TickerPool
get_all_raw_tickers()
get_all_reference_assets()
get_history_for_ticker(*args, **kwargs) → map

Gets the history of the ticker symbol

Parameters:
  • *args – unknown, as it depends on the exchange
  • **kwargs – unknown, as it depends on the exchange
Returns:

map object of history of the ticker

Return type:

map

get_named_ohlcv_tuple()
get_ticker_instance(*args, **kwargs)

Gets the standard ticker dataclass object. Note that the fields may be dependent on the exchange that it is coming from

Parameters:
  • *args – unknown, as it depends on the exchange
  • **kwargs – unknown, as it depends on the exchange
Returns:

dataclass instance of the symbol info

Return type:

dataclass

class crypto_history.stock_market.stock_market_factory.BinanceHomogenizer
get_all_base_assets() → List[T]

Obtains the list of all base assets

get_all_coins_ticker_objects

Obtains the exchange-independent TickerPool from all the tickers/symbols that are available on the exchange

Returns:All tickers and their information stored in the TickerPool defined in
Return type:TickerPool

# TODO

get_all_raw_tickers() → List[T]

Obtains the list of all raw tickers available on binance

get_all_reference_assets() → List[T]

Obtains the list of all reference assets

get_exchange_assets(type_of_asset: str) → Generator[T_co, T_contra, V_co]

Obtains the type of asset from the exchange. :param type_of_asset: string identifier that the binance API uses to identify the key in each symbol :type type_of_asset: str

Returns:The generator of items that are available in the exchange
Return type:Generator
get_exchange_info()
get_history_for_ticker(*args, **kwargs) → map

Gets the history of the ticker for the desired duration,

# TODO Probably yank the doc from MarketOperator to here

Parameters:
  • *args – See the BinanceMarketOperator.            get_raw_history_for_ticker for arguments
  • **kwargs – See the BinanceMarketOperator.            get_raw_history_for_ticker for arguments
Returns:

map of the history of the ticker mapped to the OHLCVFields namedtuple

Return type:

map

get_set_of_ticker_attributes(attribute: str)

Aggregates the set items of the required attribute across the whole history

Parameters:attribute – The attribute/key which is the common term in the history whose values are to be identified
Returns:set of values whose attributes are common
Return type:set
get_ticker_instance(ticker_name: str)

Obtains the TickerDataclass based on the string of the ticker name provided

Parameters:ticker_name (str) – ticker name whose standard Ticker dataclass object is desired
Returns:instance of the dataclass of the ticker
Return type:dataclass
class crypto_history.stock_market.stock_market_factory.AbstractMarketOperations

Abstract Base Class to serve as the parent for all market operators.

Seeing that the market requester may respond with different formats, it is not possible to know the signature of the method. The arguments and the return values are unknown by the AbstractMarketOperator

get_all_raw_tickers(*args, **kwargs)

Obtain all the tickers from the low-level market requester. Seeing that the market requester may respond with different formats, it is not possible to know the signature of the method

get_exchange_info(*args, **kwargs)

Gets general properties of the exchange

get_raw_history_for_ticker(*args, **kwargs)

Obtain the raw history of a particular ticker.

get_raw_symbol_info(*args, **kwargs)

Obtains the information on the particular ticker. It is not known what are the exact information that is going to be received because the information is coming from various exchanges

class crypto_history.stock_market.stock_market_factory.BinanceMarketOperations

Binance’s market operator. Implements methods to get market knowledge

get_all_raw_tickers()

Gets all the tickers available on the binance exchange.

Returns:All the raw tickers obtained from the python-binance (python-binance) In binance, the format of each raw ticker is {“symbol”: <>, “price”: <>}
Return type:list
get_exchange_info()

Obtains the complete information available at the exchange Returns:

get_raw_history_for_ticker(ticker: str, interval: str, start_time: int, end_time: int) → List[T]

Gets the kline history of the ticker from binance exchange

Parameters:
  • ticker (str) – ticker whose history has to be pulled
  • interval (str) – interval of the history (eg. 1d, 3m, etc). See binance.enums() in python-binance
  • start_time (int) – Start date string in exchange-format
  • end_time (int) – End date string in exchange-format
Returns:

List of snapshots of history. Each snapshot is a list of collection of OHLCV values. See details in BinanceHomogenizer.OHLCVFields

Return type:

list

get_raw_symbol_info(symbol: str)

Obtains the information for the symbol/ticker requested

Parameters:symbol (str) – symbol of the ticker whose information is desired
Returns:The raw information of the ticker desired with information where the keys are the baseAsset, precision, quoteAsset, etc. See binance.AsyncClient.get_symbol_info() in python-binance
Return type:dict
class crypto_history.stock_market.request.AbstractMarketRequester

AbstractBaseClass for the low-level market requester

request(method_name: str, *args, **kwargs)

Interface to the user of the low level request made to the API server

Parameters:
  • method_name – name of the method to be called on the client object.
  • *args – arguments transferred by the market operator
  • **kwargs – arguments transferred by the market operator
Returns:

response from the market/exchange

class crypto_history.stock_market.request.BinanceRequester

Low level requester for the Binance API. api_key and api_secret are not required to get market information. Limit for requests are officially set at 2400 per minute. However, it is throttled to 500 per minute

class crypto_history.stock_market.stock_market_factory.AbstractOHLCVFieldTypes
class OHLCVFields
get_dict_name_type()
get_named_tuple()
class crypto_history.stock_market.stock_market_factory.BinanceRequester

Low level requester for the Binance API. api_key and api_secret are not required to get market information. Limit for requests are officially set at 2400 per minute. However, it is throttled to 500 per minute

class crypto_history.stock_market.stock_market_factory.AbstractTimeIntervalChunks

Abstract class to handle the chunking of dates as the exchanges have limits on the length of the interval of history

get_exchange_specific_sub_chunks(sub_chunks: List[tuple]) → List[tuple]

Gets the exchange specific sub-chunk from default sub-chunks :param sub_chunks: default sub-chunks to be converted to exchange specific :type sub_chunks: list

Returns:List of exchange-specific formatted sub-chunks
get_time_range_for_historical_calls(raw_time_range_dict: Dict[KT, VT]) → List[tuple]

Obtains the time ranges for making the historical calls.

Parameters:
  • raw_time_range_dict – Dictionary of the
  • (start – str, end:str): (type_of_interval: str)
Returns:

List of the tuples of the exchange-specific format. ((start_time, end_time), type_of_interval)

limit = inf
static sanitize_datetime_to_exchange_specific(datetime_obj: datetime.datetime)

Converts the datetime object to exchange specific format

static sanitize_item_to_datetime_object(item_to_parse: str) → datetime.datetime

Converts/sanitizes the string to the datetime.datetime object .. rubric:: Notes

Timezone is not handled. The local timezone is considered by dateutil’s parser

Parameters:item_to_parse (str) – the item that has to be converted
Returns:datetime.datetime object from the string
url = ''
class crypto_history.stock_market.stock_market_factory.BinanceTimeIntervalChunks

Binance specific information for the interval generation

limit = 1000
static sanitize_datetime_to_exchange_specific(datetime_obj: datetime.datetime) → int

Converts the datetime object to binance specific format for making the requests :param datetime_obj: datetime.datetime object which needs to be converted

Returns:binance specific format
url = 'https://github.com/binance-exchange/binance- official-api-docs/blob/master/rest-api.md#enum-definitions'