simple live trading framework
Project description
pylivetrader
pylivetrader is a simple python live trading framework with zipline interface.
Simple Usage
Here is the example dual moving average algorithm (by quantopian/zipline). We provide mostly the same API interfaces with zipline.
from pylivetrader.api import order_target, symbol
def initialize(context):
context.i = 0
context.asset = symbol('AAPL')
def handle_data(context, data):
# Compute averages
# data.history() has to be called with the same params
# from above and returns a pandas dataframe.
short_mavg = data.history(context.asset, 'price', bar_count=100, frequency="1m").mean()
long_mavg = data.history(context.asset, 'price', bar_count=300, frequency="1m").mean()
# Trading logic
if short_mavg > long_mavg:
# order_target orders as many shares as needed to
# achieve the desired number of shares.
order_target(context.asset, 100)
elif short_mavg < long_mavg:
order_target(context.asset, 0)
You can run your algorithm from CLI tool named pylivetrader
, simply like below. Then your algorithm just start running with broker API. You don't need to ready for bundle file in advance as zipline does.
$ pylivetrader run -f algo.py --broker-config config.yaml
Config file is just simple yaml or json format.
$ cat config.yaml
key_id: BROKER_API_KEY
secret: BROKER_SECRET
Installation
Install with pip.
$ pip install pylivetrader
Supported Broker
Alpaca
Configuration by environment variables.
$ export APCA_API_KEY_ID={your api key id}
$ export APCA_API_SECRET_KEY={your api secret key}
$ pylivetrader run -f algo.py
Configuration by config file. Either yaml or json.
$ cat config.yaml
key_id: {your api key id}
secret: {your api secret key}
$ pylivetrader run -f algo.py --broker-config config.yaml
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
pylivetrader-0.0.4.tar.gz
(63.5 kB
view hashes)
Built Distribution
Close
Hashes for pylivetrader-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eee037aed9bf816fd7c5e83f6a6d713049e41af2d4812e8d24541727e89b386f |
|
MD5 | 7a381ee4909f66d64c9b76badc5ba1c0 |
|
BLAKE2b-256 | f4d06e059c4a1a3ad81bd9aaa4c5f9c94a84959b47d0a78844179077e3c7fa3d |