• Stars
    star
    198
  • Rank 196,898 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pipeline Extension for Live Trading

⚠️ This software is very outdated and is not recommended for use in new setups ⚠️

We will keep this project up and with the documentation for the parts that remain for those users who are still using this, but we suggest migrating to another tool until we perform a major refactoring of this project to bring it up to speed. If this is something you'd like to see please reach out to us to let us know!

The docs below still talk about zipline and Quantopian however Quantopian has since gone out of business and the below hasn't yet been updated to reflect this.

If you're looking for another modern alternative to zipline, we recommend checking out zipline-reloaded in the meantime while we review committing to a major refactor of this project.

Zipline Pipeline Extension for Live Trading

pipeline-live is an extension for zipline pipeline independently usable for live trading, outside of zipline. While zipline is a great backtesting library, the default Pipeline API requires complicated setup for data bundle, which is often challenging to average users. Quantopian's proprietary data sources such as Morningstar is also not available to many. This library is to address this issue by using online API data sources and simplify the interface for live trading usage. The interface complies the original zipline/pipeline for the most part. For more details about the Pipeline API, please see Quantopian's tutorial and zipline document.

If you are looking to use this library for your Quantopian algorithm, check out the migration document.

Data Sources

This library predominantly relies on the Alpaca Data API for daily price data. IEX Cloud data is also supported, though if too much data is requested, it stops being free. (See the note in the IEX section below.)

Install

pipeline-live is a PyPI module and you can install it using pip command.

$ pip install pipeline-live

This module is tested and expected to work with python 3.6 and later

Example

Here is a simple pipeline example. Please make sure to first set your API keys to these environment variables:

using python

import os
os.environ["APCA_API_KEY_ID"] = <ALPACA_API_KEY>
os.environ["APCA_API_SECRET_KEY"] = <ALPACA_SECRET_KEY>
# if you use the paper endpoint:
os.environ["APCA_API_BASE_URL"] = "https://paper-api.alpaca.markets"

(or do it with bash if you prefer)

from pipeline_live.engine import LivePipelineEngine
from pipeline_live.data.sources.alpaca import list_symbols
from pipeline_live.data.alpaca.pricing import USEquityPricing
from pipeline_live.data.alpaca.factors import AverageDollarVolume
from zipline.pipeline import Pipeline

eng = LivePipelineEngine(list_symbols)
top5 = AverageDollarVolume(window_length=20).top(5)
pipe = Pipeline({
    'close': USEquityPricing.close.latest,
}, screen=top5)

df = eng.run_pipeline(pipe)

'''
        close
AAPL   215.49
AMZN  1902.90
FB     172.90
QQQ    180.80
SPY    285.79
'''

Data Cache

Since most of the data does not change during the day, the data access layer caches the dataset on disk. In case you need to purge the cache, the cache data is located in $ZIPLINE_ROOT/data/daily_cache.

Pipeline API

pipeline_live.engine.LivePipelineEngine

This class provides the similar interface to zipline.pipeline.engine.SimplePipelineEngine. The main difference is its run_pipeline does not require the start and end dates as parameters, and returns a DataFrame with the data for the current date (US/Eastern time). Its constructor accepts list_symbol function that is supposed to return the full set of symbols as a string list, which is used as the maximum universe inside the engine.

Alpaca Data API

The Alpaca Data API is currently the least-limited source of pricing data supported by pipeline-live. In order to use the Alpaca Data API, you'll need to register for an Alpaca account here and generate API key information with the dashboard. Once you have your keys generated, you need to store them in the following environment variables:

APCA_API_BASE_URL
APCA_API_KEY_ID
APCA_API_SECRET_KEY

pipeline_live.data.alpaca.pricing.USEquityPricing

This class provides the basic price information retrieved from Alpaca Data API.

Where Did the Polygon integration go?

Alpaca used to offer an integration with polygon, however with the removal of that integration from the Alpaca api we removed the polygon integration here as well.

IEX Data Source API

To use IEX-source data, you need to sign up for an IEX Cloud account and save your IEX token as an environment variable called IEX_TOKEN.

IMPORTANT NOTE: IEX data is now limited for free accounts. In order to avoid using more messages than you are allotted each month, please be sure that you are not using IEX-sourced factors too frequently or on too many securities. For more information about how many messages each method will cost, please refer to this part of the IEX Cloud documentation.

pipeline_live.data.iex.pricing.USEquityPricing

This class provides the basic price information retrieved from IEX Chart API.

pipeline_live.data.iex.fundamentals.IEXCompany

