-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtcturkclass.py
153 lines (144 loc) · 5.81 KB
/
btcturkclass.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from datetime import datetime
import errorclass as error
import requests
import mariadb
class ExchangeInfo:
def __init__(self,
dbCursor=None,
symbol=None,
baseAsset=None,
quoteAsset=None,
baseAssetName=None,
exchangeId=3, # BTCTURK
status=0,
updateDate=datetime.now().strftime("%Y-%m-%d"),
updateTime=datetime.now().strftime("%H:%M:%S")
):
self.dbCursor = dbCursor
self.symbol = symbol # ETHBTC
self.baseAsset = baseAsset # ETH
self.quoteAsset = quoteAsset # BTC
self.baseAssetName = baseAssetName # ethereum
self.exchangeId = exchangeId # 3 (BTCTURK)
self.status = status
self.updateDate = updateDate
self.updateTime = updateTime
def getData(self, url=None):
dbCursor = self.dbCursor
try:
response = requests.get(url)
response.raise_for_status()
records = response.json()
return records['data']['symbols']
# return records['result']['data']
except requests.exceptions.HTTPError as errh:
log = error.ErrorLog()
log.dbCursor = dbCursor
log.errorNo = errh.response.status_code
log.errorMessage = errh.response.text
log.moduleName = type(self).__name__
log.explanation = "Http Error: " + errh.response.url
log.addData()
except requests.exceptions.ConnectionError as errc:
log = error.ErrorLog()
log.dbCursor = dbCursor
log.errorNo = errc.response.status_code
log.errorMessage = errc.response.text
log.moduleName = type(self).__name__
log.explanation = "Error Connecting: " + errc.response.url
log.addData()
except requests.exceptions.Timeout as errt:
log = error.ErrorLog()
log.dbCursor = dbCursor
log.errorNo = errt.response.status_code
log.errorMessage = errt.response.text
log.moduleName = type(self).__name__
log.explanation = "Timeout Error: " + errt.response.url
log.addData()
except requests.exceptions.RequestException as err:
log = error.ErrorLog()
log.dbCursor = dbCursor
log.errorNo = err.response.status_code
log.errorMessage = err.response.text
log.moduleName = type(self).__name__
log.explanation = err.response.url
log.addData()
def addData(self):
try:
self.dbCursor.execute(
"INSERT INTO coin (symbol, base_asset, quote_asset, base_asset_name, "
" exchange_id, status, update_date, update_time) "
"VALUES (?, ?, ?, ?, ? ,?, ?, ?)",
(self.symbol, self.baseAsset, self.quoteAsset, self.baseAssetName,
self.exchangeId, self.status, self.updateDate, self.updateTime))
except mariadb.Error as e:
# print(f"Error: {e.errno} {e.errmsg}")
log = error.ErrorLog()
log.dbCursor = self.dbCursor
log.errorNo = e.errno
log.errorMessage = e.errmsg
log.moduleName = type(self).__name__
log.explanation = "INSERT INTO coin"
log.addData()
class OrderBook:
def __init__(self,
dbCursor=None,
symbol=None,
bidPrice=None,
bidQty=None,
askPrice=None,
askQty=None
):
self.dbCursor = dbCursor
self.symbol = symbol
self.bidPrice = bidPrice
self.bidQty = bidQty
self.askPrice = askPrice
self.askQty = askQty
def getData(self, url=None):
dbCursor = self.dbCursor
prm = {'pairSymbol': self.symbol,
'limit': 1
}
try:
response = requests.get(url, params=prm)
# response = requests.get(url=prm)
response.raise_for_status()
records = response.json()
return records['data']
# return records['result']['data']
except requests.exceptions.HTTPError as errh:
log = error.ErrorLog()
log.dbCursor = dbCursor
log.errorNo = errh.response.status_code
log.errorMessage = errh.response.text
log.moduleName = type(self).__name__
if errh.response.status_code == 429:
log.explanation = "Too many request: " + errh.response.url
else:
log.explanation = "Http Error: " + errh.response.url
log.addData()
except requests.exceptions.ConnectionError as errc:
log = error.ErrorLog()
log.dbCursor = dbCursor
log.errorNo = errc.response.status_code
log.errorMessage = errc.response.text
log.moduleName = type(self).__name__
log.explanation = "Error Connecting: " + errc.response.url
log.addData()
except requests.exceptions.Timeout as errt:
log = error.ErrorLog()
log.dbCursor = dbCursor
log.errorNo = errt.response.status_code
log.errorMessage = errt.response.text
log.moduleName = type(self).__name__
log.explanation = "Timeout Error: " + errt.response.url
log.addData()
except requests.exceptions.RequestException as err:
log = error.ErrorLog()
log.dbCursor = dbCursor
log.errorNo = err.response.status_code
log.errorMessage = err.response.text
log.moduleName = type(self).__name__
log.explanation = err.response.url
log.addData()