Exemplo n.º 1
0
 def __init__(self, username: str, password: str, public: bool = True):
     self.session = tasty_session.create_new_session(
         username, password
     )
     self.watchlists = asyncio.run(
         WatchlistGroup.get_watchlists(self.session, public=public)  # NOQA: E501
     )
Exemplo n.º 2
0
def main():
    tasty_client = tasty_session.create_new_session('your_username',
                                                    'your_password_here')

    streamer = DataStreamer(tasty_client)
    LOGGER.info('Streamer token: %s' % streamer.get_streamer_token())
    loop = asyncio.get_event_loop()

    try:
        loop.run_until_complete(main_loop(tasty_client, streamer))
    finally:
        # find all futures/tasks still running and wait for them to finish
        pending_tasks = [
            task for task in asyncio.Task.all_tasks() if not task.done()
        ]
        loop.run_until_complete(asyncio.gather(*pending_tasks))
        loop.close()
Exemplo n.º 3
0
def main():
    from tastyworks.__auth import USERNAME, PASSWORD
    tasty_client = tasty_session.create_new_session(USERNAME, PASSWORD)

    account_streamer = AccountStreamer(tasty_client)

    loop = asyncio.get_event_loop()

    try:
        loop.run_until_complete(main_loop(tasty_client, account_streamer))
    except Exception:
        LOGGER.exception('Exception in main loop')
    finally:
        pending_tasks = [
            task for task in asyncio.Task.all_tasks() if not task.done()
        ]
        loop.run_until_complete(asyncio.gather(*pending_tasks))
        loop.close()
Exemplo n.º 4
0
def main():
    from tastyworks.__auth import USERNAME, PASSWORD
    tasty_client = tasty_session.create_new_session(USERNAME, PASSWORD)

    streamer = DataStreamer(tasty_client)
    LOGGER.info('Streamer token: %s' % streamer.get_streamer_token())
    loop = asyncio.get_event_loop()

    try:
        loop.run_until_complete(main_loop(tasty_client, streamer))
    except Exception:
        LOGGER.exception('Exception in main loop')
    finally:
        # find all futures/tasks still running and wait for them to finish
        pending_tasks = [
            task for task in asyncio.Task.all_tasks() if not task.done()
        ]
        loop.run_until_complete(asyncio.gather(*pending_tasks))
        loop.close()
        return date(this_year, month, day)
    else:
        next_year = this_year + 1
        return date(next_year, month, day)

def get_profit_percent(position: Position):
    entry_fee = Decimal('1.00') * Decimal(position.quantity)
    entry = position.average_open_price * position.multiplier
    if entry_fee > 10:
        entry = entry + Decimal('10')
    else:
        entry = entry + entry_fee
    currentpl = (position.mark_price - position.average_open_price) * position.multiplier
    return Decimal((currentpl / entry) * 100)

tasty_client = tasty_session.create_new_session(Settings.tasty_user, Settings.tasty_password)
streamer = DataStreamer(tasty_client)
LOGGER.info('TW Streamer token: %s' % streamer.get_streamer_token())
tw_accounts = asyncio.new_event_loop().run_until_complete(TradingAccount.get_remote_accounts(tasty_client))
tasty_acct = None
for account in tw_accounts:
    if account.account_number == Settings.tasty_account_number and account.is_margin == False:
        tasty_acct = account
        LOGGER.info('TW Account found: %s', tasty_acct)
if not tasty_acct:
    raise Exception('Could not find a TastyWorks cash account with account number {} in the list of accounts: {}'.format(Settings.tasty_account_number, tw_accounts))

loop = asyncio.get_event_loop()

try:
    task1 = loop.create_task(client.start(Settings.Discord_Token, bot=False))
Exemplo n.º 6
0
 def __init__(self, tw_user, tw_password):
     self.account = None
     if tw_user != '' and tw_password != '':
         self.session = tasty_session.create_new_session(
             tw_user, tw_password)