mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-27 20:20:55 +08:00
exchange unit tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import shutil
|
||||
import random
|
||||
import tempfile
|
||||
import pandas as pd
|
||||
|
||||
@@ -6,6 +7,8 @@ from catalyst.exchange.exchange_bundle import ExchangeBundle
|
||||
from catalyst.exchange.exchange_bcolz import BcolzExchangeBarWriter, \
|
||||
BcolzExchangeBarReader
|
||||
|
||||
from catalyst.exchange.bundle_utils import get_df_from_arrays
|
||||
|
||||
from nose.tools import assert_equals
|
||||
|
||||
|
||||
@@ -24,7 +27,7 @@ class TestBcolzWriter(object):
|
||||
bundle = ExchangeBundle(exchange_name)
|
||||
index = bundle.get_calendar_periods_range(start, end, freq)
|
||||
df = pd.DataFrame(index=index, columns=self.columns)
|
||||
df.fillna(1, inplace=True)
|
||||
df.fillna(random.random(), inplace=True)
|
||||
return df
|
||||
|
||||
def test_bcolz_write_daily_past(self):
|
||||
@@ -107,14 +110,18 @@ class TestBcolzWriter(object):
|
||||
def bcolz_exchange_daily_write_read(self, exchange_name):
|
||||
start = pd.to_datetime('2017-10-01 00:00')
|
||||
end = pd.to_datetime('today')
|
||||
freq = 'minute'
|
||||
freq = 'daily'
|
||||
|
||||
bundle = ExchangeBundle(exchange_name)
|
||||
|
||||
df = self.generate_df(exchange_name, freq, start, end)
|
||||
|
||||
print df.index[0],df.index[-1]
|
||||
|
||||
writer = BcolzExchangeBarWriter(
|
||||
rootdir=self.root_dir,
|
||||
start_session=start,
|
||||
end_session=end,
|
||||
start_session=df.index[0],
|
||||
end_session=df.index[-1],
|
||||
data_frequency=freq,
|
||||
write_metadata=True)
|
||||
|
||||
@@ -125,9 +132,15 @@ class TestBcolzWriter(object):
|
||||
reader = BcolzExchangeBarReader(rootdir=self.root_dir,
|
||||
data_frequency=freq)
|
||||
|
||||
dx = reader.load_raw_arrays(self.columns, start, end, [1, ])
|
||||
arrays = reader.load_raw_arrays(self.columns, start, end, [1, ])
|
||||
|
||||
# assert_equals(dx, df)
|
||||
periods = bundle.get_calendar_periods_range(
|
||||
start, end, freq
|
||||
)
|
||||
|
||||
dx = get_df_from_arrays(arrays, periods)
|
||||
|
||||
assert_equals(df.equals(df), True)
|
||||
pass
|
||||
|
||||
def test_bcolz_bitfinex_daily_write_read(self):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import hashlib
|
||||
from logging import Logger
|
||||
from logging import getLogger
|
||||
|
||||
import pandas as pd
|
||||
|
||||
@@ -14,7 +14,7 @@ from catalyst.exchange.exchange_utils import get_exchange_folder
|
||||
from catalyst.exchange.init_utils import get_exchange
|
||||
from catalyst.utils.paths import ensure_directory
|
||||
|
||||
log = Logger('test_exchange_bundle')
|
||||
log = getLogger('test_exchange_bundle')
|
||||
|
||||
|
||||
class TestExchangeBundle:
|
||||
@@ -298,7 +298,7 @@ class TestExchangeBundle:
|
||||
data_frequency = 'minute'
|
||||
|
||||
exchange = get_exchange(exchange_name)
|
||||
asset = exchange.get_asset('neo_btc')
|
||||
asset = exchange.get_asset('neos_btc')
|
||||
|
||||
path = get_bcolz_chunk(
|
||||
exchange_name=exchange_name,
|
||||
|
||||
@@ -21,7 +21,7 @@ class TestPoloniexTestCase(BaseExchangeTestCase):
|
||||
|
||||
def test_order(self):
|
||||
log.info('creating order')
|
||||
asset = self.exchange.get_asset('neo_btc')
|
||||
asset = self.exchange.get_asset('neos_btc')
|
||||
order_id = self.exchange.order(
|
||||
asset=asset,
|
||||
limit_price=0.0005,
|
||||
@@ -33,7 +33,7 @@ class TestPoloniexTestCase(BaseExchangeTestCase):
|
||||
|
||||
def test_open_orders(self):
|
||||
log.info('retrieving open orders')
|
||||
asset = self.exchange.get_asset('neo_btc')
|
||||
asset = self.exchange.get_asset('neos_btc')
|
||||
orders = self.exchange.get_open_orders(asset)
|
||||
pass
|
||||
|
||||
@@ -53,13 +53,13 @@ class TestPoloniexTestCase(BaseExchangeTestCase):
|
||||
log.info('retrieving candles')
|
||||
ohlcv_neo = self.exchange.get_candles(
|
||||
data_frequency='5m',
|
||||
assets=self.exchange.get_asset('neo_btc')
|
||||
assets=self.exchange.get_asset('neos_btc')
|
||||
)
|
||||
ohlcv_neo_ubq = self.exchange.get_candles(
|
||||
data_frequency='5m',
|
||||
assets=[
|
||||
self.exchange.get_asset('neo_btc'),
|
||||
self.exchange.get_asset('ubq_btc')
|
||||
self.exchange.get_asset('neos_btc'),
|
||||
self.exchange.get_asset('via_btc')
|
||||
],
|
||||
bar_count=14
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user