Last active
February 14, 2020 16:11
-
-
Save anthonymorast/183f12c0b43e3a5cb68e3708f3787677 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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