{"id":21042718,"url":"https://github.com/yugabytedb-samples/market-orders-app-python","last_synced_at":"2025-03-13T21:43:06.823Z","repository":{"id":59674529,"uuid":"524233206","full_name":"YugabyteDB-Samples/market-orders-app-python","owner":"YugabyteDB-Samples","description":"This application subscribes to the PubNub Market Orders Stream via Python client and stores the market trades in YugabyteDB.","archived":false,"fork":false,"pushed_at":"2022-09-19T09:58:12.000Z","size":690,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-20T17:18:16.860Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YugabyteDB-Samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-12T21:51:22.000Z","updated_at":"2022-10-27T15:42:46.000Z","dependencies_parsed_at":"2022-09-19T20:00:31.234Z","dependency_job_id":null,"html_url":"https://github.com/YugabyteDB-Samples/market-orders-app-python","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/YugabyteDB-Samples%2Fmarket-orders-app-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fmarket-orders-app-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fmarket-orders-app-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fmarket-orders-app-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YugabyteDB-Samples","download_url":"https://codeload.github.com/YugabyteDB-Samples/market-orders-app-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243489780,"owners_count":20298997,"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-11-19T14:08:47.224Z","updated_at":"2025-03-13T21:43:06.800Z","avatar_url":"https://github.com/YugabyteDB-Samples.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Market Orders Streaming to YugabyteDB with Python\n\nThis application subscribes to the [PubNub Market Orders Stream](https://www.pubnub.com/developers/realtime-data-streams/financial-securities-market-orders/) via Python client and stores the market trades in YugabyteDB.\n\nCheck [this blog post](https://dev.to/yugabyte/building-an-application-with-yugabytedb-and-flask-1eal) for a quick app overview.\n\n## Run using YugabyteDB Managed\n\n1. [Sign up for YugabyteDB Managed](https://docs.yugabyte.com/preview/yugabyte-cloud/cloud-quickstart/) and create a free cluster.  Additionally, follow this [guide](https://docs.yugabyte.com/preview/yugabyte-cloud/cloud-quickstart/cloud-build-apps/cloud-add-ip/#download-your-cluster-certificate) to download your cluster CA certificate and set up your cluster IP allow list.\n\n2. Run the following to create [virtual environment](https://docs.python.org/3/glossary.html#term-virtual-environment) for app and install application dependencies (first time only):\n\n```bash\n$ python3 -m venv market_order_app_venv  # create the virtual environment\n$ source market_order_app_venv/bin/activate  # activate the virtual environment\n$ cd market-orders-app-python/app/\n$ pip install -r ../requirements.txt\n```\n\n3. Configure your environment variables in the .env file (create a .env file if it doesn't exist):\n\n```bash\nDB_HOST=127.0.0.1\nPORT=5433\nDB_NAME=yugabyte\nUSERNAME=username\nPASSWORD=password\n```\n\n4. Run the following to initialize the database with schema:\n\n```bash\n$ python db.py\n```\n\n`db.py` will create tables and relations using [`schema/default_schema.sql`](schema/default_schema.sql)\n\n5. Seed the user data in the `User` table. Run the following to insert the default user data for User table:\n\n```bash\n$ python seed_user_data.py\n```\n\n`seed_user_data.py` will create user data using the [`faker`](https://github.com/joke2k/faker) module and inserts it into the `User` table.\n\n6. Run the application:\n\n```bash\n$ python flask_app.py\n```\n\nYou can see the app running on [http://127.0.0.1:5001](http://127.0.0.1:5001)\n\n7. Test the application (You can use [Postman](https://www.postman.com/downloads/) or cURL to send the requests)\n\n    - Subscribe to a channel - `curl --location --request GET 'http://127.0.0.1:5001/subscription/add?channel=pubnub-market-orders'`\n    - Unsubscribe from a channel - `curl --location --request GET 'http://127.0.0.1:5001/subscription/remove?channel=pubnub-market-orders'`\n    - Get subscribed channels - `curl --location --request GET 'http://127.0.0.1:5001/subscription/list'`\n    - Ingest the market order stream to YugabyteDB - `curl --location --request GET 'http://127.0.0.1:5001/ingeststreamdata'`\n    - Get Trade stats - `curl --location --request GET 'http://127.0.0.1:5001/tradestats'`\n\n    Here is the screenshot of how to call the API request in Postman.\n    - **Subscribe to a channel:**\n    ![Subscribe to the channel](/Docs/images/add_subscription.png)\n    - **Get Trade stats:**\n    ![Get Trade stats](/Docs/images/trade_stats.png)\n\n\n## Run using YugabyteDB locally\n\n1. [Install YugabyteDB locally](https://docs.yugabyte.com/quick-start/install/).\n\n2. Follow the same instructions as above (from step 2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Fmarket-orders-app-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyugabytedb-samples%2Fmarket-orders-app-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Fmarket-orders-app-python/lists"}