All Projects → alpacahq → Alpaca Backtrader Api

alpacahq / Alpaca Backtrader Api

Licence: apache-2.0
Alpaca Trading API integrated with backtrader

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Alpaca Backtrader Api

cira
Cira algorithmic trading made easy. A Façade library for simpler interaction with alpaca-trade-API from Alpaca Markets.
Stars: ✭ 21 (-91.46%)
Mutual labels:  finance, trading, trading-bot, stock-market, algotrading
algotrading-example
algorithmic trading backtest and optimization examples using order book imbalances. (bitcoin, cryptocurrency, bitmex, binance futures, market making)
Stars: ✭ 169 (-31.3%)
Mutual labels:  trading, trading-bot, algotrading, trading-algorithms
Algotrading
Algorithmic trading framework for cryptocurrencies.
Stars: ✭ 249 (+1.22%)
Mutual labels:  trading-bot, trading, trading-algorithms, algotrading
trading sim
📈📆 Backtest trading strategies concurrently using historical chart data from various financial exchanges.
Stars: ✭ 21 (-91.46%)
Mutual labels:  finance, trading, trading-bot, stock-market
AutoTrader
A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
Stars: ✭ 227 (-7.72%)
Mutual labels:  finance, trading, trading-bot, trading-algorithms
Awesome Quant
A curated list of insanely awesome libraries, packages and resources for Quants (Quantitative Finance)
Stars: ✭ 8,205 (+3235.37%)
Mutual labels:  trading-bot, finance, trading-algorithms, algotrading
Turingtrader
The Open-Source Backtesting Engine/ Market Simulator by Bertram Solutions.
Stars: ✭ 132 (-46.34%)
Mutual labels:  trading-bot, trading, finance, trading-algorithms
Machine Learning And Ai In Trading
Applying Machine Learning and AI Algorithms applied to Trading for better performance and low Std.
Stars: ✭ 258 (+4.88%)
Mutual labels:  trading-bot, trading, finance, trading-algorithms
Lean
Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
Stars: ✭ 5,675 (+2206.91%)
Mutual labels:  trading-bot, finance, trading-algorithms, trading
Quantdom
Python-based framework for backtesting trading strategies & analyzing financial markets [GUI ]
Stars: ✭ 449 (+82.52%)
Mutual labels:  trading, finance, stock-market, algotrading
Ta Rs
Technical analysis library for Rust language
Stars: ✭ 248 (+0.81%)
Mutual labels:  trading, finance, stock-market, trading-algorithms
Pandas Ta
Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 130+ Indicators
Stars: ✭ 962 (+291.06%)
Mutual labels:  trading, finance, stock-market, trading-algorithms
Pipeline Live
Pipeline Extension for Live Trading
Stars: ✭ 154 (-37.4%)
Mutual labels:  trading-bot, trading, finance, algotrading
Mop
Stock market tracker for hackers.
Stars: ✭ 1,534 (+523.58%)
Mutual labels:  finance, trading, stock-market
Astibot
Astibot is a simple, visual and automated trading software for Coinbase Pro cryptocurrencies (Bitcoin trading bot)
Stars: ✭ 104 (-57.72%)
Mutual labels:  trading-bot, trading, trading-algorithms
Chanlun
文件 笔和线段的一种划分.py,只需要把k线high,low数据输入,就能自动实现笔,线段,中枢,买卖点,走势类型的划分了。可以把sh.csv 作为输入文件。个人简历见.pdf。时间的力量。有人说择时很困难,有人说选股很容易,有人说统计套利需要的IT配套设施很重要。还有人说系统有不可测原理。众说纷纭。分布式的系统,当你的影响可以被忽略,你才能实现,Jiang主席所谓之,闷声发大财。
Stars: ✭ 206 (-16.26%)
Mutual labels:  trading-bot, trading, trading-algorithms
Trendyways
Simple javascript library containing methods for financial technical analysis
Stars: ✭ 121 (-50.81%)
Mutual labels:  trading, finance, stock-market
Quant
Codera Quant is a Java framework for algorithmic trading strategies development, execution and backtesting via Interactive Brokers TWS API or other brokers API
Stars: ✭ 104 (-57.72%)
Mutual labels:  trading-bot, trading, trading-algorithms
Aat
Asynchronous, event-driven algorithmic trading in Python and C++
Stars: ✭ 109 (-55.69%)
Mutual labels:  trading-bot, trading, stock-market
Jiji2
Forex algorithmic trading framework using OANDA REST API.
Stars: ✭ 211 (-14.23%)
Mutual labels:  trading, finance, trading-algorithms

