Bug fixes and working on unit tests for the data portal

This commit is contained in:
fredfortier
2017-09-18 22:19:27 -04:00
parent 18bfaff7c9
commit b70ff3a740
6 changed files with 52 additions and 41 deletions
+30 -30
View File
@@ -60,7 +60,7 @@ class DataPortalExchangeBase(DataPortal):
exchange = self.exchanges[exchange_name]
assets = exchange_assets[exchange_name]
df = self.get_exchange_spot_value_history_window(
df_exchange = self.get_exchange_history_window(
exchange,
assets,
end_dt,
@@ -70,7 +70,7 @@ class DataPortalExchangeBase(DataPortal):
data_frequency,
ffill)
df_list.append(df)
df_list.append(df_exchange)
# Merging the values values of each exchange
return pd.concat(df_list)
@@ -113,7 +113,7 @@ class DataPortalExchangeBase(DataPortal):
bar_count,
frequency,
field,
data_frequency,
data_frequency=None,
ffill=True):
return self._get_history_window(assets,
end_dt,
@@ -124,15 +124,15 @@ class DataPortalExchangeBase(DataPortal):
ffill)
@abc.abstractmethod
def get_exchange_spot_value_history_window(self,
exchange,
assets,
end_dt,
bar_count,
frequency,
field,
data_frequency,
ffill=True):
def get_exchange_history_window(self,
exchange,
assets,
end_dt,
bar_count,
frequency,
field,
data_frequency,
ffill=True):
pass
def _get_spot_value(self, assets, field, dt, data_frequency,
@@ -202,15 +202,15 @@ class DataPortalExchangeLive(DataPortalExchangeBase):
def __init__(self, *args, **kwargs):
super(DataPortalExchangeLive, self).__init__(*args, **kwargs)
def get_exchange_spot_value_history_window(self,
exchange,
assets,
end_dt,
bar_count,
frequency,
field,
data_frequency,
ffill=True):
def get_exchange_history_window(self,
exchange,
assets,
end_dt,
bar_count,
frequency,
field,
data_frequency,
ffill=True):
df = exchange.get_history_window(
assets,
end_dt,
@@ -233,15 +233,15 @@ class DataPortalExchangeBacktest(DataPortalExchangeBase):
def __init__(self, exchanges, *args, **kwargs):
super(self.__class__, self).__init__(exchanges, *args, **kwargs)
def get_exchange_spot_value_history_window(self,
exchange,
assets,
end_dt,
bar_count,
frequency,
field,
data_frequency,
ffill=True):
def get_exchange_history_window(self,
exchange,
assets,
end_dt,
bar_count,
frequency,
field,
data_frequency,
ffill=True):
df = exchange.get_history_window(
assets,
end_dt,
+2 -2
View File
@@ -346,7 +346,7 @@ class Exchange:
bar_count,
frequency,
field,
data_frequency,
data_frequency=None,
ffill=True):
"""
@@ -399,7 +399,7 @@ class Exchange:
value_series = pd.Series(values, index=dates)
series[asset] = value_series
df = pd.concat(series)
df = pd.DataFrame(series)
return df
def synchronize_portfolio(self):
+1 -1
View File
@@ -2,7 +2,7 @@ import unittest
from abc import ABCMeta, abstractmethod
class BaseExchangeTestCase():
class BaseExchangeTestCase:
__metaclass__ = ABCMeta
@abstractmethod
+1 -2
View File
@@ -1,7 +1,6 @@
from catalyst.exchange.bitfinex.bitfinex import Bitfinex
from .base import BaseExchangeTestCase
from base import BaseExchangeTestCase
from logbook import Logger
import pandas as pd
from catalyst.finance.execution import (MarketOrder,
LimitOrder,
StopOrder,
+1 -1
View File
@@ -1,6 +1,6 @@
from catalyst.exchange.bittrex.bittrex import Bittrex
from catalyst.finance.order import Order
from .base import BaseExchangeTestCase
from base import BaseExchangeTestCase
from logbook import Logger
from catalyst.exchange.exchange_utils import get_exchange_auth
+17 -5
View File
@@ -1,5 +1,5 @@
import pandas as pd
# from catalyst import get_calendar
from catalyst import get_calendar
from logbook import Logger
from catalyst.exchange.asset_finder_exchange import AssetFinderExchange
@@ -31,8 +31,7 @@ class ExchangeDataPortalTestCase:
base_currency='usd'
)
# open_calendar = get_calendar('OPEN')
open_calendar = None
open_calendar = get_calendar('OPEN')
asset_finder = AssetFinderExchange()
self.data_portal_live = DataPortalExchangeLive(
exchanges=dict(bitfinex=self.bitfinex, bittrex=self.bittrex),
@@ -42,14 +41,27 @@ class ExchangeDataPortalTestCase:
)
def test_get_history_window_live(self):
asset_finder = self.data_portal_live.asset_finder
assets = [
asset_finder.lookup_symbol('eth_btc', self.bitfinex),
asset_finder.lookup_symbol('eth_btc', self.bittrex)
]
now = pd.Timestamp.utcnow()
data = self.data_portal_live.get_history_window(
assets,
now,
10,
'1m',
'price')
pass
def test_get_spot_value_live(self):
asset_finder = self.data_portal_live.asset_finder
assets = [
asset_finder.lookup_symbol('eth_usd', self.bitfinex),
asset_finder.lookup_symbol('eth_usd', self.bittrex)
asset_finder.lookup_symbol('eth_btc', self.bitfinex),
asset_finder.lookup_symbol('eth_btc', self.bittrex)
]
now = pd.Timestamp.utcnow()
value = self.data_portal_live.get_spot_value(