Rapidly build trading bots that run on any exchange
Project description
Blankly is an elegant python library for interacting with many crypto and stock exchanges for automated portfolios in a consistent way. Blankly offers a powerful feature-set, optimized for speed and ease of use.
We're bridging the gap between local development systems & live APIs by building a framework which allows backtesting, paper trading, sandbox testing, and live cross-exchange deployment without modifying a single line of trading logic.
Check out our website and our docs.
Getting Started
Installation
First install Blankly using pip
. Blankly is hosted on PyPi.
$ pip install blankly
Make sure you're using a supported version of python. The module is currently tested on these versions:
- Python 3.7+
Directory Setup and API Keys
Next, add settings.json
and keys.json
to your root project directory. More information can be found on our docs
From there, insert your API keys from your exchange into your keys.json
file.
The working directory format should look similar to this:
Project
|-script.py
|-keys.json
|-settings.json
Additional Info
For more info, and ways to do more advanced things, check out our getting started docs.
Example Use
We have a pre-built cookbook examples that implement strategies such as RSI, MACD, and the Golden Cross found in our examples.
We have made Blankly extremely easy to integrate with any existing models and price events to make it super easy to switch.
import blankly
from blankly.strategy import Strategy, StrategyState
from model import my_awesome_model
def price_event(price: float, ticker: str, state: StrategyState):
interface = state.interface
# Add this most recent price to be stored for this particular price event
history = state.variables['history']
history.append(price)
# easily integrate your model
decision = my_awesome_model(history)
# buy or sell based on that decision
if decision:
buy_order = int(.025 * interface.cash)
if buy_order > 10:
interface.market_order(ticker, 'buy', int(.025 * interface.cash))
state.variables['has_buy_order'] = True
elif state.variables['has_buy_order'] and not decision:
amt = interface.account[ticker]['available']
interface.market_order(ticker, 'sell', int(amt))
state.variables['has_buy_order'] = False
# Easily run setup code
def strategy_init(currency_pair, state: StrategyState):
state.variables['history'] = state.interface.history(symbol=currency_pair,
to='4w',
resolution='1h')['close'].tolist()
if __name__ == "__main__":
# All authentication is done in this line
exchange = blankly.CoinbasePro()
# Now just wrap it into a strategy to gain a huge amount of functionality
strategy = Strategy(exchange)
# Run the code above with a new price once a day
strategy.add_price_event(price_event,
symbol='BTC-USD',
resolution='1h',
# Pass an init function to run before any price events
init=strategy_init)
# Run the code above with a new price once every thirty minutes
strategy.add_price_event(price_event,
symbol='LINK-USD',
resolution='1h',
init=strategy_init)
strategy.start()
Supported Exchanges
Exchange | REST Support | Ticker Websocket | Order Book | Interface |
---|---|---|---|---|
Coinbase Pro | 🟢 | 🟢 | 🟢 | 🟢 |
Binance | 🟢 | 🟢 | 🟢 | 🟢 |
Alpaca | 🟢 | 🟡 | 🟡 | 🟢 |
OANDA | 🔴 | 🔴 | 🔴 | 🔴 |
🟢 = 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.
Bugs
Please report any bugs or issues on the Github's Issues page.
Disclaimer
Trading is risky. We are not responsible for losses incurred using this software, software fitness for any particular purpose, or responsibility for any issues or bugs. This is free software.
Contributing
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
Licensing
Blankly is distributed under the LGPL License. See the LICENSE for more details.
New updates every day 💪.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for blankly-1.0.0b0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33f22b558e28498eb901a93cbbbbda82475a8396f1c07f7dc0f172d4410ccd1e |
|
MD5 | c9e461db2e9393e81135e4209f466de2 |
|
BLAKE2b-256 | 1338d81e36fbf3f5c93b95b1d4730ace36ccb47b0c9982ac839d63453527dd83 |