PyPI version CircleCI Updates Python 3

alpaca-backtrader-api

alpaca-backtrader-api is a python library for the Alpaca trade API within backtrader framework. It allows rapid trading algo development easily, with support for the both REST and streaming interfaces. For details of each API behavior, please see the online API document.

Note this module supports only python version 3.5 and above, due to the underlying library alpaca-trade-api.

Install

$ pip3 install alpaca-backtrader-api

Example

These examples only work if you have a funded brokerage account or another means of accessing Polygon data.

you can find example strategies in the samples folder.

remember to add you credentials.

you can toggle between backtesting and paper trading by changing ALPACA_PAPER

a strategy looks like this:

In order to call Alpaca's trade API, you need to obtain API key pairs. Replace <key_id> and <secret_key> with what you get from the web console.

import alpaca_backtrader_api
import backtrader as bt
from datetime import datetime

ALPACA_API_KEY = <key_id>
ALPACA_SECRET_KEY = <secret_key>
ALPACA_PAPER = True


class SmaCross(bt.SignalStrategy):
  def __init__(self):
    sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
    crossover = bt.ind.CrossOver(sma1, sma2)
    self.signal_add(bt.SIGNAL_LONG, crossover)


cerebro = bt.Cerebro()
cerebro.addstrategy(SmaCross)

store = alpaca_backtrader_api.AlpacaStore(
    key_id=ALPACA_API_KEY,
    secret_key=ALPACA_SECRET_KEY,
    paper=ALPACA_PAPER
)

if not ALPACA_PAPER:
  broker = store.getbroker()  # or just alpaca_backtrader_api.AlpacaBroker()
  cerebro.setbroker(broker)

DataFactory = store.getdata  # or use alpaca_backtrader_api.AlpacaData
data0 = DataFactory(dataname='AAPL', historical=True, fromdate=datetime(
    2015, 1, 1), timeframe=bt.TimeFrame.Days)
cerebro.adddata(data0)

print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.run()
print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.plot()

API Document

The HTTP API document is located in https://docs.alpaca.markets/

Authentication

The Alpaca API requires API key ID and secret key, which you can obtain from the web console after you sign in. You can set them in the AlpacaStore constructor, using 'key_id' and 'secret_key'.

Paper/Live mode

The 'paper' parameter is default to False, which allows live trading. If you set it to True, then you are in the paper trading mode.

Running Multiple Strategies/Datas

There's a way to execute an algorithm with multiple datas or/and execute more than one algorithm.
The websocket connection is limited to 1 connection per account. Alpaca backtrader opens a websocket connection for each data you define.
For that exact purpose this project was created
The steps to execute this are:

  • Run the Alpaca Proxy Agent as described in the project's README
  • Define this env variable: DATA_PROXY_WS to be the address of the proxy agent. (e.g: DATA_PROXY_WS=ws://192.168.99.100:8765)
  • execute your algorithm. it will connect to the servers through the proxy agent allowing you to execute multiple datas/strategies

Support and Contribution

For technical issues particular to this module, please report the issue on this GitHub repository. Any API issues can be reported through Alpaca's customer support.

New features, as well as bug fixes, by sending pull request is always welcomed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].