-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.py
More file actions
159 lines (143 loc) · 4.62 KB
/
Copy pathSetup.py
File metadata and controls
159 lines (143 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Novixel's Config File Setup
# ConfigSetup.py
# CryptoCollector
# Version 1.2.1b
# May 5th, 2021
import os
from pathlib import Path
from configparser import ConfigParser
from datetime import datetime
# (Build Directory)
# Build A place for the bots config files to be stored
def BuildBotNest():
fullPath = os.path.realpath(__file__) # Get Exact Path to this file
thisDir = os.path.dirname(fullPath) # Get Exact Directory of this File
botFold = thisDir + '\BOT' # Create a new folder path for setup
Path(botFold).mkdir(parents=True, exist_ok=True) # Check for folder or make if not there
os.chdir(botFold) # change Directory to save setup files
return botFold
path = str(BuildBotNest()) # we need this for all the settings :)
pathStr = (path + '\info.ini') # create the file string for repeat
pathTra = (path + '\_trades.ini')
pathLog = (path + "\log.log")
# (Build Config File)
# Build a config file in that folder we just made for later use.
def BuildBotSettings():
config_object = ConfigParser()
config_object["API"] = {
"key" : "CoinbaseProAPI key",
"b64secret" : "CoinbaseProAPI b64secret",
"passphrase" : "CoinbaseProAPI passphrase"
}
config_object["TICKER"] = {
"trade_id" : "Trade ID Number",
"price" : "Current Price",
"size" : "0.000000000000000",
"time" : "2021-05-01T12:00:00.578544Z",
"bid" : "0.000000000000000",
"ask" : "0.000000000000000",
"volume" : "0.000000000000000"
}
#Write to a file!!
with open(pathStr,'w') as conf:
config_object.write(conf)
# (Edit That Config File)
# Save to new data to The Config File we just made
# these need to be compacted in to one function
def SaveNewApi(key,b64secret,passphrase):
c = ConfigParser()
c.read(pathStr)
#Get the api from config
API = c["API"]
API["key"] = str(key)
API["b64secret"] = str(b64secret)
API["passphrase"] = str(passphrase)
#Write changes back to file
with open(pathStr, 'w') as conf:
c.write(conf)
def SaveDisplay(x,d):
c = ConfigParser()
c.read(pathStr)
#Get the api from config
if c.has_section(str("DISPLAY")):
pass
else:
c.add_section(str("DISPLAY"))
#then edit it
display = c[str("DISPLAY")]
display[str(x)] = d
with open(pathStr, 'w') as conf:
c.write(conf)
def SaveAccount(cur, x,d):
c = ConfigParser()
c.read(pathStr)
#Get the api from config
if c.has_section(str(cur + "ACCOUNT")):
pass
else:
c.add_section(str(cur + "ACCOUNT"))
#then edit it
account = c[str(cur + "ACCOUNT")]
account[str(x)] = d
with open(pathStr, 'w') as conf:
c.write(conf)
def SaveTicker(x , d ):
c = ConfigParser()
c.read(pathStr)
#Get the api from config
TICKER = c["TICKER"]
TICKER[str(x)] = d
with open(pathStr, 'w') as conf:
c.write(conf)
def SaveTrade(cur,amount):
now = datetime.now()
time = now.strftime("%m/%d/%Y, %H:%M:%S")
with open(pathTra, 'a') as conf:
Text = (time +","+ cur + ",PROFIT," + ("%.4f"%amount))
conf.writelines(Text + "\n")
conf.close
def LogThis(message):
message = str(message)
now = datetime.now()
time = now.strftime("%m/%d/%Y, %H:%M:%S")
with open(pathLog, 'a') as log:
Text = (time + ":DEBUG: " + message)
log.writelines(Text + "\n")
log.close
# (Read That Config File)
# Read the file and assign variables to the values
# these need to be compacted in to one function
def ReadConfig(x):
"""x should be what you want from the config file as a string"""
c = ConfigParser()
c.read(pathStr)
#Get Info from config
API = c["API"]
return API[x]
def ReadTICKER(x):
"""x = 'price',etc """
c = ConfigParser()
c.read(pathStr)
#Get Info from config
TICKER = c["TICKER"]
return TICKER[x]
def ReadAccount(cur,x):
"""x = 'available',etc """
c = ConfigParser()
c.read(pathStr)
#Get Info from config
ACCOUNT = c[str(cur + "ACCOUNT")]
return ACCOUNT[x]
def ReadDisplay(x):
"""x = 'currency',etc """
c = ConfigParser()
c.read(pathStr)
#Get Info from config
DISPLAY = c["DISPLAY"]
return DISPLAY[x]
def ReadALLDisplay():
c = ConfigParser()
c.read(pathStr)
#Get Info from config
DISPLAY = c["DISPLAY"]
return DISPLAY