From 78dca955e43322729f32a4d14bf00efc16bf3d5b Mon Sep 17 00:00:00 2001 From: Brian Searls <11205878+briansrls@users.noreply.github.com> Date: Sun, 28 Oct 2018 20:21:22 -0400 Subject: [PATCH] removed redundant file and removed requirements.txt --- Robinhood/Robinhood.py | 16 ++---- Robinhood/trade_history_downloader.py | 74 --------------------------- requirements.txt | 3 -- 3 files changed, 5 insertions(+), 88 deletions(-) delete mode 100644 Robinhood/trade_history_downloader.py delete mode 100644 requirements.txt diff --git a/Robinhood/Robinhood.py b/Robinhood/Robinhood.py index 81f8b5c..5e36f99 100644 --- a/Robinhood/Robinhood.py +++ b/Robinhood/Robinhood.py @@ -15,7 +15,6 @@ import requests import six import dateutil -import urllib #Application-specific imports from . import exceptions as RH_exception @@ -89,8 +88,7 @@ def login_prompt(self): # pragma: no cover def login(self, username, - password, - mfa_code=None): + password): """Save and test login info for Robinhood accounts Args: @@ -109,10 +107,7 @@ def login(self, 'scope': 'internal', 'username': username, } - try: - data = urllib.urlencode(fields) #py2 - except: - data = fields + data = fields res = self.session.post(endpoints.login(), data=data) res = res.json() @@ -120,12 +115,11 @@ def login(self, if 'mfa_required' in res: try: self.mfa_code = raw_input("MFA code: ").strip() - fields['mfa_code'] = self.mfa_code - data = urllib.urlencode(fields) except: self.mfa_code = input("MFA code: ").strip() - fields['mfa_code'] = self.mfa_code - data = fields + + fields['mfa_code'] = self.mfa_code + data = fields res = self.session.post(endpoints.login(), data=data) res = res.json() diff --git a/Robinhood/trade_history_downloader.py b/Robinhood/trade_history_downloader.py deleted file mode 100644 index 45f4e8f..0000000 --- a/Robinhood/trade_history_downloader.py +++ /dev/null @@ -1,74 +0,0 @@ -import json -import csv -import shelve - -from Robinhood import Robinhood - -def get_symbol_from_instrument_url(rb_client, url, db): - instrument = {} - if url in db: - instrument = db[url] - else: - db[url] = fetch_json_by_url(rb_client, url) - instrument = db[url] - return instrument['symbol'] - - -def fetch_json_by_url(rb_client, url): - return rb_client.session.get(url).json() - - -def order_item_info(order, rb_client, db): - #side: .side, price: .average_price, shares: .cumulative_quantity, instrument: .instrument, date : .last_transaction_at - symbol = get_symbol_from_instrument_url(rb_client, order['instrument'], db) - return { - 'side': order['side'], - 'price': order['average_price'], - 'shares': order['cumulative_quantity'], - 'symbol': symbol, - 'date': order['last_transaction_at'], - 'state': order['state'] - } - - -def get_all_history_orders(rb_client): - orders = [] - past_orders = rb_client.order_history() - orders.extend(past_orders['results']) - while past_orders['next']: - print("{} order fetched".format(len(orders))) - next_url = past_orders['next'] - past_orders = fetch_json_by_url(rb_client, next_url) - orders.extend(past_orders['results']) - print("{} order fetched".format(len(orders))) - return orders - -logged_in = False - - -rb = Robinhood() -# !!!!!! change the username and passs, be careful when paste the code to public -while not logged_in: - if username == "": - print("Robinhood username:") - try: input = raw_input - except NameError: pass - username = input() - if password == "": - password = getpass.getpass() - - logged_in = robinhood.login(username=username, password=password) - logged_in = rb.login(username="name", password="pass") - if logged_in == False: - password = "" - print ("Invalid username or password. Try again.\n") - -past_orders = get_all_history_orders(rb) -instruments_db = shelve.open('instruments.db') -orders = [order_item_info(order, rb, instruments_db) for order in past_orders] -keys = ['side', 'symbol', 'shares', 'price', 'date', 'state'] -with open('orders.csv', 'w') as output_file: - dict_writer = csv.DictWriter(output_file, keys) - dict_writer.writeheader() - dict_writer.writerows(orders) - diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index c60a014..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -pip install requests -pip install six -pip install python-dateutil