β Blankly is an elegant python library for interacting with many crypto exchanges on multiple portfolios in a consistent way. Blankly offers a powerful feature-set, optimized for speed and ease of use.
Check out our website.
-
Full REST API support for non-margin accounts on listed exchanges
-
Ticker websocket support
-
Order book websocket support
-
Fully multiprocessed bots with flexible arguments.
-
Quickstart access for interacting with exchanges
-
Support for multiple portfolios on multiple exchanges, all independently
-
Multi-process communication
-
Long term and high resolution historical data downloads as pandas dataframes
-
Single pip module (
pip install Blankly
) -
Asynchronous callbacks from ticker feeds
-
ZeroRPC server to report to Javascript or React **
-
Easy access to raw API calls
-
Customizable circular buffer websocket feeds
-
Support for coinbase pro & binance sandbox modes
-
Instant paper trade wrapper for supported exchanges
-
Run scheduled functions natively
-
Logs for websocket feeds
-
Status management for purchases
-
Interface that allows calls to each supported exchange to be identical:
Buy example for Coinbase Pro and Binance:
Coinbase Pro:
self.Interface.market_order(.01, "buy", "BTC-USD")
Binance:
self.Interface.market_order(.01, "buy", "BTC-USD")
** Means that the feature is still in development but has some degree of support.
- Backtesting (
bot.backtest(time_frame)
) - Deployment (
> Blankly push bot/*
) - Online hosting
- Using Blankly is incredibly easy. It just requires the pip module and 3 basic files. First install the pip module by
pip install Blankly
- Next you need the files in the
Examples
folder:
Basic_Bot.py
Keys_Example.json
Settings.json
-
Place these in the
root
orworking directory
of the project. -
Rename
Keys_Example.json
toKeys.json
or create your own.json
that has the same structure. -
Insert the API keys from your exchange into the renamed
Keys.json
file.- You can add multiple portfolios! You can specify the name of the portfolio to load when you construct the exchange.
- Example:
Blankly.Coinbase_Pro(portfolio_name="my cool portfolio")
). - If you don't provide one to the constructor, it will just default to the first one given in the
Keys.json
file and show a warning.
-
The script defaults to Coinbase Pro. If you're using that, great! If not, change the line that says:
exchange = Blankly.Coinbase_Pro()
to one that matches your exchange, such as:
exchange = Blankly.Binance()
-
Everything should work! Run the
Basic_Bot
example inBasic_Bot.py
. Note a warning will be shown because theBasic_Bot
script does not specify the exchange name by default (explained in step 5 above).- Note the library is developed on Python 3.7, but most modern versions of python 3 should work.
The comments offer a decent amount of description for the behavior, but here is a broader overview:
β The motivation behind this is to allow full independence between each bot, but still giving it the ability to report back to the main thread easily. The setup runs by specifying three increasingly specific things about the behavior we want:
-
We first declare that we want to run on a certain
exchange
, such as Coinbase Pro or Binance. This is done with (for example)Blankly.Coinbase_Pro()
-
Documentation refers to this as the
exchange
-
if __name__ == "__main__": """ Easily setup and run a model on any exchange """ # This creates an authenticated exchange. Now we can append models. exchange = Blankly.Coinbase_Pro() # Imagine this: # Coinbase Pro <-- Choosing to assign this bot to this exchange # Kraken # Binance
-
-
We initialize the bot object. This creates a boilerplate bot that isn't attached or running on anything yet.
-
# Create the bot. bot=Bot()
-
-
This same function is also attached to a
portfolio
within the exchange. Each portfolio has access to eachcurrency
on theexchange
. This means that each portfolio is independent from the other. You can tell it which portfolio you want by naming it in theKeys.json
file and then declaring theportfolio_name
argument to match the same name inKeys.json
-
Documentation refers to this set of currencies as a
portfolio
-
# Add it to run as the coinbase_pro bitcoin model exchange.append_model(bot, "BTC-USD") # Imagine this: # Coinbase Pro: # Bitcoin # Ethereum # Stellar # The Graph <-- Added to the data from this currency
-
-
The code above also declares the
currency
that we want it to run on within theportfolio
. The bot is attached to this currency and is provided default ways to interact with the exchange.- Documentation calls this the
currency
. Bots are by default not currency specific because this dramatically enhances portability.
- Documentation calls this the
-
We then ask the model to start. By default this iterates through all the attached models and queries them to start but you can also specify a particular currency to begin executing the bot attached to it.
-
# Begins running the main() function of the model on a different process exchange.start_models() # Imagine this: # Coinbase Pro: # Bitcoin # Ethereum # Stellar # The Graph <-- Bot <-- Asking to start
-
-
The bot then starts the main class. The example updates the "heartbeat" value every second. The main thread then reads this and prints it along with some exchange information about that currency.
-
Some default, pre-authenticaed objects are provided to quick start interact with the exchange:
self.Interface: allows API through the Blankly exchange interface. The interface object is already authenticated, so the calls are ready to go!
self.Ticker_Manager: Allows easy access to a websocket ticker. The actual ticker object can be pulled by self.Ticker_Manager.get_ticker(). This offers all kinds of functionality. See the docs for more information. By default this will be calling the
price_event
function. -
Main thread calling:
-
# Now other processes can be created or just continue with this one. while True: # Print the state every 2 seconds state = exchange.get_full_state("BTC-USD") Blankly.utils.pretty_print_JSON(state) time.sleep(1)
-
Bot state updates:
-
while True: # This demonstrates a way to change the state. The default script just reports the state on this currency. # Increment heartbeat value by one every second self.update_state("Heartbeat", self.get_state()["Heartbeat"] + 1) time.sleep(1)
-
Exchange | REST Support | Ticker Websocket | Order Book | Interface |
---|---|---|---|---|
Coinbase Pro | π’ | π’ | π’ | π’ |
Binance | π’ | π’ | π’ | π‘ |
Alpaca | π‘ | π΄ | π΄ | π‘ |
π’ = working
π‘ = in development, some or most features are working
π΄ = planned but not yet in development
- Interface calls take ~300 Β΅s extra to homogenize the exchange data.
https://edove.gitbook.io/blankly/
Please report any bugs or issues in Github's Issues page.
Trading is risky. We are not responsible for losses incurred using this software.
If you would like to support the project, pull requests are welcome. You can also contribute just by telling us what you think of Blankly: https://forms.gle/4oAjG9MKRTYKX2hP9
New updates every day πͺ.