UnicornFy

A python module to unify received raw data from crypto exchanges

The python module UnicornFy is unifying the received raw data from crypto exchanges.

This serves two needs:

  1. Its easyier to work with well formed names that dont change for every exchange
  2. if the exchange is doing changes, the UnicornFy module can handle it on a central point.

How to use it?

Download the latest release and put it to your project or install with `pip install unicorn-fy` from PyPI.

from unicorn_fy.unicorn_fy import UnicornFy
unicorn_fied_stream_data = UnicornFy.binance_websocket(received_raw_stream_data)

Example file:
https://github.com/unicorn-data-analysis/unicorn_fy/blob/master/example_unicorn_fy.py

UnicornFy API documentation

class unicorn_fy.UnicornFy

Unify received data from crypto exchanges

Supported exchanges:
  • Binance

static binance_com_websocket(raw_stream_data)

unicorn_fy binance.com raw_stream_data

Parameters

stream_data_json (json) – The received raw stream data from the Binance.com websocket

Returns

dict

static binance_je_websocket(raw_stream_data)

unicorn_fy binance.je raw_stream_data

Parameters

stream_data_json (json) – The received raw stream data from the Binance.je (Jersey) websocket

Returns

dict

static get_latest_version()

Get the version of the latest available release (cache time 1 hour)

Returns

str or False

static get_version()

Get the package/module version

Returns

str

get_latest_release_info()

Get infos about the latest available release

Returns

dict or False

is_update_availabe()

Is a new release of this package available?

Returns

bool

Binance mapping com/je

unicorn_fied_version = ['binance', '0.2.0']
unicorn_fied_data['unicorn_fied'] = unicorn_fied_version

!miniTicker@arr

stream_data['stream'] = '!miniTicker@arr'
unicorn_fied_data = {'stream_type': stream_data['stream'],
'event_type': stream_data['data']['e'],
'event_time': stream_data['data']['E'],
'symbol': stream_data['data']['s'],
'close_price': stream_data['data']['c'],
'open_price': stream_data['data']['o'],
'high_price': stream_data['data']['h'],
'low_price': stream_data['data']['l'],
'taker_by_base_asset_volume': stream_data['data']['v'],
'taker_by_quote_asset_volume': stream_data['data']['q']}

!ticker@arr

stream_data['stream'] = '!ticker@arr'
unicorn_fied_data = {'stream_type': stream_data['stream'],
'event_type': stream_data['data']['e'],
'event_time': stream_data['data']['E'],
'symbol': stream_data['data']['s'],
'price_change': stream_data['data']['p'],
'price_change_percent': stream_data['data']['P'],
'weighted_average_price': stream_data['data']['w'],
'trade_before_24h_window': stream_data['data']['x'],
'last_price': stream_data['data']['c'],
'last_quantity': stream_data['data']['Q'],
'best_bid_price': stream_data['data']['b'],
'best_bid_quantity': stream_data['data']['B'],
'best_ask_price': stream_data['data']['a'],
'best_ask_quantity': stream_data['data']['A'],
'open_price': stream_data['data']['o'],
'high_price': stream_data['data']['h'],
'low_price': stream_data['data']['l'],
'total_traded_base_asset_volume': stream_data['data']['v'],
'total_traded_quote_asset_volume': stream_data['data']['q'],
'statistics_open_time': stream_data['data']['O'],
'statistics_close_time': stream_data['data']['C'],
'first_trade_id': stream_data['data']['F'],
'last_trade_id': stream_data['data']['L'],
'total_nr_of_trades': stream_data['data']['n']}

24hrMiniTicker

stream_data = {'data': stream_data[0]}
unicorn_fied_data = {'stream_type': stream_data['stream'],
'event_type': stream_data['data']['e'],
'event_time': stream_data['data']['E'],
'symbol': stream_data['data']['s'],
'close_price': stream_data['data']['c'],
'open_price': stream_data['data']['o'],
'high_price': stream_data['data']['h'],
'low_price': stream_data['data']['l'],
'taker_by_base_asset_volume': stream_data['data']['v'],
'taker_by_quote_asset_volume': stream_data['data']['q']}

24hrTicker

stream_data = {'data': stream_data[0]}
unicorn_fied_data = {'stream_type': stream_data['stream'],
'event_type': stream_data['data']['e'],
'event_time': stream_data['data']['E'],
'symbol': stream_data['data']['s'],
'price_change': stream_data['data']['p'],
'price_change_percent': stream_data['data']['P'],
'weighted_average_price': stream_data['data']['w'],
'trade_before_24h_window': stream_data['data']['x'],
'last_price': stream_data['data']['c'],
'last_quantity': stream_data['data']['Q'],
'best_bid_price': stream_data['data']['b'],
'best_bid_quantity': stream_data['data']['B'],
'best_ask_price': stream_data['data']['a'],
'best_ask_quantity': stream_data['data']['A'],
'open_price': stream_data['data']['o'],
'high_price': stream_data['data']['h'],
'low_price': stream_data['data']['l'],
'total_traded_base_asset_volume': stream_data['data']['v'],
'total_traded_quote_asset_volume': stream_data['data']['q'],
'statistics_open_time': stream_data['data']['O'],
'statistics_close_time': stream_data['data']['C'],
'first_trade_id': stream_data['data']['F'],
'last_trade_id': stream_data['data']['L'],
'total_nr_of_trades': stream_data['data']['n']}

aggTrade