This provides the DataSet interface using IEX Company API.

pipeline_live.data.iex.fundamentals.IEXKeyStats

This provides the DataSet interface using IEX Key Stats API.

pipeline_live.data.iex.factors

It is important to note that the original builtin factors from zipline does not work here as is, since some of them rely on zipline's USEquityPricing class. This package provides the same set of zipline's builtin factor classes using pipeline_live.data.iex.pricing.USEquityPricing class. For the complete list of builtin factors, please refer zipline document

pipeline_live.data.iex.classifiers.Sector()

A shortcut for IEXCompany.sector.latest

pipeline_live.data.iex.classifiers.Industry()

A shortcut for IEXCompany.industry.latest

More Repositories

1

marketstore

DataFrame Server for Financial Timeseries Data
Go
1,814
star
2

alpaca-trade-api-python

Python client for Alpaca's trade API
Python
1,552
star
3

pylivetrader

Python live trade execution library with zipline interface.
Python
622
star
4

example-scalping

A working example algorithm for scalping strategy trading multiple stocks concurrently using python asyncio
Python
619
star
5

example-hftish

Example Order Book Imbalance Algorithm
Python
615
star
6

Momentum-Trading-Example

An example algorithm for a momentum-based day trading strategy.
Python
568
star
7

alpaca-backtrader-api

Alpaca Trading API integrated with backtrader
Python
524
star
8

alpaca-trade-api-js

Node.js library for Alpaca Trade API.
JavaScript
428
star
9

alpaca-trade-api-go

Go client for Alpaca's trade API
Go
318
star
10

alpaca-py

The Official Python SDK for Alpaca API
Python
249
star
11

alpaca-trade-api-csharp

C# SDK for Alpaca Trade API https://docs.alpaca.markets/
C#
208
star
12

alpaca-ts

A TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams.
TypeScript
144
star
13

Alpaca-API

The Alpaca API is a developer interface for trading operations and market data reception through the Alpaca platform.
136
star
14

pymarketstore

Python driver for MarketStore
Python
103
star
15

user-docs

Documentation for the Alpaca platform.
HTML
72
star
16

samplealgo01

Sample algo
Python
69
star
17

slait

A time-series data cache
Go
47
star
18

roboadvisor

Python
43
star
19

example-portfolio-manager

Simple portfolio management script in python
Python
42
star
20

insomnia-workspace

An Insomnia Workspace for Alpaca API
34
star
21

ribbit-backend

Backend for Ribbit, Broker API Reference App
Go
33
star
22

blogmaterials

Jupyter Notebook
30
star
23

alpaca-postman

Postman collections for Alpaca's APIs
29
star
24

alpaca-zipline

Alpaca riding on a zipline
Python
28
star
25

ribbit-ios

iOS app for Ribbit, Broker API Reference App
Swift
28
star
26

plug-and-play-strategies

Jupyter Notebook
27
star
27

sp100algo

Follow S&P100
Python
16
star
28

alpaca-erasure

Example script to generate Erasure data
Python
15
star
29

slackbot-trader

A Slackbot that can access the Alpaca API
Python
14
star
30

ribbit-android

Android app for Ribbit, Broker API Reference App
Java
12
star
31

alpaca-docs

Developer documentation for Alpaca API's
HTML
10
star
32

broker-fastapi-backend

A reference backend for Alpaca's Broker API utilizing Python & FastAPI
Python
8
star
33

bkdocs

Broker API Documentation
HTML
8
star
34

notebooks

A collection of Jupyter notebooks for getting started with Alpaca
Jupyter Notebook
6
star
35

Alpaca-Flutter-Demo-App

A boilerplate trading application to trade crypto on Alpaca. Made with Flutter and Dart.
C++
5
star
36

alpacadecimal

Similar and compatible with decimal.Decimal, but optimized for Alpaca's data sets.
Go
5
star
37

supertrend_crypto_bot

An Alpaca Live Crypto Trading Bot built with Python!
Python
4
star
38

Triangular-Arbitrage-with-Alpaca-API-s

Python
3
star
39

quantopian-fundamentals-examples

Implementations of algorithms from https://blog.quantopian.com/fundamentals-contest-winners/ using Alpaca's API.
Python
3
star
40

plprofiler

Python
2
star
41

alpaca-discord-bot

Python
1
star
42

go-onfido

Wrapper around the go-onfido-openapi package
1
star
43

alexa-trader-skill

An Alexa skill that can access the Alpaca API
1
star
44

go-onfido-openapi

Golang sdk for onfido. Generated from openapi
Shell
1
star