-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalytics.py
135 lines (98 loc) · 4.37 KB
/
analytics.py
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
############
# By Michael Bjeski
# With motivation from Satoshi, finest in the crypto MOONING Industry
# Start: 04.10.2018
# Get coin-pair information from cryptocurrency exchanges and save that information into a csv or excel file
# while using pandas; ccxt-library, cryptocompare-api
############
"""
MIT License
Copyright (c) 05.11.2018 Michael Bjeski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import getpass
import logging
logging.getLogger(__name__).addHandler(logging.NullHandler())
from cryptor import Decryptor
import json
from Api_Classes_ccxt import ApiClassesCCXT
from csv_executor import CSVExecutor
# Entry point for analytics.py -> if "python analytics.py" is called
if __name__ == '__main__':
crypt = Decryptor()
classes_exchanges_used = []
exchanges_used = []
d = []
try:
with open('exch_details.json') as json_data:
# with open('exchanges_details_ETH.json') as json_data:
d = json.load(json_data)
json_data.close()
exchanges_used = d['exchanges_used'] # all exchanges being taken into account for loop
print(exchanges_used)
passwd = getpass.getpass('pass?:') # (input("pass?"))
saltwd = getpass.getpass('salt?:') # (input("salt?"))
c = False
while not c:
ask_price = input("Get price in USD? (y,n)")
if ask_price == "y":
c = True
ask_price = True
elif ask_price == "n":
c = True
ask_price = False
for count in range(0, len(exchanges_used)):
name_exchange = exchanges_used[count]
pub = d[name_exchange]["pub_key_crypt"]
priv = d[name_exchange]["priv_key_crypt"]
decrypt_returner = crypt.decrypt(pub, priv, passwd, saltwd)
pub_returner = bytes.decode(decrypt_returner[0])
priv_returner = bytes.decode(decrypt_returner[1])
x = ApiClassesCCXT(pub_returner, priv_returner, name_exchange)
classes_exchanges_used.append(x)
except ValueError:
print('Critical need restart')
# Get balances from every coin from and use parameter -> exchanges_used
dict_coins_exchanges = {'test': {'coin_1': 'amount', 'coin_2': 'amount'}} # example
list_final = []
helper_dict = {'coin_1': 'amount'} # example
dict_coins_exchanges.clear()
helper_dict.clear()
for counter in range(0, len(exchanges_used)):
balance_info = classes_exchanges_used[counter].fetch_balance()
loop_name = 0
if balance_info:
loop_name = classes_exchanges_used[counter].returnName()
print(loop_name)
else:
continue
##################### EXCEPTION HANDLING #################################
if loop_name == 'liqui':
var_balance = 'free'
else:
var_balance = 'total'
##################### EXCEPTION HANDLING #################################
# print(balance_info[var_balance].items())
helper_dict.clear()
for k, v in balance_info[var_balance].items():
if v > 0.001: # Minimum Amount on exchange
helper_dict.update({str(k): str(v)})
dict_coins_exchanges = {loop_name: helper_dict.copy()}
list_final.append(dict_coins_exchanges)
# print(list_final)
csv_class = CSVExecutor(list_final, ask_price)
# print(list_final)