### Install Blankly with Pip Source: https://github.com/blankly-finance/blankly/blob/main/README.md Installs the Blankly library using pip, the Python package installer. This is the primary method for getting started with Blankly. ```bash pip install blankly ``` -------------------------------- ### Install Testing Dependencies with Pip Source: https://github.com/blankly-finance/blankly/blob/main/CONTRIBUTING.md Installs the necessary testing dependencies, pytest and pytest_mock, using pip. This is a prerequisite for running the project's tests locally. ```bash pip install pytest pytest_mock ``` -------------------------------- ### Start Blankly Strategy Source: https://github.com/blankly-finance/blankly/blob/main/README.md Initiates the trading strategy. This is a core function for running a bot with Blankly. ```python strategy.start() ``` -------------------------------- ### Initialize Blankly Project Source: https://github.com/blankly-finance/blankly/blob/main/README.md Initializes a new Blankly project, creating essential configuration files like keys.json, settings.json, backtest.json, and a sample bot.py script. ```bash blankly init ``` -------------------------------- ### Transition from Backtesting to Live Trading with Blankly Source: https://github.com/blankly-finance/blankly/blob/main/README.md Shows a simple transition from a backtested strategy to a live trading execution within the Blankly framework. It highlights how a single line of code can switch the execution mode from simulation to live trading. ```python # Just turn this strategy.backtest(to='1y') ``` -------------------------------- ### Initialize and Trade Across Multiple Asset Classes with Blankly Source: https://github.com/blankly-finance/blankly/blob/main/README.md Demonstrates how to initialize trading interfaces for different asset classes like stocks, crypto, and futures using Blankly. It shows how to perform market orders across these asset types and access specific futures functionalities. ```python from blankly import Alpaca, CoinbasePro stocks = Alpaca() crypto = CoinbasePro() futures = BinanceFutures() # Easily perform the same actions across exchanges & asset types stocks.interface.market_order('AAPL', 'buy', 1) crypto.interface.market_order('BTC-USD', 'buy', 1) # Full futures feature set futures.interface.get_hedge_mode() ``` -------------------------------- ### Backtest Custom Data with Blankly's Model Framework Source: https://github.com/blankly-finance/blankly/blob/main/README.md Illustrates how to backtest a trading strategy using custom event data, such as tweets, with Blankly's `Model` framework. It covers defining a trading logic within the `main` and `event` methods, adding custom data sources like JSON files, and integrating price data for backtesting. ```python import blankly """ This example shows how backtest over tweets """ class TwitterBot(blankly.Model): def main(self, args): while self.has_data: self.backtester.value_account() self.sleep('1h') def event(self, type_: str, data: str): # Now check if it's a tweet about Tesla if 'tsla' in data.lower() or 'gme' in data.lower(): # Buy, sell or evaluate your portfolio pass if __name__ == "__main__": exchange = blankly.Alpaca() model = TwitterBot(exchange) # Add the tweets json here model.backtester.add_custom_events(blankly.data.JsonEventReader('./tweets.json')) # Now add some underlying prices at 1 month model.backtester.add_prices('TSLA', '1h', start_date='3/20/22', stop_date='4/15/22') # Backtest or run live print(model.backtest(args=None, initial_values={'USD': 10000})) ``` -------------------------------- ### Run Blankly Tests with Pytest Source: https://github.com/blankly-finance/blankly/blob/main/CONTRIBUTING.md Executes all tests within the Blankly project using the pytest framework. Ensure you are in the root Blankly directory before running this command. ```bash pytest ``` -------------------------------- ### Event-Driven Strategy with Custom Events (Python) Source: https://github.com/blankly-finance/blankly/blob/main/blankly/BACKTESTING_ENGINEERING.md Demonstrates how to create an event-driven strategy within the blankly backtesting engine. This snippet shows how to handle custom events, specifically checking for tweets mentioning 'microsoft' and executing a market order. ```python # New events are injected here def event(self, type_: str, data: str): # Now check if it's a tweet about microsoft if type_ == "tweet": if 'msft' in data.lower(): print("Buying microsoft...") self.interface.market_order('MSFT', 'buy', 1) else: print("Message did not contain microsoft") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.