Exchange

The exchange object is designed to be an easy & homogeneous way to interact with each exchange or brokerage added to Blankly. Each object will contain a similar set of baseline functions outlined here.

Creation

Because this is designed to work with each exchange, the creation is different depending on usage & goal.

Coinbase Pro

exchange = blankly.CoinbasePro()

Binance

exchange = blankly.Binance()

Alpaca

exchange = blankly.Alpaca()

Arguments

ArgDescriptionExamplesType
portfolio_nameOptionally fill this with a reference to a portfolio inside keys.json.'my cool portfolio'str
keys_pathOptionally fill this with a path to the keys.json file.'./keys.json'str
settings_pathOptionally fill this with a path to the settings.json file'./settings.json'str

Response

DescriptionExamplesType
An exchange objectscheduler = blankly.CoinbasePro()Exchange object.

Functions

get_name()

Get the name of the portfolio that the exchange object is using.

Response

DescriptionExamplesType
The name of the portfolio from Keys.json'my_cool_portfolio'str

get_type()

Get the type of exchange that the interface is running on.

Response

DescriptionExamplesType
A string identifier for the exchange'binance', 'coinbase_pro', 'alpaca'str

get_preferences()

Get the preferences dictionary that the exchange class is using.

Response

DescriptionExamplesType
A dictionary with defined preferences. See here.'binance', 'coinbase_pro', 'alpaca'str

get_interface()

Get the authenticated interface object (very important).

Response

DescriptionExamplesType
This gives the actual interface object to use. See here.All interfaces have identical callsICurrencyInterface

start_models(symbol=None)

Used for multiprocessed bots. This calls the run functions of each appended multiprocessed model. See the multiprocessing demo for usage.

Arguments

ArgDescriptionExamplesType
symbolModels are appended by reference to their asset. Optionally fill this with a reference to just start that single asset.'BTC-USD'str

get_model_state(self, symbol)

Returns the shared memory dictionary from the requested multiprocessed model. This is the function used by the main process to understand what other processes are doing internally.

Arguments

ArgDescriptionExamplesType
symbolThe asset identifier for the multiprocessed model'BTC-USD'str

Response

DescriptionExamplesType
A shared dictionary that can be written to and read by both processes{'heartbeat': 231}dict

get_full_state(self, symbol)

Returns the shared memory dictionary from the requested multiprocessed model as well as an exchange API request that shows the state of the coin that the process is running on.

Arguments

ArgDescriptionExamplesType
symbolThe asset identifier for the multiprocessed model'BTC-USD'str

Response

DescriptionExamplesType
A shared dictionary that can be written to and read by both processes{'model':{'heartbeat': 231}, "account": {"currency":"BTC","hold": 0.0,"available": 54.90091578}}dict

write_value(symbol, key, value)

Write a value to the shared memory dictionary. This can be used to communicate with other processes. Generally this is used for multiprocess bots.

Arguments

ArgDescriptionExamplesType
symbolAsset identifier for which bot to write the dictionary value.'BTC-USD'str
keyThe key of the value to write'stop'immutable
valueValue to write to they key'true'any

append_model(model, symbol, args=None)

Append a new blankly.BlanklyBot object to the exchange. This can be run with .start_models(). This is the append function for multiprocess bots.

Arguments

ArgDescriptionExamplesType
modelAn object inheriting from blankly.BlanklyBotSee multicore_bot.pyBot
symbolThe asset to append the bot to'BTC-USD'str
argsOptionally add any type which will be passed into the main function in the Bot class. This works well as a dictionary with key/value pairs that can give settings.{'check_interval': .5}any

get_direct_calls() -> API

This is an important function that allows the user to get the direct, unfiltered API calls to the exchange. This function can be used to bypass the user interface & opens up all implemented calls which go far beyond the scope of the interface.

This is also pre-typed for each exchange which allows autofill when using this function.

Response

DescriptionExamplesType
A direct calls object which bypasses all Blankly featuresAPIVarious API objects

get_market_clock() -> dict (Alpaca Only)

This will get the current market clock (i.e. current market timestamp, whether or not it's open and when the next open and close will be) that's running for the U.S. stock exchanges.

Response

DescriptionExamplesType
A response displaying the current timestamp, whether the market is open or not, and when the next market open or close is.dictView this for more details

Paper Trade Limit Order Watch

Because paper trading happens entirely locally, prices always have to be downloaded to be used in the paper trading system. We created a watchdog system which allows continuous background monitoring of the price on the exchange. One started, this will continue to read the price on regular intervals and execute any limit orders if necessary.

start_limit_order_watch() (Paper Trade Only)

Start the paper trade limit order watch (see explanation above).

stop_limit_order_watch() (Paper Trade Only)

Stop the paper trade limit order watch (see explanation above).