{"id":17300478,"url":"https://github.com/atomantic/bitcoin_orderbook_indicator","last_synced_at":"2025-04-14T12:32:12.300Z","repository":{"id":41467872,"uuid":"188886103","full_name":"atomantic/bitcoin_orderbook_indicator","owner":"atomantic","description":"📉📈Bitcoin orderbook data collection and analysis. Just some fun data science stuff","archived":false,"fork":false,"pushed_at":"2021-03-03T05:08:26.000Z","size":10290,"stargazers_count":16,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T01:49:51.320Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/atomantic.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}},"created_at":"2019-05-27T17:44:18.000Z","updated_at":"2024-12-30T16:13:17.000Z","dependencies_parsed_at":"2022-09-02T13:21:21.208Z","dependency_job_id":null,"html_url":"https://github.com/atomantic/bitcoin_orderbook_indicator","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/atomantic%2Fbitcoin_orderbook_indicator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomantic%2Fbitcoin_orderbook_indicator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomantic%2Fbitcoin_orderbook_indicator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomantic%2Fbitcoin_orderbook_indicator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atomantic","download_url":"https://codeload.github.com/atomantic/bitcoin_orderbook_indicator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248881720,"owners_count":21176904,"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":[],"created_at":"2024-10-15T11:28:48.418Z","updated_at":"2025-04-14T12:32:12.254Z","avatar_url":"https://github.com/atomantic.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BTC Order Book Indicator\n\n\u003e DISCLAIMER: nothing in this project is financial advice. Any ideas of trading, investment, or other tomfoolery is at your own risk, discretion, and responsibility. The creator of this project has no position in Bitcoin. This is just for scientific interest.\n\nPolls the Coinbase Pro order book for BTCUSD and logs the following:\n- `datetime`\n- the current `price`\n- `m1_buy`: the price at which the order book would slip downward if someone (or many people) market sold down $1M worth\n- `m1_sell`: the price at which the order book would slip upward if someone market purchased $1M worth\n- same for $5M (`m5_buy`, `m5_sell`), $10M, $20M, $30M, $40M, $50M\n\nThis data set can then be used to construct a trading indicator, showing how the order book price volumes relate to the changing prices.\n\n## The Indicator\nThe primary theoretical indicator is called \"pull\" and shows the weight that the orderbook plays on pulling the price into a new direction. The pull is calculated for each threshold ($1M, $5M, $10M, $20M, $50M) using this formula: \n`sell_limit_price - market_price + buy_limit_price`\n\nTo make more sense of this, you can think of it as taking the dollar difference between the actual `price` and the slippage up (`sell_diff`), and taking the dollar slippage between the actual `price` and the slippage down (`buy_diff`), then measuring the pull as `price + sell_diff - buy_diff`.\n\n### Example\nIn the case of the `$1,000,000` price threshold: \n- let's say the `price` is `$8000`\n-`$1M` in buying would slip upward to `$8250` - diff is `$250`\n-`$1M` in selling would slip downward to `$7500` - diff is `$500`\n\nThere is more ceiling pressure than floor support (twice as much), so the `pull` is:\n```\n8250 - 8000 + 7500 = 7750\n```\n\nThis indicates that downward movement has less resistence than upward movement.\n\n## What?\nHere you can see when Bitcoin was in the `$6500` zone on May 10th, 2019 that the order books were thin on the sell side compared to the buy side. $7.5M in market selling action would reduce the price to `~$6020`, but $7M in market purchases would raise the price to `~$11,500`:\n![buy](img/buy.png)\n![sell](img/sell.png)\nOver the next week, Bitcoin shot up to nearly `$9K`.\n\n## How?\n\n```mermaid\nsequenceDiagram\n    participant Engine\n    participant Coinbase API\n    participant UI\n    Engine-\u003e\u003eEngine: startup\n    Engine-\u003e\u003eCoinbase API: fetch order book\n    Engine-\u003e\u003eUI: websocket send new data\n    UI-\u003e\u003eUI: render graphs\n    loop Healthcheck\n        Engine-\u003e\u003eCoinbase API: poll order book every 1 minute\n        Engine-\u003e\u003eUI: socket send new data\n        UI-\u003e\u003eUI: update graphs\n    end\n```\n\nThe logger runs every 1 minute and logs to a rolling log file in the `data` directory.\nThe payload for the BTCUSD orderbook is `2.8MB`, so we have to limit the data collection every minute :)\nWe log the following columns, tab delimited\n```\ndatetime price size bid ask volume total_buy total_sell_volume max_up_slippage max_down_slippage m1_buy m5_buy m10_buy m20_buy m30_buy m40_buy m50_buy m1_sell m5_sell m10_sell m20_sell m30_sell m40_sell m50_sell\n```\nWe can then take this data in python (there's a Jupyter Notebook in the `notebooks` directory), process the data, and visualize it (just for experimentation).\n\nAdditionally, the app runs a UI service that streams the data via websockets to a D3 graph\n![dashboard](img/dashboard.png)\n\n\n## Notes on Project Data\n\nThis is very experimental. As such, I realized some data I wanted to collect after the engine was running for a few days. Rather than deleting the old data, I backfilled generic approximations for the new data fields:\n\nData Collection Update #1 (`2019-05-31-081655`):\n```\nreplacing: ([^Z]+Z(\\s[\\d.]+){5})\nwith: $1\t54635567\t184140\t250000\t0.01\n```\nThese fields are:\n`total_buy` `total_sell_volume` `max_up_slippage` `max_down_slippage`\n\nData Collection Update #2 (2019-06-15):\n```\nreplacing: ([^Z]+Z(\\s[\\d.]+){13})\nwith: $1\t6612\t5850\n```\nThese fields are:\n`m30_buy` `m40_buy`\n\u0026 \n```\nreplacing: ([^Z]+Z(\\s[\\d.]+){20})\nwith: $1\t10000   11494\n```\nThese fields are:\n`m30_sell` `m40_sell`\n\n## Getting Started\n\nDevelopment mode\n* starts up the runner to collect data every minute\n* starts the UI\n* watches client code for changes\n```\nnpm run setup\nnpm run dev\n```\n\nProduction mode\nusing PM2 to keep the service alive:\n```\nnpm i -g pm2\npm2 start npm --name \"btc_orders\" -- start; pm2 logs\n```\n\n## Visualizing Data\n\nWhat good is an indicator without some data visualization?\n\nFor now, I'm playing with the data in Python because that's where I have all my machine learning tooling.\nLaunch Jupyter Notebooks to ingest the data in python:\n\nlocally:\n```\ndocker run -it -v $(pwd):/home/jovyan --rm -p 8888:8888 jupyter/scipy-notebook\n```\nor [launch on the web using MyBinder](https://mybinder.org/v2/gh/atomantic/bitcoin_orderbook_indicator/master)\n\n![sample data](img/sample.png)\n*here we see running the engine for a few days during a price pump*\n\nAdditionally, the app now launches a UI service that charts the data using D3, and live updates as the runner collects more data.\n\n\n## What Else?\n\nYou might be interested in some of my Pine Script indicators: https://github.com/atomantic/pine_scripts\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomantic%2Fbitcoin_orderbook_indicator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatomantic%2Fbitcoin_orderbook_indicator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomantic%2Fbitcoin_orderbook_indicator/lists"}