{"id":15043580,"url":"https://github.com/alpacahq/example-hftish","last_synced_at":"2025-04-12T19:48:40.474Z","repository":{"id":45770870,"uuid":"167564099","full_name":"alpacahq/example-hftish","owner":"alpacahq","description":"Example Order Book Imbalance Algorithm","archived":false,"fork":false,"pushed_at":"2023-07-25T16:50:41.000Z","size":62,"stargazers_count":789,"open_issues_count":10,"forks_count":244,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-04-12T19:48:32.439Z","etag":null,"topics":["alpaca","async","asyncio","finance","hft","hft-trading","nats-streaming","numpy","orderbook","python","python3","real-time","trading","trading-algorithms"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alpacahq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-01-25T14:56:38.000Z","updated_at":"2025-04-10T15:20:22.000Z","dependencies_parsed_at":"2023-10-20T16:52:16.629Z","dependency_job_id":null,"html_url":"https://github.com/alpacahq/example-hftish","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpacahq%2Fexample-hftish","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpacahq%2Fexample-hftish/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpacahq%2Fexample-hftish/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpacahq%2Fexample-hftish/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alpacahq","download_url":"https://codeload.github.com/alpacahq/example-hftish/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625500,"owners_count":21135513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alpaca","async","asyncio","finance","hft","hft-trading","nats-streaming","numpy","orderbook","python","python3","real-time","trading","trading-algorithms"],"created_at":"2024-09-24T20:49:17.986Z","updated_at":"2025-04-12T19:48:40.438Z","avatar_url":"https://github.com/alpacahq.png","language":"Python","readme":"# Example HFT-ish Algorithm for Alpaca Trading API\n\nThe aim of this algorithm is to capture slight moves in the bid/ask spread\nas they happen. It is only intended to work for high-volume stocks where there\nare frequent moves of 1 cent exactly.  It is one of the trading strategies\nbased on order book imbalance. For more details about it, please refer to\n[Darryl Shen, 2015](http://eprints.maths.ox.ac.uk/1895/1/Darryl%20Shen%20%28for%20archive%29.pdf)\nor other online articles.\n\nThis algorithm will make many trades on the same security each day, so any\naccount running it will quickly encounter PDT rules. Please make sure your\naccount balance is well above $25,000 before running this script in a live\nenvironment.\n\nThis script also presents a basic framework for streaming-based algorithms.\nYou can learn how to write your algorithm based on the real-time price updates.\n\n## Setup\n\nThis algorithm runs with Python 3.6 or above. It uses\n[Alpaca Python SDK](https://pypi.org/project/alpaca-trade-api/) so make\nsure install it beforehand, or if you have [pipenv](https://pipenv.readthedocs.io),\nyou can install it by\n\n```sh\n$ pipenv install\n```\n\nin this directory.\n\n## API Key\n\nIn order to run this algorithm, you have to have Alpaca Trading API key.\nPlease obtain it from the dashboard and set it in enviroment variables.\n\n```sh\nexport APCA_API_KEY_ID=\u003cyour key id\u003e\nexport APCA_API_SECRET_KEY=\u003cyour secret key\u003e\n```\n\n## Run\n\n```\n$ python ./tick_taker.py\n```\n\nThe parameters are following.\n\n- `--symbol`: the stock to trade (defaults to \"SNAP\")\n- `--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.)\n- `--key-id`: your API key ID. (Can also be set via the APCA_API_KEY_ID environment variable.)\n- `--secret-key`: your API key secret. (Can also be set via the APCA_API_SECRET_KEY environment variable.)\n- `--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.)\n\nThe 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.)\n\n## Note\n\nPlease also note that this algorithm uses the Polygon streaming API with Alpaca API key,\nso you have to have a live trading account setup. For more details about the data\nrequirements, please see\n[Alpaca documentation](https://docs.alpaca.markets/web-api/market-data/).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falpacahq%2Fexample-hftish","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falpacahq%2Fexample-hftish","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falpacahq%2Fexample-hftish/lists"}