-6

I️ want to write a program in Python that saves the history of crypto currency purchases/sales I️ make. I️ want to be able to save data such as time of purchase, price of currency at time of transaction, and profit to look for patterns. How would I️ go about saving this data?

martineau
  • 119,623
  • 25
  • 170
  • 301
jfisher020
  • 19
  • 2

1 Answers1

0

You can make yourself a program writing a history file or log as a plain .txt file very easily:

import datetime
import os

os.chdir("C:\Users\<username>\Documents") #Location of history file

day_of_purchase = datetime.date.today()
price_of_currency = 10
profit = 0

file_object  = open("textfile.txt", "w")
file_object.write(str(day_of_purchase)+"," +str(price_of_currency)+"," +str(profit))
file_object.close()

If you want to keep adding history output to the file just append the .txt file. You could also set up a more sophisticated .csv file using the csv module: https://docs.python.org/3.4/library/csv.html. You can also use some more elaborated libraries to save an excel file although excel is very capable of reading .csv files directly, using a designated character as a column deliminator. (In the above case, select the comma as the deliminator.)

You can make the program more sophisticated by creating some interactive components like the input() parameter.