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?
Asked
Active
Viewed 1,135 times
-6
-
Are you asking about how to create/write to files in python? What specific problem are you having? – Patrick Haugh Jan 07 '18 at 04:01
-
...and what code/research you have done so far? – Sunil Jan 07 '18 at 04:02
-
The answers to the question [Saving an Object (Data persistence)](https://stackoverflow.com/questions/4529815/saving-an-object-data-persistence) might be helpful. – martineau Jan 07 '18 at 04:14
1 Answers
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.

F Rooyackers
- 45
- 5