Quick and Dirty QIF export of Robinhood Buy/Sells
#!/usr/bin/python3.7 # Export all Buy/Sell to QIF format import robin_stocks as r # Creds username = '' password = '' # Account name in program account_name = 'Robinhood' login = r.login(username,password) all_orders = r.orders.get_all_stock_orders() all_stock_symbols = [] all_instruments = [] all_orders.reverse() total_profit = float() total_stock_value = 0 for order in all_orders: instrument = order['instrument'] if instrument not in all_instruments: all_instruments.append(instrument) print('===================== Beginning of QIF File ======================') print('!Account') print('N' + account_name) print('TInvst') print('^') for instrument in all_instruments: total = 0 shares = 0 profit = 0 sale_profit = 0 current_symbol = r.get_instrument_by_url(instrument)['symbol'] for order in all_orders: if order['instrument'] == instrument: name = r.stocks.get_instrument_by_url(order['instrument'])['name'] last_transaction_at = order['last_transaction_at'] side = order['side'] year = last_transaction_at.split('-')[0] month = last_transaction_at.split('-')[1].strip('0') day = last_transaction_at.split('-')[2].split('T')[0] for execution in order['executions']: price = execution['price'] quantity = execution['quantity'] total = float(quantity) * float(price) print('!Type:Invst') print("D" + month + "/" + day + "'" + year) if side == 'buy': print('NBuy') elif side == 'sell': print('NSell') print('Y' + name) print('T' + str(total)) print('I' + price) print('Q' + quantity) print('^')