forked from wookpump/wookpump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarketHist.py
61 lines (49 loc) · 1.72 KB
/
marketHist.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
from bittrex import Bittrex
import json
import threading
from threading import Thread
import traceback
from pymongo import MongoClient
import time
with open("secrets.json") as secrets_file:
secrets = json.load(secrets_file)
secrets_file.close()
bittrex = Bittrex(secrets['key'], secrets['secret'])
client = MongoClient("mongodb://127.0.0.1:27017")
db = client.market_history
class ThreadGetMarketHistory(Thread):
def __init__(self, MarketName):
self.MarketName = MarketName
threading.Thread.__init__(self)
def run(self):
while True:
try:
history = bittrex.get_market_history(self.MarketName, 10)
for data in history['result']:
result = db[MarketName].insert_one(data)
print(result)
# result = db[MarketName].insert_one(history['result'])
except:
print(self.MarketName + ' : error')
traceback.print_exc()
break
time.sleep(1.1)
def isExcludedCoin(MarketName):
print("MarketName : " + MarketName)
with open("excluded_coin_list.json") as f:
excludedCoinName = json.load(f)
if MarketName in excludedCoinName['coin']:
print("Excluded")
return True
else:
print("Included")
return False
result = bittrex.get_markets()
for coin in result['result']:
MarketName = coin['MarketName']
if 'BTC-' in MarketName and coin['IsActive'] and isExcludedCoin(MarketName) is not True:
try:
ThreadGetMarketHistory(MarketName).start()
except:
print('error : ' + MarketName)
# print(MarketName + ' : ' + str(currency))