unicorn_fied_data = {'stream_type': stream_data['stream'],
'event_type': stream_data['data']['e'],
'event_time': stream_data['data']['E'],
'symbol': stream_data['data']['s'],
'aggregate_trade_id': stream_data['data']['a'],
'price': stream_data['data']['p'],
'quantity': stream_data['data']['q'],
'first_trade_id': stream_data['data']['f'],
'last_trade_id': stream_data['data']['l'],
'trade_time': stream_data['data']['T'],
'is_market_maker': stream_data['data']['m'],
'ignore': stream_data['data']['M']

depth

unicorn_fied_data = {'stream_type': stream_data['stream'],
'event_type': stream_data['data']['e'],
'symbol': stream_data['stream'][:stream_data['stream'].find('@')].upper(),
'last_update_id': stream_data['data']['lastUpdateId'],
'bids': stream_data['data']['bids'],
'asks': stream_data['data']['asks']}

depthUpdate

unicorn_fied_data = {'stream_type': stream_data['stream'],
'event_type': stream_data['data']['e'],
'event_time': stream_data['data']['E'],
'symbol': stream_data['data']['s'],
'first_update_id_in_event': stream_data['data']['U'],
'final_update_id_in_event': stream_data['data']['u'],
'bids': stream_data['data']['b'],
'asks': stream_data['data']['a']}

executionReport

unicorn_fied_data = {'stream_type': '!userData@arr',
'event_type': stream_data['data']['e'],
'event_time': stream_data['data']['E'],
'symbol': stream_data['data']['s'],
'client_order_id': stream_data['data']['c'],
'side': stream_data['data']['S'],
'order_type': stream_data['data']['o'],
'time_in_force': stream_data['data']['f'],
'order_quantity': stream_data['data']['q'],
'order_price': stream_data['data']['p'],
'stop_price': stream_data['data']['P'],
'iceberg_quantity': stream_data['data']['F'],
'ignore_g': stream_data['data']['g'],
'original_client_order_id': stream_data['data']['C'],
'current_execution_type': stream_data['data']['x'],
'current_order_status': stream_data['data']['X'],
'order_reject_reason': stream_data['data']['r'],
'order_id': stream_data['data']['i'],
'last_executed_quantity': stream_data['data']['l'],
'cumulative_filled_quantity': stream_data['data']['z'],
'last_executed_price': stream_data['data']['L'],
'commission_amount': stream_data['data']['n'],
'commission_asset': stream_data['data']['N'],
'transaction_time': stream_data['data']['T'],
'trade_id': stream_data['data']['t'],
'ignore_I': stream_data['data']['I'],
'is_order_working': stream_data['data']['w'],
'is_trade_maker_side': stream_data['data']['m'],
'ignore_M': stream_data['data']['M'],
'order_creation_time': stream_data['data']['O'],
'cumulative_quote_asset_transacted_quantity': stream_data['data']['Z'],
'last_quote_asset_transacted_quantity': stream_data['data']['Y']}

kline

stream_data['data'] = UnicornFy.set_to_false_if_not_exist(stream_data['data'], 'f')
stream_data['data'] = UnicornFy.set_to_false_if_not_exist(stream_data['data'], 'L')
unicorn_fied_data = {'stream_type': stream_data['stream'],
'event_type': stream_data['data']['e'],
'event_time': stream_data['data']['E'],
'symbol': stream_data['data']['s'],
'kline': {'kline_start_time': stream_data['data']['k']['t'],
'kline_close_time': stream_data['data']['k']['T'],
'symbol': stream_data['data']['k']['s'],
'interval': stream_data['data']['k']['i'],
'first_trade_id': stream_data['data']['f'],
'last_trade_id': stream_data['data']['L'],
'open_price': stream_data['data']['k']['o'],
'close_price': stream_data['data']['k']['c'],
'high_price': stream_data['data']['k']['h'],
'low_price': stream_data['data']['k']['l'],
'base_volume': stream_data['data']['k']['v'],
'number_of_trades': stream_data['data']['k']['n'],
'is_closed': stream_data['data']['k']['x'],
'quote': stream_data['data']['k']['q'],
'taker_by_base_asset_volume': stream_data['data']['k']['V'],
'taker_by_quote_asset_volume': stream_data['data']['k']['Q'],
'ignore': stream_data['data']['k']['B']}}

outboundAccountInfo

unicorn_fied_data = {'stream_type': '!userData@arr',
'event_type': stream_data['data']['e'],
'event_time': stream_data['data']['E'],
'maker_commission_rate': stream_data['data']['m'],
'taker_commission_rate': stream_data['data']['t'],
'buyer_commission_rate': stream_data['data']['b'],
'seller_commission_rate': stream_data['data']['s'],
'can_trade': stream_data['data']['T'],
'can_withdraw': stream_data['data']['W'],
'can_deposit': stream_data['data']['D'],
'balances': {'asset': item['a'],
'free': item['f'],
'locked': item['l']}}

trade

unicorn_fied_data = {'stream_type': stream_data['stream'],
'event_type': stream_data['data']['e'],
'event_time': stream_data['data']['E'],
'symbol': stream_data['data']['s'],
'trade_id': stream_data['data']['t'],
'price': stream_data['data']['p'],
'quantity': stream_data['data']['q'],
'buyer_order_id': stream_data['data']['b'],
'seller_order_id': stream_data['data']['a'],
'trade_time': stream_data['data']['T'],
'is_market_maker': stream_data['data']['m'],
'ignore': stream_data['data']['M']}