def get_debits(exchange=None, address=None, currency=None, ref_id=None, session=None): if session is None: session, eng = create_session_engine() query = session.query(wm.Debit) query = filter_query_by_attr(query, wm.Debit, 'ref_id', ref_id) query = filter_query_by_attr(query, wm.Debit, 'network', exchange) query = filter_query_by_attr(query, wm.Debit, 'address', address) query = filter_query_by_attr(query, wm.Debit, 'currency', currency) resp = [] for deb in query: resp.append(deb) return resp
def get_balances(exchange=None, currency=None, session=None): if session is None: session, eng = create_session_engine() query = session.query(wm.Balance) if currency is not None: query = filter_query_by_attr(query, wm.Balance, 'currency', currency) if exchange is not None: query = query.join(um.User).filter(um.User.username == "%sManager" % exchange.lower()) total = Balance() available = Balance() for bal in query: total = total + bal.total available = available + bal.available return total, available
def get_trades(exchange=None, market=None, tid=None, trade_id=None, session=None): if session is None: session, eng = create_session_engine() query = session.query(em.Trade) if trade_id is not None: trade_id = trade_id if "|" in str(trade_id) else '%s|%s' % (exchange.lower(), trade_id) query = filter_query_by_attr(query, em.Trade, 'trade_id', trade_id) query = filter_query_by_attr(query, em.Trade, 'exchange', exchange) query = filter_query_by_attr(query, em.Trade, 'market', market) query = filter_query_by_attr(query, em.Trade, 'id', tid) resp = [] for trade in query: resp.append(trade) return resp
def get_orders(exchange=None, market=None, side=None, oid=None, order_id=None, state=None, session=None): if session is None: session, eng = create_session_engine() query = session.query(em.LimitOrder) if order_id is not None: order_id = order_id if "|" in str(order_id) else '%s|%s' % (exchange.lower(), order_id) query = filter_query_by_attr(query, em.LimitOrder, 'order_id', order_id) query = filter_query_by_attr(query, em.LimitOrder, 'market', market) query = filter_query_by_attr(query, em.LimitOrder, 'side', side) query = filter_query_by_attr(query, em.LimitOrder, 'exchange', exchange) query = filter_query_by_attr(query, em.LimitOrder, 'id', oid) query = filter_query_by_attr(query, em.LimitOrder, 'state', state) resp = [] for order in query: resp.append(order) return resp
def setUp(self): self.ses, self.eng = create_session_engine(cfg=get_config("helper")) setup_database(self.eng, modules=[um, em, wm])
def test_create_session_engine_cfg(): cfg = get_config("helper") ses, eng = create_session_engine(cfg=cfg) assert str(eng.url) == cfg.get('db', 'SA_ENGINE_URI')
""" The main trade_manager module. Initializes sessions, and connections. """ from sqlalchemy_models import wallet as wm, exchange as em, user as um, create_session_engine, setup_database from tapp_config import get_config CFG = get_config('trade_manager') ses, eng = create_session_engine(cfg=CFG) setup_database(eng, modules=[wm, em, um]) NETWORK_COMMODITY_MAP = {'BTC': 'Bitcoin', 'DASH': 'Dash', 'ETH': 'Ethereum', 'LTC': 'Litecoin'} EXCHANGES = ['kraken', 'bitfinex', 'poloniex']
def setup_connections(self): if self.session is None or self.engine is None: self.session, self.engine = create_session_engine(cfg=self.cfg) setup_database(self.engine, modules=[wm, em, um]) self.red = setup_redis() if self.red is None else self.red