Exemplo n.º 1
0
 def __init__(
         self,
         report_day=datetime.datetime.utcnow(),
 ):
     self._report_day = report_day
     self.email_user = utils.retrieve_secret('EMAIL_USER')
     self.email_password = utils.retrieve_secret('EMAIL_PASSWORD')
Exemplo n.º 2
0
 def email_recipients(self) -> list:
     return utils.retrieve_secret('EMAIL_DAD')
Exemplo n.º 3
0
import datetime
import requests
from typing import NamedTuple

from finance.trading import access
from finance.utilities import utils

_ACCOUNT = utils.retrieve_secret('TD_PRIMARY_ACCOUNT')
_ACCESS_TOKEN: str = access.get_access_token()

_ACCOUNTS_URL = r'https://api.tdameritrade.com/v1/accounts'
_ORDER_URL = 'https://api.tdameritrade.com/v1/accounts/{account}/orders'

_RAW_DT_FMT = '%Y-%m-%dT%H:%M:%S+0000'
_DT_FMT = '%Y-%m-%d %H:%M:%S'


class Order(NamedTuple):
    id: str = None
    status: str = None
    symbol: str = None
    price: str = None
    quantity: int = None
    instruction: str = 'BUY'
    asset_type: str = 'EQUITY'
    order_type: str = 'LIMIT'
    account: str = _ACCOUNT
    entered_time: str = datetime.datetime.utcnow().strftime(_DT_FMT)
    closed_time: str = datetime.datetime.utcnow().strftime(_DT_FMT)

Exemplo n.º 4
0
 def api_secret(self) -> str:
     return utils.retrieve_secret(self.job_name)
Exemplo n.º 5
0
import requests
import urllib
from finance.utilities import utils

_AUTH_URL = r'https://api.tdameritrade.com/v1/oauth2/token'
_ACCOUNTS_URL = r'https://api.tdameritrade.com/v1/accounts'
_HEADERS = {"Content-Type": "application/x-www-form-urlencoded"}

_ACCESS_CODE = utils.retrieve_secret('API_TD_ACCESS_CODE')
_CLIENT_ID = utils.retrieve_secret('API_TD')
_REDIRECT_URI = utils.retrieve_secret('API_TD_REDIRECT_URI')
_REFRESH_TOKEN = utils.retrieve_secret('API_TD_REFRESH_TOKEN')


# Manually refresh API_TD_LOGIN_URL in env
def _get_refresh_token(access_code=_ACCESS_CODE,
                       auth_url=_AUTH_URL,
                       client_id=_CLIENT_ID,
                       redirect_uri=_REDIRECT_URI) -> dict:
    """
    Get TD Refresh Token to store in env vars

    1. Update API_TD_ACCESS_CODE in env vars
    2. Run this function
    3. Update API_TD_REFRESH_TOKEN in env vars
    """

    # Url encode access code
    code = urllib.parse.unquote(access_code)

    # Post request