Skip to content

Instantly share code, notes, and snippets.

@anthonymorast
Last active Feb 14, 2020
Embed
What would you like to do?
## Buy as many notes out of the goodness_dict that we can
purchasedNotes = pd.DataFrame(columns=notedf.columns)
for key in goodness_dict:
row = notedf.loc[key]
loanId = row["LoanId"]
orderId = row["OrderId"]
noteId = row["NoteId"]
price = row["AskPrice"]
log.write("Attempting to buy note\n")
log.write("\tLoanId: " + str(loanId) + "\tOrderId: " + str(orderId) + \
"\tNoteId: " + str(noteId) + "\tPrice: " + str(price) + "\tTheir YTM: " + str(row["YTM"]) + \
"\tMarkup/Discount: " + str(row['Markup Discount']) + "\tMy YTM: " + str(row["MyYield"]) + "\n")
response = None
if cash > price:
if manual:
print(row)
val = input("\nDo you want to purchase this note (y/n)?")
while val != 'y' and val != 'n':
val = input("Select Yes or No (y/n): ")
if val == 'n':
print("\n\nPassing on note.\n\n")
continue
if val == 'y':
print("\n\nPurchasing note...\n\n")
response = api.buy_note(loanId, orderId, noteId, price)
else:
response = api.buy_note(loanId, orderId, noteId, price)
else:
log.write("\tNot enough cash! Available Cash: " + str(cash) + " Note Price: " + str(price) + "\n")
# not enough money, try the next note
continue
# successful? change cash
if response is not None:
executionStatus = response["buyNoteConfirmations"][0]["executionStatus"][0].strip()
log.write("\tExecution Status: " + executionStatus + "\n")
if executionStatus == "SUCCESS_PENDING_SETTLEMENT":
log.write("\tThe note was successfully purchased, pending settlement.\n")
purchasedNotes = purchasedNotes.append(row, ignore_index=True)
cash -= price
if purchasedNotes.shape[0] > 0:
purchasedNotes.to_csv("/home/pi/FolioBot/purchase_history/" + datetime.now(pytz.timezone('US/Mountain')).strftime("%Y_%m_%d_%H_%M_%S") + "_purchased_notes.csv", index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment