示例#1
0
 def test_accounts_no_accountIDs(self):
     from tdameritrade import TDClient
     with patch('tdameritrade.session.TDASession.request') as m:
         m.return_value.status_code = 200
         m.return_value.json.return_value = [MagicMock()]
         tdc = TDClient(
             client_id=123,
             refresh_token='reftoken',
         )
         tdc.accounts()
示例#2
0
    def test_movers(self):
        from tdameritrade import TDClient

        tdc = TDClient('test', [1, 2])

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = {'aapl': {'test'}}
示例#3
0
    def test_movers(self):
        from tdameritrade import TDClient

        tdc = TDClient(clientId=123, refreshToken='reftoken',
                       accountIds=[1, 2])

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = {'aapl': {'test'}}
示例#4
0
async def get_and_save_quotes(client: tdameritrade.TDClient, quotes,
                              start_time: float, time_sec: int) -> None:
    """
    Get the quotes and then save them to DB.
    """

    try:
        active_pulse.inc()
        quotes = client.quote(QUOTE_SYMBOLS)

        await write_quotes_to_db(quotes, start_time, time_sec)
    except Exception as error:
        logger.error("Unable to get quote data for symbols: {}".format(error))
        tda_quotes_error.inc()
示例#5
0
def main(args):
    # setup TDA API
    authReply = tdameritrade.auth.authentication("abhishekda1423", "http://localhost")
    ACCESS_TOKEN = authReply['access_token']
    REFRESH_TOKEN = authReply['refresh_token']
    logging.info("Access token = %s" % ACCESS_TOKEN)
    c = TDClient(ACCESS_TOKEN)
    today = datetime.datetime.now().strftime("%m-%d-%Y")
    isHoliday = today in closed
    logging.info("Today is %s, isHoliday = %s" % (today, isHoliday))
    if isHoliday:
        logging.error("Holiday exit")
        sys.exit(0)

    # get SPX History.  This appears to only be available the day after (12:01 CST)
    SPXImage = tpoSymbol(c.tpoHistory('SPX'))

    tickerImages = defaultdict()
    for ticker in tickers:
        tickerImages[ticker] = tpoSymbol(c.tpoHistory(ticker))

    # post it to reddit
    r = praw.Reddit("TPO")
    d = datetime.datetime.today()
    dFormat = d.strftime("%m-%d-%Y")
    title = "Daily SPX TPO's %s" % dFormat
    url = SPXImage
    subreddit = r.subreddit('thewallstreet').submit(title, url=url, send_replies=True)
    replyTemplate = 'New to Market profile? ' \
                    '[Check out this guide](http://www.ranchodinero.com/volume-tpo-essentials/) ' \
                    'and [this book](https://web.archive.org/web/20170829185705/https://www.cmegroup.com/education/interactive/marketprofile/handbook.pdf)\n\n \n\n' \
                    'Additional tickers (PM or reply in these threads if you want one added)\n\n'
    for ticker in tickers:
        replyTemplate += '[%s](%s)\n\n' % (ticker, tickerImages[ticker])

    subreddit.reply(replyTemplate)
示例#6
0
    def test_quote(self, mock_rtie):
        from tdameritrade import TDClient

        tdc = TDClient(clientId=123, refreshToken='reftoken',
                       accountIds=[1, 2])

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = {'aapl': {'test': 1, 'test2': 2}}
            tdc.quote('aapl')
            tdc.quoteDF('aapl')
示例#7
0
    def test_history(self, mock_rtie):
        from tdameritrade import TDClient

        tdc = TDClient(clientId=123, refreshToken='reftoken',
                       accountIds=[1, 2])

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = {'candles': [{'datetime': 1, 'test2': 2}]}
            tdc.history('aapl')
            tdc.historyDF('aapl')
示例#8
0
    def test_accounts(self):
        from tdameritrade import TDClient

        tdc = TDClient('test', [1, 2])

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = [MagicMock()]
            tdc.accounts()

        tdc = TDClient('test', [1, 2])

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = [MagicMock()]

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = [{'test': 1, 'test2': 2}]
            tdc.accountsDF()
示例#9
0
class TDAPI:
    def __init__(self):
        self.ACCOUNT_ID = self._get_account_id()
        self.REFRESH_TOKEN = self._get_refresh_token()
        self.API_KEY = self._get_api_key()
        self.ACCESS_TOKEN = refresh_token(self.REFRESH_TOKEN,self.API_KEY)['access_token']
        self.client = TDClient(access_token=self.ACCESS_TOKEN)

    def _get_account_id(self):
        return os.environ.get('TD_BROKER_ID')

    def _get_refresh_token(self):
        return os.environ.get('TD_REFRESH_TOKEN')

    def _get_api_key(self):
        return os.environ.get('TD_API_KEY')

    def get_movers(self, index, direction='up', change_type='percent'):
        return self.client.movers(index, direction, change_type)
