Exemplo n.º 1
0
 def test_get_crypto_currency_pairs(self):
     pairs = r.get_crypto_currency_pairs(info=None)
     btc = [x for x in pairs if x['symbol'] == self.bitcoin_currency][0]
     assert ('asset_currency' in btc)
     assert ('display_only' in btc)
     assert ('id' in btc)
     assert ('max_order_size' in btc)
     assert ('min_order_size' in btc)
     assert ('min_order_price_increment' in btc)
     assert ('min_order_quantity_increment' in btc)
     assert ('name' in btc)
     assert ('quote_currency' in btc)
     assert ('symbol' in btc)
     assert ('tradability' in btc)
     fake = [x for x in pairs if x['symbol'] == self.fake]
     assert (len(fake) == 0)
Exemplo n.º 2
0
print(df_buy)
print(df_sell)

tkr_buy_list  = df_buy['ticker'].tolist()
tkr_sell_list = df_sell['ticker'].tolist()

print(f"{len(r.orders.get_all_open_orders())} open order") 

r.orders.cancel_all_open_orders()

if len(tkr_sell_list) > 0:
    for i in tkr_sell_list:
        print(i)
        print(r.orders.order_sell_market(i,4,timeInForce= 'gfd'))
else:
    print('Nothing to sell right now!')


if len(tkr_buy_list) > 0:
    for i in tkr_buy_list:
        test = r.orders.order_buy_market(i,4,timeInForce= 'gfd')
        print(i)
        print(test)
        print(type(test))
else:
    print('Nothing to buy right now!')

r.get_crypto_currency_pairs()

r.stocks.get_earnings('TSLA',info='report')
Exemplo n.º 3
0
def main():

    # these global variable's can be edited here
    global CREDENTIALSFILE, FILENAME, dir_suffix, cryptopairs

    # args parser

    arg_desc = f"rhood v{Version} - Text analysis of robinhood profile, portfolio and profits. Please review README.md for login instructions. There are 2 methods: creating '{CREDENTIALSFILE}' file (more secure), or providing credentials in the command line (less secure)."
    end_message = f"Example: first create '{CREDENTIALSFILE}' credentials file following the README.md instructions, then run # python rhood.py --all-info"
    parser = argparse.ArgumentParser(description=arg_desc,epilog=end_message)
    parser.add_argument("--username","-U",help="Robinhood username. Must be used with --password and --authkey, if 2 factor authentication is used.", action="store", default="")
    parser.add_argument("--password","-P",help="Robinhood password.", action="store", default="")
    parser.add_argument("--authkey","-K",help="2 factor authentication key. Only needed if 2Factor is enabled.", action="store", default="")
    parser.add_argument("--insecure","-I",help=f"Not recommended. Login insecurely without 2factor authentication. '{CREDENTIALSFILE}' only holds username line and password line in encoded base64 ascii format. Sidenote: default secure mode also needs third auth key line encoded as well.", action="store_true")
    parser.add_argument("--creds-file","-C",help=f"Where to load base64 encoded credentials from (README.md for more information). By default it is '{CREDENTIALSFILE}'.", action="store", default=CREDENTIALSFILE)
    parser.add_argument("--all-info","-i",help="Get all profile + order + open positions + profit info.",action="store_true")
    parser.add_argument("--profile-info","-r",help="Get only profile information.",action="store_true")
    parser.add_argument("--finance-info","-f",help="Get financial information: all orders + open positions + profit info.",action="store_true")
    parser.add_argument("--save","-s",help=f"Save all orders + open positions to file '{FILENAME}'. Only works with --all-info or --finance-info.",action="store_true")
    parser.add_argument("--load","-l",help=f"Load all orders + open positions from file '{FILENAME}', therefore we don't have to contact API; Saves time but gets older data. Only works  with --all-info or --finance-info.",action="store_true")
    parser.add_argument("--finance-file","-F",help=f"Change financial orders file to save to or load from. By default it is '{FILENAME}'.", action="store", default=FILENAME)
    parser.add_argument("--extra","-e",help="Shows extra order information (time consuming). only works with --all-info or --finance-info.",action="store_true")
    parser.add_argument("--csv","-c",help="Save all loaded orders to csv files in 'csv' directory (dir is created if missing). Only works  with --all-info or --finance-info.", action="store_true")
    parser.add_argument("--profile-csv","-p",help="Save all profile data to csv. Only works if --profile-info or --all-info used as well.", action="store_true")
    parser.add_argument("--csv-dir","-D",help=f"Change output directory for csv files generated by --csv and --profile-csv option, by default the directory is named '{dir_suffix}'.", action="store", default=dir_suffix)
    parser.add_argument("--sort-by-name","-S",help="Sorts open positions + profits by name instead of value. Only works if --finance-info or --all-info is used as well.", action="store_true")

    args = parser.parse_args()

    # parse save and load
    save_bool = args.save
    load_bool = args.load

    # extra information
    extra_info_bool = args.extra

    # save csv of orders
    csv_bool = args.csv
    csv_profile_bool = args.profile_csv

    # info bools
    all_info_bool = args.all_info
    profile_info_bool = args.profile_info
    finance_info_bool = args.finance_info
    if profile_info_bool and finance_info_bool:
        # if we are asking for profile + order info then just get all of it
        all_info_bool = True

    # sort type
    sort_alpha_bool = args.sort_by_name

    # credentials at cli, if not used the are "", we check for missing items inside LOGIN files
    cli_user = args.username
    cli_pass = args.password
    cli_key = args.authkey

    # error checking on saving and loading
    if load_bool and save_bool:
        errext(3, "Can't save and load. Try again with either save or load.")

    # Credentials file (if we don't need it, that is okay and handled in LOGIN functions)
    CREDENTIALSFILE = args.creds_file

    # Pickle file
    FILENAME = args.finance_file

    # csv directory
    dir_suffix = args.csv_dir

    # LOGIN securely or insecurely
    if not args.insecure:
        _login_output = LOGIN(un=cli_user,pw=cli_pass,ke=cli_key) # gives us r from secure login
    else:
        _login_output = LOGIN_INSECURE(un=cli_user,pw=cli_pass) # gives us r from insecure login

    # GET CRYPTOPAIRS (global var used in pairing crypto ids to coin name)
    cryptopairs = r.get_crypto_currency_pairs() # global var

    # kicking off main operation below:
    if all_info_bool: # this should be all info - get main profile & orders
        PRINT_ALL_PROFILE_AND_ORDERS(save_bool=save_bool, load_bool=load_bool, extra_info_bool=extra_info_bool,csv_bool=csv_bool,csv_profile_bool=csv_profile_bool,info_type="ALL", sort_alpha_bool=sort_alpha_bool)
    elif profile_info_bool: # this should be just profile info
        PRINT_ALL_PROFILE_AND_ORDERS(save_bool=save_bool, load_bool=load_bool, extra_info_bool=extra_info_bool,csv_bool=csv_bool,csv_profile_bool=csv_profile_bool,info_type="PROFILE", sort_alpha_bool=sort_alpha_bool)
    elif finance_info_bool: # this is just finance info
        PRINT_ALL_PROFILE_AND_ORDERS(save_bool=save_bool, load_bool=load_bool, extra_info_bool=extra_info_bool,csv_bool=csv_bool,csv_profile_bool=csv_profile_bool,info_type="FINANCE", sort_alpha_bool=sort_alpha_bool)