Metadata-Version: 2.2
Name: tradebot
Version: 0.2.0
Summary: A Python wrapper around the TDAmeritrade API
Author-email: Adeiron Barolli <obarolli@onicodes.io>
License: MIT License
        
        Copyright (c) 2022 Adeiron Barolli
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/abarolli/tradebot
Project-URL: Issues, https://github.com/abarolli/tradebot/issues
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests

# Tradebot
## A Python wrapper around the TDAmeritrade API

The only thing that needs to be manually configured by the user is the config file.
As of right now, this needs to be a json file with the following format:

```
{
  "access_token": "oMLcWUb4GFRnSRCztRGy...",
  "refresh_token": "7GWdTz2AdBAz1IEtsErLM...",
  "scope": "PlaceTrades AccountAccess MoveMoney",
  "expires_in": 1800,
  "refresh_token_expires_in": 7776000,
  "token_type": "Bearer",
  "consumer_key": "5SMAF9JAZYKKPIPL5E6IZUQCAKZOV5D7",
  "account_number": "495909744"
}
```

You must make a [developer account](https://developer.tdameritrade.com/) with TDAmeritrade to get your consumer/api key.

Follow the official TDAmeritrade API documentation for instructions on [generating the refresh token](https://developer.tdameritrade.com/content/simple-auth-local-apps).
Following those instructions will provide you with the initial json you need; copy this into a json file in your source code directory. This is the central point of truth for your api configurations.

The *access_token* is essential for all requests and must be kept up-to-date. This expires every 30 minutes, but the user does not have to manually create a new one. Use the following snippet as an example of how to update the access token with the `update_access_token` utility function. This will automatically update the source json file.

```
from pathlib import Path
from tradebot.configs.utils import update_access_token

config_file = Path(__file__).parent / "configs.json"
configs = TradebotConfigs(config_file)
update_access_token(configs)
```

The *refresh_token* is what is used to get a new access token. The user must follow the [same process as before](https://developer.tdameritrade.com/content/simple-auth-local-apps) to get a new refresh token. Thankfully, this only expires every 90 days. Work is in progress to automate this with Chromium drivers.

The *account_number* refers to the account number of your TDAmeritrade brokerage account and is only useful if you wish to see account info (positions, balances, etc). It is not necessary to perform the other stock related functions of Tradebot.

Here are some code snippets to get started.

**Requesting fundamental data for a given ticker:**
```
from pathlib import Path
from tradebot.configs import TradebotConfigs
from tradebot.backend import Tradebot
from tradebot.requests import TradebotRequests

file = Path(__file__).parent / "configs.json"
configs = TradebotConfigs(file)
requests = TradebotRequests(configs)
bot = Tradebot(configs, requests)

msft_fundamentals = bot.fundamentals("MSFT")
```

**Requesting price history:**
```
from tradebot.backend.enums import CandlePeriodType, CandleFrequencyType

file = Path(__file__).parent / "configs.json"
configs = TradebotConfigs(file)
requests = TradebotRequests(configs)
bot = Tradebot(configs, requests)

aapl_price_history = bot.price_history(
    "AAPL",
    period_type=CandlePeriodType.DAY,
    period=2,
    frequency_type=CandleFrequencyType.MINUTE,
    frequency=1
)
```
