{"id":24087974,"url":"https://github.com/tinybirdco/stocks-realtime","last_synced_at":"2025-09-09T04:35:24.987Z","repository":{"id":113973197,"uuid":"549774024","full_name":"tinybirdco/stocks-realtime","owner":"tinybirdco","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-14T14:55:44.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-27T05:25:07.212Z","etag":null,"topics":[],"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/tinybirdco.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-11T18:02:56.000Z","updated_at":"2022-12-14T03:40:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"3f2492cf-b4e2-4ff8-97e2-f6d81cbeeb58","html_url":"https://github.com/tinybirdco/stocks-realtime","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tinybirdco/stocks-realtime","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinybirdco%2Fstocks-realtime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinybirdco%2Fstocks-realtime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinybirdco%2Fstocks-realtime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinybirdco%2Fstocks-realtime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinybirdco","download_url":"https://codeload.github.com/tinybirdco/stocks-realtime/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinybirdco%2Fstocks-realtime/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274244001,"owners_count":25248156,"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","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-01-10T03:56:43.380Z","updated_at":"2025-09-09T04:35:24.979Z","avatar_url":"https://github.com/tinybirdco.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Project\nData project to analyze realtime stock market data in a candlestick chart using [Alpaca](https://alpaca.markets/) + [Tinybird](https://www.tinybird.co/).\n\n## Working with the Tinybird CLI\n\nTo start working with data projects as if they were software projects, first install the Tinybird CLI in a virtual environment.\nCheck the [CLI documentation](https://docs.tinybird.co/cli.html) for other installation options and troubleshooting.\n\n```bash\npython3 -mvenv .e\n. .e/bin/activate\npip install tinybird-cli\ntb auth --interactive\n```\n\nChoose your region: __1__ for _us-east_, __2__ for _eu_\n\nGo to your workspace, copy a token with admin rights and paste it. A new `.tinyb` file will be created.\n\n\n## Alpaca Credentials\n\nGo to [Alpaca](https://alpaca.markets/) and sign up for a free account (or login if you already have an account). On your dashboard overview, generate a new API key and secret.\n\n![alpaca_api_key](https://user-images.githubusercontent.com/105812959/195167108-7ceb66f1-dcf1-4924-958f-e38f77236427.png)\n\nUpdate the `.alpaca` file with your credentials.\n\n\n## Project Description\n\n```bash\n├── datasources\n│   └── stocks_stream.datasource\n├── endpoints\n│   ├── api_candlestick_chart.pipe\n│   └── api_ui_filters.pipe\n```\n\nIn the `/datasources` folder, we have one data source to store the stock market data.\n\nIn the `/endpoints` folder, we have one pipe to transform quote data into a candlestick chart, and another pipe to feed a dropdown filter on the frontend.\n\nPush the data project to your workspace:\n\n```bash\ntb push --no-check\n```\n\n## Streaming realtime stock data\n\nGo to the `data-generator` folder and run the generator script to stream stock data:\n\n```bash\npython3 data-generator/stream_data.py\n```\n\nFeel free to play around with any of the flags to modify the data. See `python3 data-generator/stream_data.py --help` for all of the different flags.\n\nFor generating data for popular stock symbols, we used:\n\n```bash\npython3 data-generator/stream_data.py --symbols AMZN,TSLA,NVDA,AAPL,MSFT,META,GOOG\n```\n\nIf required, install the required websocket library with `pip install websocket-client`.\n\n_Note: data will only stream while the market is open._\n\n\n## Token Security\n\nYou now have your data project in Tinybird with data.\n\nThe endpoints need a [token](https://www.tinybird.co/guide/serverless-analytics-api) to be consumed. You should not expose your admin token, so let's create one with more limited scope:\n\n```bash\npip install jq\n\nTOKEN=$(cat .tinyb | jq '.token'| tr -d '\"')\nHOST=$(cat .tinyb | jq '.host'| tr -d '\"')\n\ncurl -H \"Authorization: Bearer $TOKEN\" \\\n-d \"name=endpoints_token\" \\\n-d \"scope=PIPES:READ:api_candlestick_chart\" \\\n-d \"scope=PIPES:READ:api_ui_filters\" \\\n$HOST/v0/tokens/\n```\n\nYou will see a response similar to this:\n\n```json\n{\n    \"token\": \"\u003cnew_token\u003e\",\n    \"scopes\": [\n        {\n            \"type\": \"PIPES:READ\",\n            \"resource\": \"api_candlestick_chart\",\n            \"filter\": \"\"\n        }\n    ],\n    \"name\": \"endpoints_token\"\n}\n```\n\n## Clean the Workspace\n\nIf you want to delete all pipes and data sources, be sure you have them in your local folder `tb pull` and run `tb workspace clear`\n\n```bash\n$ tb workspace clear\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinybirdco%2Fstocks-realtime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinybirdco%2Fstocks-realtime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinybirdco%2Fstocks-realtime/lists"}