示例#10
0
    def test_accounts(self, mock_rtie):
        from tdameritrade import TDClient

        tdc = TDClient(clientId=123, refreshToken='reftoken',
                       accountIds=[1, 2])

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = [MagicMock()]
            tdc.accounts()

        tdc = TDClient(clientId=123, refreshToken='reftoken',
                       accountIds=[1, 2])

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = [MagicMock()]

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = [{'test': 1, 'test2': 2}]
            tdc.accountsDF()
示例#11
0
    def test_history(self):
        from tdameritrade import TDClient

        tdc = TDClient('test', [1, 2])

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = {
                'candles': [{
                    'datetime': 1,
                    'test2': 2
                }]
            }
            tdc.history('aapl')
            tdc.historyDF('aapl')
示例#12
0
    def test_quote(self):
        from tdameritrade import TDClient

        tdc = TDClient('test', [1, 2])

        with patch('requests.get') as m:
            m.return_value.status_code = 200
            m.return_value.json.return_value = {
                'aapl': {
                    'test': 1,
                    'test2': 2
                }
            }
            tdc.quote('aapl')
            tdc.quoteDF('aapl')
示例#13
0
from tdameritrade import TDClient
import os

TOKEN = os.environ.get('CLIENT_TOKEN')

if TOKEN is None:
    raise ValueError('CLIENT_TOKEN environment variable has not been set. Please set it to use the TDClient')

c = TDClient(TOKEN)
示例#14
0
 def test_init(self):
     from tdameritrade import TDClient
     tdc = TDClient('test')
     tdc._headers()
示例#15
0
 def __init__(self):
     self.ACCOUNT_ID = self._get_account_id()
     self.REFRESH_TOKEN = self._get_refresh_token()
     self.API_KEY = self._get_api_key()
     self.ACCESS_TOKEN = refresh_token(self.REFRESH_TOKEN,self.API_KEY)['access_token']
     self.client = TDClient(access_token=self.ACCESS_TOKEN)
示例#16
0
    select.select_by_value('MARKET')

    #print(driver.page_source)


def timeout():
    print("Alarm!")


timer = Timer(1500.0, timeout)
timer.start()

response = au.refresh_token(REFRESH_TOKEN, 'CHARLIEQ')
print(response)

c = TDClient(response['access_token'])
c.accounts()

#access_Trade(html)

again = True

while again:

    #print("current Price")
    if timer.is_alive() == False:
        print("STOPPED")
        response = au.refresh_token(REFRESH_TOKEN, 'CHARLIEQ')
        c = TDClient(response['access_token'])
        c.accounts()
        timer = Timer(1500.0, timeout)
示例#17
0
def tdclient():
    from tdameritrade import TDClient
    tdc = TDClient('test', [1, 2])
    return tdc
示例#18
0
import tdameritrade

from matplotlib import pyplot as plt, rcParams
from tdameritrade import auth, TDClient
from experimental.tdam.plotter import detailed_plotter, price_plotter
from experimental.tdam.scatter_plot import scatter_plot

# TODO Add multi threading. one thread to gather the data for a stock and store it in a DataFrame
# TODO a second thread to plot that data as it is being streamed
# TODO a third thread potentially to plot the full data set.

# REDIRECT_URI = "http://localhost:8080"
CLIENT_ID = os.getenv("TDAMERITRADE_CLIENT_ID")
REFRESH_TOKEN = os.getenv("TDAMERITRADE_REFRESH_TOKEN")

tdclient = TDClient(client_id=CLIENT_ID, refresh_token=REFRESH_TOKEN)


def get_arg_parser():
    """
    Gets arguments for stock scraping.
    """

    arg_parser = ArgumentParser(
        description=
        """Detailed analysis of stocks and options using the tdameritrade api."""
    )

    arg_parser.add_argument(
        "symbol",
        type=str.upper,
示例#19
0
 def test_init(self):
     from tdameritrade import TDClient
     tdc = TDClient(clientId=123, refreshToken='reftoken',
                    accountIds=[1, 2])
     self.assertEqual(tdc._refreshToken['token'], 'reftoken')
示例#20
0
def access_client(token):
    return TDClient(token["access_token"]) if "access_token" in token else None
示例#21
0
def tdclient():
    from tdameritrade import TDClient

    tdc = TDClient(client_id=123, refresh_token="reftoken", account_ids=[1, 2])
    return tdc