-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram_manager.py
More file actions
134 lines (95 loc) · 6.37 KB
/
program_manager.py
File metadata and controls
134 lines (95 loc) · 6.37 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
'''
Created on Jun 6, 2018
@author: dpolyakov
This script will be the launching point of the bot overall.
'''
#import a bunch of stuff that maybe i need.
import decider2 as dec
import ticker
import cbpro, time, datetime, _csv
import numpy as np
import matplotlib.pyplot as plt
def main():
print("Bot Started")
#excel recorder initialization
with open("C:/Users/Danny/Documents/GitHub/bot/output.csv", 'w', encoding='utf8') as f:
outputFile = _csv.writer(f, delimiter=',', lineterminator='\n')
#data for testing purposes
'''
btcData = _csv.reader(open("FILEPATH", 'r', encoding='utf8'), delimiter=',', lineterminator='\n')
ltcData = _csv.reader(open("FILEPATH", 'r', encoding='utf8'), delimiter=',', lineterminator='\n')
ethData = _csv.reader(open("FILEPATH", 'r', encoding='utf8'), delimiter=',', lineterminator='\n')
etcData = _csv.reader(open("FILEPATH", 'r', encoding='utf8'), delimiter=',', lineterminator='\n')
bchData = _csv.reader(open("FILEPATH", 'r', encoding='utf8'), delimiter=',', lineterminator='\n')
'''
#authorized client initialization
#websocket client initializtion Litecoin Bitcoin Ether Ether Classic Bitcoin Cash
#general_client = ticker.TickerWebsocketClient(message_type='ticker',products=["LTC-USD", "BTC-USD", "ETH-USD", "ETC-USD", "BCH-USD"])
general_client = ticker.TickerWebsocketClient(message_type='ticker',products=["BTC-USD"])
general_client.start()
general_client.verify_data_loaded() #verification of data moved to api
initial_ana_values = {}
print('getting initial analyzer values')
while len(initial_ana_values) < 1: #change value to 5 when testing all currencies
print(initial_ana_values)
crypto = general_client.message['product_id']
initial_ana_values[crypto] = float(general_client.message['price'])
print(initial_ana_values)
# initial val crypto type wal_usc al_cryp quant, thresh auth_client
#bitcoin
decBTC = dec.Decider2(initial_ana_values['BTC-USD'], 'BTC', 50.0, .5, .25, .024 )
'''
Non litecoin analysis commented out for testing reasons
#bitcoin
decBTC = dec.Decider2(initial_ana_values['BTC-USD'], 'BTC', 50.0, .5, .25, .024, auth_client)
#ether
decETH = dec.Decider2(initial_ana_values['ETH-USD'], 'ETH', 50.0, .5, .25, .024, auth_client)
#ether classic
decETC = dec.Decider2(initial_ana_values['ETC-USD'], 'ETC', 50.0, .5, .25, .024, auth_client)
#bitcoin cash
decBCH = dec.Decider2(initial_ana_values['BCH-USD'], 'BCH', 50.0, .5, .25, .024, auth_client)
#litecoin
decLTC = dec.Decider2(initial_ana_values['LTC-USD'], 'LTC', 50.0, .5, .25, .024, auth_client)
#
general_dict = {'LTC-USD' : decLTC, 'BTC-USD' : decBTC, 'ETH-USD' : decETH, 'ETC-USD' : decETC, 'BCH-USD' : decBCH}
'''
general_dict = {'BTC-USD' : decBTC}
#create a decider object with specified given variables
# initial val, crypto type, start USD, start LTC, quant, threshhold, analyzer object, auth_client(for trading)
#dec = decider.Decider(float(ws_client.message['price']), 'LTC', 50.0, .5, .25, .024, analy, auth_client)
print('setup finished. Main loop Started.')
prev_prod = general_client.message['trade_id']
general_dict[general_client.message['product_id']].anaAdd(float(general_client.message['price']))
print(general_client.message)
#print(general_client.message)
count = 1
#run forever
while True:
if not prev_prod == general_client.message['trade_id']:
prod = general_client.message['product_id']
prev_prod = general_client.message['trade_id']
general_dict[prod].anaAdd(float(general_client.message['price']))
general_dict[prod].trade()
temp = general_dict[prod].ana2
print("--------------------------------------------------------------------------------------------------------------------")
# print([count, temp.prev, temp.first_order, temp.second_order, temp._5, temp._5roc, temp._5roc2, temp._10, temp._10, temp._10,
# temp._30, temp._30roc, temp._30roc2, temp._60, temp._60roc, temp._60roc2])
# outputFile.writerow([count, temp.prev, temp.first_order, temp.second_order, temp._5, temp._5roc, temp._5roc2, temp._10, temp._10, temp._10,
# temp._30, temp._30roc, temp._30roc2, temp._60, temp._60roc, temp._60roc2])
outputFile.writerow([count, temp.prev, general_dict[prod].wal.totalVal, general_dict[prod].wal.USD_value,
general_dict[prod].wal.crypto_value])
print(count)
# print(general_client.message)
print(general_dict[prod].ana2.toString()) #10 entries
general_dict[prod].wal.total(general_dict[prod].ana2.prev)
print(general_dict[prod].toString())
count +=1
# toPlot = general_dict[prod].ana2.data[0:9]
# print(toPlot)
# plt.plot([0,1,2,3,4,5,6,7,8,9],toPlot)
# plt.ylabel("Current Val")
# plt.xlabel("Previous Ticks")
# plt.show()
print("--------------------------------------------------------------------------------------------------------------------")
if __name__ == '__main__':
main()