GithubHelp home page GithubHelp logo

example-hftish's Introduction

Example HFT-ish Algorithm for Alpaca Trading API

The aim of this algorithm is to capture slight moves in the bid/ask spread as they happen. It is only intended to work for high-volume stocks where there are frequent moves of 1 cent exactly. It is one of the trading strategies based on order book imbalance. For more details about it, please refer to Darryl Shen, 2015 or other online articles.

This algorithm will make many trades on the same security each day, so any account running it will quickly encounter PDT rules. Please make sure your account balance is well above $25,000 before running this script in a live environment.

This script also presents a basic framework for streaming-based algorithms. You can learn how to write your algorithm based on the real-time price updates.

Setup

This algorithm runs with Python 3.6 or above. It uses Alpaca Python SDK so make sure install it beforehand, or if you have pipenv, you can install it by

$ pipenv install

in this directory.

API Key

In order to run this algorithm, you have to have Alpaca Trading API key. Please obtain it from the dashboard and set it in enviroment variables.

export APCA_API_KEY_ID=<your key id>
export APCA_API_SECRET_KEY=<your secret key>

Run

$ python ./tick_taker.py

The parameters are following.

  • --symbol: the stock to trade (defaults to "SNAP")
  • --quantity: the maximum number of shares to hold at once. Note that this does not account for any existing position; the algorithm only tracks what is bought as part of its execution. (Default 500, minimum 100.)
  • --key-id: your API key ID. (Can also be set via the APCA_API_KEY_ID environment variable.)
  • --secret-key: your API key secret. (Can also be set via the APCA_API_SECRET_KEY environment variable.)
  • --base-url: the URL to connect to. (Can also be set via the APCA_API_BASE_URL environment variable. Defaults to "https://paper-api.alpaca.markets" if using a paper account key, "https://api.alpaca.markets" otherwise.)

The algorithm can be stopped at any time by sending a keyboard interrupt CTRL+C to the console. (You may need to send two CTRL+C commands to kill the process depending where in the execution you catch it.)

Note

Please also note that this algorithm uses the Polygon streaming API with Alpaca API key, so you have to have a live trading account setup. For more details about the data requirements, please see Alpaca documentation.

example-hftish's People

Contributors

ttt733 avatar umitanuki avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.