Esempio n. 1
0
def get_cash_info(qt: Questrade, acct: int) -> str:
    bal_response = qt._send_message('get',
                                    'accounts/' + str(acct) + '/balances')
    temp = qt._send_message('get', 'accounts/' + str(acct) + '/positions')
    print(temp)
    try:
        cash = round(bal_response['perCurrencyBalances'][0]['cash'], 2)
    except Exception:
        raise Exception
    result = '{F2}Cash{F1}: $'
    result += '{:.2f}'.format(cash)
    result += '{/F}'
    return result
Esempio n. 2
0
def get_cash_info(qt: Questrade, acct: int) -> str:
    bal_response = qt._send_message('get', 'accounts/' + str(acct) + '/balances')
    out_csv_with_timestamp(CASH_OUTPUT, bal_response['perCurrencyBalances'].copy());
    # temp = qt._send_message('get', 'accounts/' + str(acct) + '/positions')
    # print(temp);
    try:
        cash = round(bal_response['perCurrencyBalances'][0]['cash'], 2);
    except Exception:
        raise Exception;
    return F"{{F2}}Cash{{F1}}: ${cash:.2f}{{/F}}";
Esempio n. 3
0
#! /usr/bin/python

from qtrade import Questrade

# old script
# access_info = os.getenv('HOME') + '/.config/questrade/access_token.yml';
# qt = Questrade(token_yaml=access_info);
# Make sure our token is up to date and wont expire.
# qt.refresh_access_token();
# qt.save_token_to_yaml(yaml_path=access_info);
# temp.
qt = Questrade('UxOWeIWs_zBPd7KI23YB5dhdgybVXgcZ0')
# Only have one account so we grab first entry.
acct = qt.get_account_id()[0]
# My account balance code.
bal_response = qt._send_message('get', 'accounts/' + str(acct) + '/balances')
try:
    cash = round(bal_response['perCurrencyBalances'][0]['cash'], 2)
except Exception:
    print(bal_response)
    raise Exception
# Right now we are only investing in one index fund
# so the positions work as a balance.
pos = qt.get_account_positions(account_id=acct)[0]
symbol = pos['symbol']
start_investment = round(pos['totalCost'], 2)
current_val = round(pos['currentMarketValue'], 2)
day_pnl = round(pos['dayPnl'], 2)
overall_pnl = round(pos['openPnl'], 2)
start_val = round(current_val - day_pnl, 2)
day_pnl_perc = round(day_pnl / start_val * 100, 2)