{"id":16599835,"url":"https://github.com/itsjafer/schwab-api","last_synced_at":"2025-04-05T17:03:41.776Z","repository":{"id":46513128,"uuid":"353050130","full_name":"itsjafer/schwab-api","owner":"itsjafer","description":"A python library for placing trades on Charles Schwab","archived":false,"fork":false,"pushed_at":"2024-04-05T00:25:00.000Z","size":545,"stargazers_count":146,"open_issues_count":5,"forks_count":47,"subscribers_count":14,"default_branch":"main","last_synced_at":"2024-04-14T11:29:33.025Z","etag":null,"topics":["charles-schwab","charles-schwab-api","python","schwab","schwab-api","schwab-python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itsjafer.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-30T15:28:42.000Z","updated_at":"2024-06-27T19:33:06.739Z","dependencies_parsed_at":"2023-12-12T23:24:46.445Z","dependency_job_id":"a5d69218-68b8-4179-bf2e-caf1cbc2eccc","html_url":"https://github.com/itsjafer/schwab-api","commit_stats":{"total_commits":52,"total_committers":2,"mean_commits":26.0,"dds":"0.019230769230769273","last_synced_commit":"9b75c06c94b1e7d33462be29c8647a18098d5ecd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsjafer%2Fschwab-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsjafer%2Fschwab-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsjafer%2Fschwab-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsjafer%2Fschwab-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itsjafer","download_url":"https://codeload.github.com/itsjafer/schwab-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247369953,"owners_count":20927928,"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":["charles-schwab","charles-schwab-api","python","schwab","schwab-api","schwab-python"],"created_at":"2024-10-12T00:12:46.016Z","updated_at":"2025-04-05T17:03:41.739Z","avatar_url":"https://github.com/itsjafer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Schwab API\n\n**This is not an official API wrapper. Functionality may change with any updates made by Schwab. As of June 2024, this API continues to work as expected.**\n\nThis package enables buying and selling securities programmatically on Charles Schwab. Currently, we use a headless browser to automate logging in in order to get authorization cookies. All other functionality is done through web requests made to Schwab's own API.\n\n## Features\n\n* Buying and Selling tickers\n* Trading options\n* Get quotes for multiple tickers\n* Get order information\n* Get transaction history\n* Get tax lot info\n* Account and Position Information\n* Limit / Stop orders are possible using trade_v2 parameters\n* Multiple individual account support\n* MFA and TOTP authentication\n* Session caching\n* Async compatibility\n\n## Live Demo\n\nI am currently using this package to place trades on Schwab using my website [here](https://itsjafer.com/#/reversesplit).\n\n![Screenshot](screenshot.png)\n\n## Getting Started\n\n### Installing\n\nInstall using pypi and then download and install the playwright binaries:\n\n```\npip install schwab-api\npython -m playwright install\n```\n\n### Set up your account to use TOTP\n\nIn order to login to Schwab without having to go through SMS verification everytime, you'll need to create an authentication token (TOTP) and attach that to your Schwab account.\n\n\n1. Download a TOTP app like Google Authenticator.\n2. [Go to my website and generate a TOTP key there](https://itsjafer.com/#/schwab) by clicking 'Generate TOTP' and following the instructions. You should get a Symantec ID and a TOTP key/QR code.\n\nAlternatively, you can do this programmatically:\n\n```\nfrom schwab_api import generate_totp\n\nsymantec_id, totp_secret = generate_totp()\n\nprint(\"Your symantec ID is: \" + symantec_id)\nprint(\"Your TOTP secret is: \" + totp_secret)\n```\n\n3. Open Google Authenticator and click the `+` button to add a new account\n4. Either enter the TOTP key manually and scan the QR code from step 2.\n5. Log in to the Schwab [security center](https://client.schwab.com/app/access/securitysettings/#/security/verification)\n6. Under Two-Step Verification, select Always at Login, and then select \"Security Token\" as your method.\n7. Enter the Symantec ID from step 2 into the Credential ID field.\n8. Enter the 6-digit code from Google Authenticator into the Security Code field.\n9. Done! Now keep your TOTP secret from step 2 handy as your `SCHWAB_TOTP_SECRET` in your `.env` file under the example directory.\n\n### Quickstart\n\nYou can run this code in a [Colab Notebook here](https://github.com/itsjafer/schwab-api/blob/main/Schwab_API_Example.ipynb).\n\nHere's some code that logs in, gets all account holdings, and makes a stock purchase:\n```\nfrom schwab_api import Schwab\nimport pprint\n\n# Initialize our schwab instance\napi = Schwab()\n\n# Login using playwright\nprint(\"Logging into Schwab\")\nlogged_in = api.login(\n    username=username,\n    password=password,\n    totp_secret=totp_secret # Get this by generating TOTP at https://itsjafer.com/#/schwab\n)\n\n# Get information about a few tickers\nquotes = api.quote_v2([\"PFE\", \"AAPL\"])\npprint.pprint(quotes)\n\n# Get information about all accounts holdings\nprint(\"Getting account holdings information\")\naccount_info = api.get_account_info()\npprint.pprint(account_info)\n\nprint(\"The following account numbers were found: \" + str(account_info.keys()))\n\nprint(\"Placing a dry run trade for AAPL stock\")\n# Place a dry run trade for account 99999999\nmessages, success = api.trade_v2(\n    ticker=\"AAPL\", \n    side=\"Buy\", #or Sell\n    qty=1, \n    account_id=99999999, # Replace with your account number\n    dry_run=True # If dry_run=True, we won't place the order, we'll just verify it.\n)\n\nprint(\"The order verification was \" + \"successful\" if success else \"unsuccessful\")\nprint(\"The order verification produced the following messages: \")\npprint.pprint(messages)\n```\n\n## TODO\n\n* Currently, we use a headless browser to login to Schwab; in the future, we want to do this purely with requests.\n* Documentation of functionality\n\n## Development Guide\n\nWant to extend functionality? Here's how to get started:\n\n1. After forking, install dependencies:\n```\npip install .\nplaywright install \u0026\u0026 playwright install-deps\n```\n\n2. Run the example script:\n```\npip install . \u0026\u0026 python example/example.py\n```\n\n3. Iterate on existing code: \n* Authentication largely exists in `schwab_api/authentication.py` and is done using Playwright.\n* Trading happens in `schwab_api/schwab.py` in two functions: `trade` and `trade_v2` which use the legacy and new API respectively. Neither of these APIs are documented and were largely just reverse engineering through sniffing network requests in the UI.\n\n### Deployment\n\nBumping the version number in `setup.py` will automatically trigger a deployment that must be approved by itsjafer@.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsjafer%2Fschwab-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsjafer%2Fschwab-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsjafer%2Fschwab-api/lists"}