Initial work on bittrex implementation

This commit is contained in:
fredfortier
2017-08-27 23:26:48 -04:00
parent c40fd98022
commit 1cfcb1d96e
12 changed files with 536 additions and 38 deletions
View File
+34
View File
@@ -0,0 +1,34 @@
import unittest
from abc import ABCMeta, abstractmethod
class BaseExchangeTestCase():
__metaclass__ = ABCMeta
@abstractmethod
def test_order(self):
pass
@abstractmethod
def test_open_orders(self):
pass
@abstractmethod
def test_get_order(self):
pass
@abstractmethod
def test_cancel_order(self):
pass
@abstractmethod
def test_get_candles(self):
pass
@abstractmethod
def test_tickers(self):
pass
@abstractmethod
def get_account(self):
pass
+126
View File
@@ -0,0 +1,126 @@
from catalyst.exchange.bitfinex.bitfinex import Bitfinex
from .base import BaseExchangeTestCase
from logbook import Logger
import pandas as pd
from catalyst.finance.execution import (MarketOrder,
LimitOrder,
StopOrder,
StopLimitOrder)
from catalyst.exchange.exchange_utils import get_exchange_auth
log = Logger('test_bitfinex')
class BitfinexTestCase(BaseExchangeTestCase):
@classmethod
def setup(self):
print ('creating bitfinex object')
auth = get_exchange_auth('bitfinex')
self.exchange = Bitfinex(
key=auth['key'],
secret=auth['secret'],
base_currency='usd'
)
def test_order(self):
log.info('creating order')
pass
def test_open_orders(self):
log.info('retrieving open orders')
pass
def test_get_order(self):
log.info('retrieving order')
pass
def test_cancel_order(self):
log.info('cancel order')
pass
def test_get_candles(self):
log.info('retrieving candles')
pass
def test_tickers(self):
log.info('retrieving tickers')
pass
def get_account(self):
log.info('retrieving account data')
pass
# def test_order(self):
# log.info('ordering from bitfinex')
# bitfinex = Bitfinex()
# order_id = bitfinex.order(
# asset=bitfinex.get_asset('eth_usd'),
# style=LimitOrder(limit_price=200),
# limit_price=200,
# amount=0.5,
# stop_price=None
# )
# log.info('order created {}'.format(order_id))
# pass
#
# def test_portfolio(self):
# log.info('fetching portfolio data')
# pass
#
# def test_account(self):
# log.info('fetching account data')
# pass
#
# def test_time_skew(self):
# log.info('time skew not implemented')
# pass
#
# def test_get_open_orders(self):
# log.info('fetching open orders')
# bitfinex = Bitfinex()
# order_id = bitfinex.get_open_orders()
# log.info('open orders: {}'.format(order_id))
# pass
#
# def test_get_order(self):
# log.info('querying orders from bitfinex')
# bitfinex = Bitfinex()
# response = bitfinex.get_order(order_id=3361248395)
# log.info('the order: {}'.format(response))
# pass
#
# def test_cancel_order(self):
# log.info('canceling order from bitfinex')
# bitfinex = Bitfinex()
# response = bitfinex.cancel_order(order_id=3330847408)
# log.info('canceled order: {}'.format(response))
# pass
#
# def test_get_spot_value(self):
# log.info('spot value not implemented')
# bitfinex = Bitfinex()
# assets = [
# bitfinex.get_asset('eth_usd'),
# bitfinex.get_asset('etc_usd'),
# bitfinex.get_asset('eos_usd'),
# ]
# # assets = bitfinex.get_asset('eth_usd')
# value = bitfinex.get_spot_value(
# assets=assets,
# field='close',
# data_frequency='minute'
# )
# pass
#
# def test_tickers(self):
# log.info('fetching ticker from bitfinex')
# bitfinex = Bitfinex()
# current_date = pd.Timestamp.utcnow()
# assets = [
# bitfinex.get_asset('eth_usd'),
# bitfinex.get_asset('etc_usd'),
# bitfinex.get_asset('eos_usd'),
# ]
# tickers = bitfinex.tickers(date=current_date, assets=assets)
# log.info('got tickers {}'.format(tickers))
# pass
+51
View File
@@ -0,0 +1,51 @@
from catalyst.exchange.bittrex.bittrex import Bittrex
from .base import BaseExchangeTestCase
from logbook import Logger
import pandas as pd
from catalyst.finance.execution import (MarketOrder,
LimitOrder,
StopOrder,
StopLimitOrder)
from catalyst.exchange.exchange_utils import get_exchange_auth
log = Logger('test_bittrex')
class BittrexTestCase(BaseExchangeTestCase):
@classmethod
def setup(self):
print ('creating bittrex object')
auth = get_exchange_auth('bittrex')
self.exchange = Bittrex(
key=auth['key'],
secret=auth['secret'],
base_currency='usd'
)
def test_order(self):
log.info('creating order')
pass
def test_open_orders(self):
log.info('retrieving open orders')
pass
def test_get_order(self):
log.info('retrieving order')
pass
def test_cancel_order(self):
log.info('cancel order')
pass
def test_get_candles(self):
log.info('retrieving candles')
pass
def test_tickers(self):
log.info('retrieving tickers')
pass
def get_account(self):
log.info('retrieving account data')
pass
+50
View File
@@ -0,0 +1,50 @@
from unittest import TestCase
from logbook import Logger
from mock import patch, sentinel
from catalyst.exchange.exchange_clock import ExchangeClock
from catalyst.utils.calendars.trading_calendar import days_at_time
from datetime import time
from collections import defaultdict
from catalyst.utils.calendars import get_calendar
import pandas as pd
log = Logger('ExchangeClockTestCase')
class ExchangeClockTestCase(TestCase):
@classmethod
def setUpClass(cls):
cls.open_calendar = get_calendar("OPEN")
cls.sessions = pd.Timestamp.utcnow()
def setUp(self):
self.internal_clock = None
self.events = defaultdict(list)
def advance_clock(self, x):
"""Mock function for sleep. Advances the internal clock by 1 min"""
# The internal clock advance time must be 1 minute to match
# MinutesSimulationClock's update frequency
self.internal_clock += pd.Timedelta('1 min')
def get_clock(self, arg, *args, **kwargs):
"""Mock function for pandas.to_datetime which is used to query the
current time in RealtimeClock"""
assert arg == "now"
return self.internal_clock
def test_clock(self):
with patch('catalyst.exchange.exchange_clock.pd.to_datetime') as to_dt, \
patch('catalyst.exchange.exchange_clock.sleep') as sleep:
clock = ExchangeClock(sessions=self.sessions)
to_dt.side_effect = self.get_clock
sleep.side_effect = self.advance_clock
start_time = pd.Timestamp.utcnow()
self.internal_clock = start_time
events = list(clock)
# Event 0 is SESSION_START which always happens at 00:00.
ts, event_type = events[1]
pass