-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_index_pairs.py
63 lines (54 loc) · 2.36 KB
/
update_index_pairs.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
import logging
from database import (Currency, ExPair, IndexPair, db_session)
log = logging.getLogger(__name__)
def update_ips():
""" Creates index pairs (if necessary) for all individual ExPairs.
"""
log.debug("Updating IndexPair table")
# Query for all Currencies
all_curs = Currency.query.all()
# Quote currencies: BTC, USD, EUR
quote_curs = Currency.query.filter(Currency.symbol.in_(['BTC', 'USD', 'EUR', 'USDT', 'TUSD', 'USDC', 'USDS', 'GUSD', 'PAX'])).all()
try:
for quote_cur in quote_curs:
for base_cur in all_curs:
if base_cur.symbol in ['USD', 'EUR', 'USDT', 'TUSD', 'USDC', 'USDS', 'GUSD', 'PAX']:
# Don't want USDT/BTC or similar
continue
if quote_cur == base_cur:
continue
# Check for any ExPair for given base/quote
ex_pair = ExPair.query.filter_by(
quote_currency_id=quote_cur.id,
base_currency_id=base_cur.id,
active=True).first()
# ExPair exists, so we need a matching IndexPair
index_pair = IndexPair.query.filter_by(
quote_currency_id=quote_cur.id,
base_currency_id=base_cur.id
).first()
if not ex_pair and index_pair:
# No matching ex_pair, setting index_pair to inactive
index_pair.active = False
index_pair.save_to_db()
continue
if not ex_pair:
continue
if index_pair: # IndexPair already exists
continue
else:
log.debug("Adding missing IndexPair for %s/%s" %
(base_cur.symbol, quote_cur.symbol))
# Missing IndexPair, create new one
ip = IndexPair(
quote_currency_id=quote_cur.id,
base_currency_id=base_cur.id,
quote_symbol=quote_cur.symbol,
base_symbol=base_cur.symbol,
active=True,
candle_1h=True
)
db_session.add(ip)
db_session.commit()
except Exception as e:
log.error(e)