From cd1f5ca97b393f41743d33fb67127944ac8b053a Mon Sep 17 00:00:00 2001 From: Frederic Fortier Date: Thu, 28 Dec 2017 17:49:15 -0500 Subject: [PATCH] BLD: housekeeping, reorganizing files into smaller packages --- catalyst/__main__.py | 2 +- catalyst/assets/_assets.pyx | 3 +- catalyst/curate/poloniex.py | 14 +++++----- catalyst/data/loader.py | 5 ++-- catalyst/examples/arbitrage_with_interface.py | 2 +- catalyst/examples/buy_low_sell_high.py | 4 +-- catalyst/examples/buy_low_sell_high_live.py | 3 +- catalyst/examples/dual_moving_average.py | 4 +-- catalyst/examples/mean_reversion_simple.py | 3 +- catalyst/examples/simple_loop.py | 4 +-- catalyst/examples/simple_universe.py | 2 +- catalyst/examples/talib_simple.py | 2 +- catalyst/exchange/bitfinex/bitfinex.py | 4 +-- catalyst/exchange/bittrex/bittrex.py | 4 +-- catalyst/exchange/ccxt/ccxt_exchange.py | 6 ++-- catalyst/exchange/exchange.py | 8 +++--- catalyst/exchange/exchange_algorithm.py | 13 ++++----- catalyst/exchange/exchange_asset_finder.py | 6 ++-- catalyst/exchange/exchange_bundle.py | 14 +++++----- catalyst/exchange/exchange_data_portal.py | 2 +- catalyst/exchange/exchange_pricing_loader.py | 4 +-- catalyst/exchange/poloniex/poloniex.py | 5 ++-- catalyst/exchange/{ => utils}/bundle_utils.py | 2 +- .../exchange/{ => utils}/exchange_utils.py | 2 +- catalyst/exchange/{ => utils}/factory.py | 2 +- ...erialization.py => serialization_utils.py} | 0 catalyst/exchange/{ => utils}/stats_utils.py | 2 +- catalyst/exchange/{ => utils}/test_utils.py | 6 ++-- catalyst/support/issue_30.py | 28 +++++++++++++++++++ catalyst/utils/run_algo.py | 2 +- tests/exchange/test_bcolz.py | 13 ++++----- tests/exchange/test_bundle.py | 10 +++---- tests/exchange/test_ccxt.py | 4 +-- tests/exchange/test_data_portal.py | 4 +-- tests/exchange/test_server_bundle.py | 13 +++++---- tests/exchange/test_suite_bundle.py | 6 ++-- tests/exchange/test_suite_exchange.py | 4 +-- 37 files changed, 117 insertions(+), 95 deletions(-) rename catalyst/exchange/{ => utils}/bundle_utils.py (98%) rename catalyst/exchange/{ => utils}/exchange_utils.py (99%) rename catalyst/exchange/{ => utils}/factory.py (97%) rename catalyst/exchange/utils/{serialization.py => serialization_utils.py} (100%) rename catalyst/exchange/{ => utils}/stats_utils.py (99%) rename catalyst/exchange/{ => utils}/test_utils.py (93%) create mode 100644 catalyst/support/issue_30.py diff --git a/catalyst/__main__.py b/catalyst/__main__.py index db37f24d..82febb0b 100644 --- a/catalyst/__main__.py +++ b/catalyst/__main__.py @@ -9,7 +9,7 @@ from six import text_type from catalyst.data import bundles as bundles_module from catalyst.exchange.exchange_bundle import ExchangeBundle -from catalyst.exchange.exchange_utils import delete_algo_folder +from catalyst.exchange.utils.exchange_utils import delete_algo_folder from catalyst.utils.cli import Date, Timestamp from catalyst.utils.run_algo import _run, load_extensions diff --git a/catalyst/assets/_assets.pyx b/catalyst/assets/_assets.pyx index 07e7e813..f80fbf4a 100644 --- a/catalyst/assets/_assets.pyx +++ b/catalyst/assets/_assets.pyx @@ -17,6 +17,7 @@ """ Cythonized Asset object. """ + import hashlib cimport cython @@ -38,7 +39,7 @@ from numpy cimport int64_t import warnings cimport numpy as np -from catalyst.exchange.exchange_utils import get_sid +from catalyst.exchange.utils.exchange_utils import get_sid from catalyst.utils.calendars import get_calendar from catalyst.exchange.exchange_errors import InvalidSymbolError, SidHashError diff --git a/catalyst/curate/poloniex.py b/catalyst/curate/poloniex.py index c67e03bc..b58d0677 100644 --- a/catalyst/curate/poloniex.py +++ b/catalyst/curate/poloniex.py @@ -1,16 +1,16 @@ -import os -import time -import shutil -import json import csv +import json +import os +import shutil +import time from datetime import datetime +import logbook import pandas as pd import requests -import logbook - -from catalyst.exchange.exchange_utils import get_exchange_symbols_filename +from catalyst.exchange.utils.exchange_utils import \ + get_exchange_symbols_filename DT_START = int(time.mktime(datetime(2010, 1, 1, 0, 0).timetuple())) DT_END = pd.to_datetime('today').value // 10 ** 9 diff --git a/catalyst/data/loader.py b/catalyst/data/loader.py index b9227b3e..bfe6c701 100644 --- a/catalyst/data/loader.py +++ b/catalyst/data/loader.py @@ -22,6 +22,7 @@ from pandas_datareader.data import DataReader from six import iteritems from six.moves.urllib_error import HTTPError +from catalyst.constants import LOG_LEVEL from catalyst.utils.calendars import get_calendar from . import treasuries, treasuries_can from .benchmarks import get_benchmark_returns @@ -31,8 +32,6 @@ from ..utils.paths import ( data_root, ) -from catalyst.constants import LOG_LEVEL - logger = logbook.Logger('Loader', level=LOG_LEVEL) # Mapping from index symbol to appropriate bond data @@ -143,7 +142,7 @@ def load_crypto_market_data(trading_day=None, trading_days=None, if exchange is None: # This is exceptional, since placing the import at the module scope # breaks things and it's only needed here - from catalyst.exchange.factory import get_exchange + from catalyst.exchange.utils.factory import get_exchange exchange = get_exchange( exchange_name='poloniex', base_currency='usdt' ) diff --git a/catalyst/examples/arbitrage_with_interface.py b/catalyst/examples/arbitrage_with_interface.py index 67459e9a..ce2c7e13 100644 --- a/catalyst/examples/arbitrage_with_interface.py +++ b/catalyst/examples/arbitrage_with_interface.py @@ -6,7 +6,7 @@ from catalyst.api import ( symbol, get_open_orders ) -from catalyst.exchange.stats_utils import get_pretty_stats +from catalyst.exchange.utils.stats_utils import get_pretty_stats from catalyst.utils.run_algo import run_algorithm algo_namespace = 'arbitrage_eth_btc' diff --git a/catalyst/examples/buy_low_sell_high.py b/catalyst/examples/buy_low_sell_high.py index f4c53973..d481d2e2 100644 --- a/catalyst/examples/buy_low_sell_high.py +++ b/catalyst/examples/buy_low_sell_high.py @@ -10,6 +10,7 @@ needs to be installed. See https://mrjbq7.github.io/ta-lib/install.html for instructions on how to install the required dependencies. ''' +import pandas as pd import talib from logbook import Logger @@ -21,8 +22,7 @@ from catalyst.api import ( record, get_open_orders, ) -from catalyst.exchange.stats_utils import get_pretty_stats -import pandas as pd +from catalyst.exchange.utils.stats_utils import get_pretty_stats algo_namespace = 'buy_low_sell_high_xrp' log = Logger(algo_namespace) diff --git a/catalyst/examples/buy_low_sell_high_live.py b/catalyst/examples/buy_low_sell_high_live.py index 34b1e5f6..3b884063 100644 --- a/catalyst/examples/buy_low_sell_high_live.py +++ b/catalyst/examples/buy_low_sell_high_live.py @@ -1,7 +1,6 @@ import talib from logbook import Logger -import pandas as pd from catalyst.api import ( order, order_target_percent, @@ -9,7 +8,7 @@ from catalyst.api import ( record, get_open_orders, ) -from catalyst.exchange.stats_utils import get_pretty_stats +from catalyst.exchange.utils.stats_utils import get_pretty_stats from catalyst.utils.run_algo import run_algorithm algo_namespace = 'buy_the_dip_live' diff --git a/catalyst/examples/dual_moving_average.py b/catalyst/examples/dual_moving_average.py index f54d91b6..3a0a3f1f 100644 --- a/catalyst/examples/dual_moving_average.py +++ b/catalyst/examples/dual_moving_average.py @@ -1,12 +1,12 @@ +import matplotlib.pyplot as plt import numpy as np import pandas as pd from logbook import Logger -import matplotlib.pyplot as plt from catalyst import run_algorithm from catalyst.api import (record, symbol, order_target_percent, get_open_orders) -from catalyst.exchange.stats_utils import extract_transactions +from catalyst.exchange.utils.stats_utils import extract_transactions NAMESPACE = 'dual_moving_average' log = Logger(NAMESPACE) diff --git a/catalyst/examples/mean_reversion_simple.py b/catalyst/examples/mean_reversion_simple.py index b3fb7934..642d705e 100644 --- a/catalyst/examples/mean_reversion_simple.py +++ b/catalyst/examples/mean_reversion_simple.py @@ -12,8 +12,7 @@ from logbook import Logger from catalyst import run_algorithm from catalyst.api import symbol, record, order_target_percent, get_open_orders -from catalyst.exchange.stats_utils import extract_transactions - +from catalyst.exchange.utils.stats_utils import extract_transactions # We give a name to the algorithm which Catalyst will use to persist its state. # In this example, Catalyst will create the `.catalyst/data/live_algos` # directory. If we stop and start the algorithm, Catalyst will resume its diff --git a/catalyst/examples/simple_loop.py b/catalyst/examples/simple_loop.py index 5ad9d53b..1e639264 100644 --- a/catalyst/examples/simple_loop.py +++ b/catalyst/examples/simple_loop.py @@ -1,10 +1,10 @@ -import talib import pandas as pd +import talib from logbook import Logger, INFO from catalyst import run_algorithm from catalyst.api import symbol, record -from catalyst.exchange.stats_utils import get_pretty_stats, \ +from catalyst.exchange.utils.stats_utils import get_pretty_stats, \ extract_transactions log = Logger('simple_loop', level=INFO) diff --git a/catalyst/examples/simple_universe.py b/catalyst/examples/simple_universe.py index fec0c340..e781281f 100644 --- a/catalyst/examples/simple_universe.py +++ b/catalyst/examples/simple_universe.py @@ -35,8 +35,8 @@ import numpy as np import pandas as pd from catalyst import run_algorithm -from catalyst.exchange.exchange_utils import get_exchange_symbols from catalyst.api import (symbols, ) +from catalyst.exchange.utils.exchange_utils import get_exchange_symbols def initialize(context): diff --git a/catalyst/examples/talib_simple.py b/catalyst/examples/talib_simple.py index 5129dda9..cd9eee59 100644 --- a/catalyst/examples/talib_simple.py +++ b/catalyst/examples/talib_simple.py @@ -23,7 +23,7 @@ from catalyst.api import ( order_target_percent, symbol, ) -from catalyst.exchange.stats_utils import get_pretty_stats +from catalyst.exchange.utils.stats_utils import get_pretty_stats algo_namespace = 'talib_sample' log = Logger(algo_namespace) diff --git a/catalyst/exchange/bitfinex/bitfinex.py b/catalyst/exchange/bitfinex/bitfinex.py index 591e8486..91192493 100644 --- a/catalyst/exchange/bitfinex/bitfinex.py +++ b/catalyst/exchange/bitfinex/bitfinex.py @@ -23,11 +23,11 @@ from catalyst.exchange.exchange_errors import ( InvalidOrderStyle, OrderCancelError) from catalyst.exchange.exchange_execution import ExchangeLimitOrder, \ ExchangeStopLimitOrder, ExchangeStopOrder -from catalyst.exchange.exchange_utils import get_exchange_symbols_filename, \ +from catalyst.exchange.utils.exchange_utils import \ + get_exchange_symbols_filename, \ download_exchange_symbols, get_symbols_string from catalyst.finance.order import Order, ORDER_STATUS from catalyst.protocol import Account - # Trying to account for REST api instability # https://stackoverflow.com/questions/15431044/can-i-set-max-retries-for-requests-request from catalyst.utils.deprecate import deprecated diff --git a/catalyst/exchange/bittrex/bittrex.py b/catalyst/exchange/bittrex/bittrex.py index 3057d501..fae15430 100644 --- a/catalyst/exchange/bittrex/bittrex.py +++ b/catalyst/exchange/bittrex/bittrex.py @@ -13,11 +13,11 @@ from catalyst.exchange.exchange_bundle import ExchangeBundle from catalyst.exchange.exchange_errors import InvalidHistoryFrequencyError, \ ExchangeRequestError, InvalidOrderStyle, OrderNotFound, OrderCancelError, \ CreateOrderError -from catalyst.exchange.exchange_utils import get_exchange_symbols_filename, \ +from catalyst.exchange.utils.exchange_utils import \ + get_exchange_symbols_filename, \ download_exchange_symbols, get_symbols_string from catalyst.finance.execution import LimitOrder, StopLimitOrder from catalyst.finance.order import Order, ORDER_STATUS - # TODO: consider using this: https://github.com/mondeja/bittrex_v2 from catalyst.utils.deprecate import deprecated diff --git a/catalyst/exchange/ccxt/ccxt_exchange.py b/catalyst/exchange/ccxt/ccxt_exchange.py index 0a4b8950..acd1e114 100644 --- a/catalyst/exchange/ccxt/ccxt_exchange.py +++ b/catalyst/exchange/ccxt/ccxt_exchange.py @@ -1,17 +1,17 @@ import json +import os import re from collections import defaultdict import ccxt -import os import pandas as pd import six +from catalyst.assets._assets import TradingPair from ccxt import ExchangeNotAvailable, InvalidOrder from logbook import Logger from six import string_types from catalyst.algorithm import MarketOrder -from catalyst.assets._assets import TradingPair from catalyst.constants import LOG_LEVEL from catalyst.exchange.exchange import Exchange from catalyst.exchange.exchange_bundle import ExchangeBundle @@ -19,7 +19,7 @@ from catalyst.exchange.exchange_errors import InvalidHistoryFrequencyError, \ ExchangeSymbolsNotFound, ExchangeRequestError, InvalidOrderStyle, \ ExchangeNotFoundError, CreateOrderError, InvalidHistoryTimeframeError from catalyst.exchange.exchange_execution import ExchangeLimitOrder -from catalyst.exchange.exchange_utils import mixin_market_params, \ +from catalyst.exchange.utils.exchange_utils import mixin_market_params, \ from_ms_timestamp, get_epoch, get_exchange_folder, get_catalyst_symbol, \ get_exchange_auth from catalyst.finance.order import Order, ORDER_STATUS diff --git a/catalyst/exchange/exchange.py b/catalyst/exchange/exchange.py index bb3c5768..b6b24d20 100644 --- a/catalyst/exchange/exchange.py +++ b/catalyst/exchange/exchange.py @@ -9,15 +9,15 @@ from logbook import Logger from catalyst.constants import LOG_LEVEL from catalyst.data.data_portal import BASE_FIELDS -from catalyst.exchange.bundle_utils import get_start_dt, \ - get_delta, get_periods, get_periods_range from catalyst.exchange.exchange_bundle import ExchangeBundle from catalyst.exchange.exchange_errors import MismatchingBaseCurrencies, \ SymbolNotFoundOnExchange, \ PricingDataNotLoadedError, \ NoDataAvailableOnExchange, NoValueForField, LastCandleTooEarlyError, \ - TickerNotFoundError, BalanceNotFoundError, NotEnoughCashError -from catalyst.exchange.exchange_utils import get_exchange_symbols, \ + TickerNotFoundError, NotEnoughCashError +from catalyst.exchange.utils.bundle_utils import get_start_dt, \ + get_delta, get_periods, get_periods_range +from catalyst.exchange.utils.exchange_utils import get_exchange_symbols, \ get_frequency, resample_history_df, has_bundle log = Logger('Exchange', level=LOG_LEVEL) diff --git a/catalyst/exchange/exchange_algorithm.py b/catalyst/exchange/exchange_algorithm.py index 72a17b36..fe1f3679 100644 --- a/catalyst/exchange/exchange_algorithm.py +++ b/catalyst/exchange/exchange_algorithm.py @@ -31,28 +31,25 @@ from catalyst.exchange.exchange_errors import ( ExchangePortfolioDataError, OrderTypeNotSupported) from catalyst.exchange.exchange_execution import ExchangeLimitOrder -from catalyst.exchange.exchange_utils import ( +from catalyst.exchange.live_graph_clock import LiveGraphClock +from catalyst.exchange.simple_clock import SimpleClock +from catalyst.exchange.utils.exchange_utils import ( save_algo_object, get_algo_object, get_algo_folder, get_algo_df, save_algo_df, group_assets_by_exchange, ) -from catalyst.exchange.live_graph_clock import LiveGraphClock -from catalyst.exchange.simple_clock import SimpleClock -from catalyst.exchange.stats_utils import get_pretty_stats, stats_to_s3, \ +from catalyst.exchange.utils.stats_utils import get_pretty_stats, stats_to_s3, \ stats_to_algo_folder -from catalyst.exchange.utils.serialization import portfolio_to_dict from catalyst.finance.execution import MarketOrder -from catalyst.finance.performance import PerformanceTracker, Position +from catalyst.finance.performance import PerformanceTracker from catalyst.finance.performance.period import calc_period_stats -from catalyst.finance.performance.position import positiondict from catalyst.gens.tradesimulation import AlgorithmSimulator from catalyst.utils.api_support import api_method from catalyst.utils.input_validation import error_keywords, ensure_upper_case from catalyst.utils.math_utils import round_nearest from catalyst.utils.preprocess import preprocess -from catalyst.protocol import Portfolio log = logbook.Logger('exchange_algorithm', level=LOG_LEVEL) diff --git a/catalyst/exchange/exchange_asset_finder.py b/catalyst/exchange/exchange_asset_finder.py index 7ab00ef4..0a887986 100644 --- a/catalyst/exchange/exchange_asset_finder.py +++ b/catalyst/exchange/exchange_asset_finder.py @@ -1,10 +1,8 @@ +import pandas as pd from logbook import Logger from catalyst.constants import LOG_LEVEL -from catalyst.errors import SidsNotFound -from catalyst.exchange.factory import find_exchanges - -import pandas as pd +from catalyst.exchange.utils.factory import find_exchanges log = Logger('ExchangeAssetFinder', level=LOG_LEVEL) diff --git a/catalyst/exchange/exchange_bundle.py b/catalyst/exchange/exchange_bundle.py index fae2a066..b46bf9df 100644 --- a/catalyst/exchange/exchange_bundle.py +++ b/catalyst/exchange/exchange_bundle.py @@ -18,17 +18,17 @@ from catalyst.constants import DATE_TIME_FORMAT, AUTO_INGEST from catalyst.constants import LOG_LEVEL from catalyst.data.minute_bars import BcolzMinuteOverlappingData, \ BcolzMinuteBarMetadata -from catalyst.exchange.bundle_utils import range_in_bundle, \ - get_bcolz_chunk, get_month_start_end, \ - get_year_start_end, get_df_from_arrays, get_start_dt, get_period_label, \ - get_delta, get_assets from catalyst.exchange.exchange_bcolz import BcolzExchangeBarReader, \ BcolzExchangeBarWriter from catalyst.exchange.exchange_errors import EmptyValuesInBundleError, \ TempBundleNotFoundError, \ NoDataAvailableOnExchange, \ PricingDataNotLoadedError, DataCorruptionError, PricingDataValueError -from catalyst.exchange.exchange_utils import get_exchange_folder, \ +from catalyst.exchange.utils.bundle_utils import range_in_bundle, \ + get_bcolz_chunk, get_month_start_end, \ + get_year_start_end, get_df_from_arrays, get_start_dt, get_period_label, \ + get_delta, get_assets +from catalyst.exchange.utils.exchange_utils import get_exchange_folder, \ save_exchange_symbols, mixin_market_params, get_catalyst_symbol from catalyst.utils.cli import maybe_show_progress from catalyst.utils.paths import ensure_directory @@ -668,7 +668,7 @@ class ExchangeBundle: if self.exchange is None: # Avoid circular dependencies - from catalyst.exchange.factory import get_exchange + from catalyst.exchange.utils.factory import get_exchange self.exchange = get_exchange(self.exchange_name) problems = [] @@ -805,7 +805,7 @@ class ExchangeBundle: else: if self.exchange is None: # Avoid circular dependencies - from catalyst.exchange.factory import get_exchange + from catalyst.exchange.utils.factory import get_exchange self.exchange = get_exchange(self.exchange_name) assets = get_assets( diff --git a/catalyst/exchange/exchange_data_portal.py b/catalyst/exchange/exchange_data_portal.py index 0298a786..e9db33ce 100644 --- a/catalyst/exchange/exchange_data_portal.py +++ b/catalyst/exchange/exchange_data_portal.py @@ -13,7 +13,7 @@ from catalyst.exchange.exchange_errors import ( ExchangeRequestError, ExchangeBarDataError, PricingDataNotLoadedError) -from catalyst.exchange.exchange_utils import get_frequency, \ +from catalyst.exchange.utils.exchange_utils import get_frequency, \ resample_history_df, group_assets_by_exchange log = Logger('DataPortalExchange', level=LOG_LEVEL) diff --git a/catalyst/exchange/exchange_pricing_loader.py b/catalyst/exchange/exchange_pricing_loader.py index ed89c3c4..38663962 100644 --- a/catalyst/exchange/exchange_pricing_loader.py +++ b/catalyst/exchange/exchange_pricing_loader.py @@ -19,9 +19,9 @@ from numpy import ( from catalyst.constants import LOG_LEVEL from catalyst.data.us_equity_pricing import BcolzDailyBarReader -from catalyst.exchange.factory import get_exchange -from catalyst.lib.adjusted_array import AdjustedArray from catalyst.errors import NoFurtherDataError +from catalyst.exchange.utils.factory import get_exchange +from catalyst.lib.adjusted_array import AdjustedArray from catalyst.pipeline.data import DataSet, Column from catalyst.pipeline.loaders.base import PipelineLoader from catalyst.utils.calendars import get_calendar diff --git a/catalyst/exchange/poloniex/poloniex.py b/catalyst/exchange/poloniex/poloniex.py index 49ccbd40..6f26b905 100644 --- a/catalyst/exchange/poloniex/poloniex.py +++ b/catalyst/exchange/poloniex/poloniex.py @@ -22,9 +22,10 @@ from catalyst.exchange.exchange_errors import ( OrphanOrderReverseError) from catalyst.exchange.exchange_execution import ExchangeLimitOrder, \ ExchangeStopLimitOrder -from catalyst.exchange.exchange_utils import get_exchange_symbols_filename, \ - download_exchange_symbols, get_symbols_string from catalyst.exchange.poloniex.poloniex_api import Poloniex_api +from catalyst.exchange.utils.exchange_utils import \ + get_exchange_symbols_filename, \ + download_exchange_symbols, get_symbols_string from catalyst.finance.order import Order, ORDER_STATUS from catalyst.finance.transaction import Transaction from catalyst.protocol import Account diff --git a/catalyst/exchange/bundle_utils.py b/catalyst/exchange/utils/bundle_utils.py similarity index 98% rename from catalyst/exchange/bundle_utils.py rename to catalyst/exchange/utils/bundle_utils.py index 0d758c7d..6107bf79 100644 --- a/catalyst/exchange/bundle_utils.py +++ b/catalyst/exchange/utils/bundle_utils.py @@ -8,7 +8,7 @@ import pandas as pd import pytz from catalyst.data.bundles.core import download_without_progress -from catalyst.exchange.exchange_utils import get_exchange_bundles_folder +from catalyst.exchange.utils.exchange_utils import get_exchange_bundles_folder EXCHANGE_NAMES = ['bitfinex', 'bittrex', 'poloniex'] API_URL = 'http://data.enigma.co/api/v1' diff --git a/catalyst/exchange/exchange_utils.py b/catalyst/exchange/utils/exchange_utils.py similarity index 99% rename from catalyst/exchange/exchange_utils.py rename to catalyst/exchange/utils/exchange_utils.py index 81c302f6..ab16f71d 100644 --- a/catalyst/exchange/exchange_utils.py +++ b/catalyst/exchange/utils/exchange_utils.py @@ -14,7 +14,7 @@ from six.moves.urllib import request from catalyst.constants import DATE_FORMAT, SYMBOLS_URL from catalyst.exchange.exchange_errors import ExchangeSymbolsNotFound, \ InvalidHistoryFrequencyError, InvalidHistoryFrequencyAlias -from catalyst.exchange.utils.serialization import ExchangeJSONEncoder, \ +from catalyst.exchange.utils.serialization_utils import ExchangeJSONEncoder, \ ExchangeJSONDecoder from catalyst.utils.paths import data_root, ensure_directory, \ last_modified_time diff --git a/catalyst/exchange/factory.py b/catalyst/exchange/utils/factory.py similarity index 97% rename from catalyst/exchange/factory.py rename to catalyst/exchange/utils/factory.py index 8f8ecf34..c5503582 100644 --- a/catalyst/exchange/factory.py +++ b/catalyst/exchange/utils/factory.py @@ -6,7 +6,7 @@ from catalyst.constants import LOG_LEVEL from catalyst.exchange.ccxt.ccxt_exchange import CCXT from catalyst.exchange.exchange import Exchange from catalyst.exchange.exchange_errors import ExchangeAuthEmpty -from catalyst.exchange.exchange_utils import get_exchange_auth, \ +from catalyst.exchange.utils.exchange_utils import get_exchange_auth, \ get_exchange_folder, is_blacklist log = Logger('factory', level=LOG_LEVEL) diff --git a/catalyst/exchange/utils/serialization.py b/catalyst/exchange/utils/serialization_utils.py similarity index 100% rename from catalyst/exchange/utils/serialization.py rename to catalyst/exchange/utils/serialization_utils.py diff --git a/catalyst/exchange/stats_utils.py b/catalyst/exchange/utils/stats_utils.py similarity index 99% rename from catalyst/exchange/stats_utils.py rename to catalyst/exchange/utils/stats_utils.py index a6b0e33b..fd68964b 100644 --- a/catalyst/exchange/stats_utils.py +++ b/catalyst/exchange/utils/stats_utils.py @@ -9,7 +9,7 @@ import numpy as np import pandas as pd from catalyst.assets._assets import TradingPair -from catalyst.exchange.exchange_utils import get_algo_folder +from catalyst.exchange.utils.exchange_utils import get_algo_folder from catalyst.utils.paths import data_root, ensure_directory s3_conn = [] diff --git a/catalyst/exchange/test_utils.py b/catalyst/exchange/utils/test_utils.py similarity index 93% rename from catalyst/exchange/test_utils.py rename to catalyst/exchange/utils/test_utils.py index 331d0807..caae1e23 100644 --- a/catalyst/exchange/test_utils.py +++ b/catalyst/exchange/utils/test_utils.py @@ -1,11 +1,11 @@ import os import random - import tempfile + from catalyst.assets._assets import TradingPair -from catalyst.exchange.exchange_utils import get_exchange_folder -from catalyst.exchange.factory import find_exchanges +from catalyst.exchange.utils.exchange_utils import get_exchange_folder +from catalyst.exchange.utils.factory import find_exchanges from catalyst.utils.paths import ensure_directory diff --git a/catalyst/support/issue_30.py b/catalyst/support/issue_30.py new file mode 100644 index 00000000..89ceb92a --- /dev/null +++ b/catalyst/support/issue_30.py @@ -0,0 +1,28 @@ +from catalyst.api import symbol +from catalyst.utils.run_algo import run_algorithm + + +def initialize(context): + context.asset = symbol('bcc_usdt') + + +def handle_data(context, data): + data.history(context.asset, ['close'], bar_count=100, frequency='5T') + + +def analyze(context=None, results=None): + pass + + +if __name__ == '__main__': + run_algorithm( + capital_base=100, + initialize=initialize, + handle_data=handle_data, + analyze=analyze, + exchange_name='bittrex', + algo_namespace="bittrex_is_broken", + base_currency='usdt', + data_frequency='minute', + simulate_orders=True, + live=True) diff --git a/catalyst/utils/run_algo.py b/catalyst/utils/run_algo.py index 4a5ba74e..7f1068c7 100644 --- a/catalyst/utils/run_algo.py +++ b/catalyst/utils/run_algo.py @@ -14,7 +14,7 @@ from catalyst.data.bundles import load from catalyst.data.data_portal import DataPortal from catalyst.exchange.exchange_pricing_loader import ExchangePricingLoader, \ TradingPairPricing -from catalyst.exchange.factory import get_exchange +from catalyst.exchange.utils.factory import get_exchange try: from pygments import highlight diff --git a/tests/exchange/test_bcolz.py b/tests/exchange/test_bcolz.py index a842bee7..796a5da3 100644 --- a/tests/exchange/test_bcolz.py +++ b/tests/exchange/test_bcolz.py @@ -1,15 +1,14 @@ -import shutil import random +import shutil import tempfile -import pandas as pd -from catalyst.exchange.exchange_bundle import ExchangeBundle +import pandas as pd +from nose.tools import assert_equals + from catalyst.exchange.exchange_bcolz import BcolzExchangeBarWriter, \ BcolzExchangeBarReader - -from catalyst.exchange.bundle_utils import get_df_from_arrays - -from nose.tools import assert_equals +from catalyst.exchange.exchange_bundle import ExchangeBundle +from catalyst.exchange.utils.bundle_utils import get_df_from_arrays class TestBcolzWriter(object): diff --git a/tests/exchange/test_bundle.py b/tests/exchange/test_bundle.py index a0d23319..3864d531 100644 --- a/tests/exchange/test_bundle.py +++ b/tests/exchange/test_bundle.py @@ -5,15 +5,15 @@ from logging import getLogger import pandas as pd -from catalyst.exchange.bundle_utils import get_bcolz_chunk, \ - get_start_dt, get_df_from_arrays from catalyst.exchange.exchange_bcolz import BcolzExchangeBarReader, \ BcolzExchangeBarWriter from catalyst.exchange.exchange_bundle import ExchangeBundle, \ BUNDLE_NAME_TEMPLATE -from catalyst.exchange.exchange_utils import get_exchange_folder -from catalyst.exchange.factory import get_exchange -from catalyst.exchange.stats_utils import df_to_string +from catalyst.exchange.utils.bundle_utils import get_bcolz_chunk, \ + get_start_dt, get_df_from_arrays +from catalyst.exchange.utils.exchange_utils import get_exchange_folder +from catalyst.exchange.utils.factory import get_exchange +from catalyst.exchange.utils.stats_utils import df_to_string from catalyst.utils.paths import ensure_directory log = getLogger('test_exchange_bundle') diff --git a/tests/exchange/test_ccxt.py b/tests/exchange/test_ccxt.py index 3d9d37f9..b60e7d96 100644 --- a/tests/exchange/test_ccxt.py +++ b/tests/exchange/test_ccxt.py @@ -1,10 +1,10 @@ import pandas as pd from logbook import Logger -from base import BaseExchangeTestCase +from base import BaseExchangeTestCase from catalyst.exchange.ccxt.ccxt_exchange import CCXT +from catalyst.exchange.utils.exchange_utils import get_exchange_auth from catalyst.finance.order import Order -from catalyst.exchange.exchange_utils import get_exchange_auth log = Logger('test_ccxt') diff --git a/tests/exchange/test_data_portal.py b/tests/exchange/test_data_portal.py index 7febfcd5..4a9beba8 100644 --- a/tests/exchange/test_data_portal.py +++ b/tests/exchange/test_data_portal.py @@ -7,8 +7,8 @@ from catalyst.exchange.exchange_data_portal import ( DataPortalExchangeBacktest, DataPortalExchangeLive ) -from catalyst.exchange.exchange_utils import get_common_assets -from catalyst.exchange.factory import get_exchanges +from catalyst.exchange.utils.exchange_utils import get_common_assets +from catalyst.exchange.utils.factory import get_exchanges from test_utils import rnd_history_date_days, rnd_bar_count log = Logger('test_bitfinex') diff --git a/tests/exchange/test_server_bundle.py b/tests/exchange/test_server_bundle.py index ea90c0f2..eb4f4703 100644 --- a/tests/exchange/test_server_bundle.py +++ b/tests/exchange/test_server_bundle.py @@ -1,17 +1,18 @@ -import os import importlib +import os -import pandas as pd import matplotlib import matplotlib.pyplot as plt -from matplotlib.finance import candlestick2_ohlc # from matplotlib.finance import volume_overlay import matplotlib.ticker as ticker +import pandas as pd +from matplotlib.finance import candlestick2_ohlc -from catalyst.exchange.exchange_bundle import ExchangeBundle from catalyst.exchange.exchange_bcolz import BcolzExchangeBarReader -from catalyst.exchange.bundle_utils import get_df_from_arrays, get_bcolz_chunk -from catalyst.exchange.factory import get_exchange +from catalyst.exchange.exchange_bundle import ExchangeBundle +from catalyst.exchange.utils.bundle_utils import get_df_from_arrays, \ + get_bcolz_chunk +from catalyst.exchange.utils.factory import get_exchange EXCHANGE_NAMES = ['bitfinex', 'bittrex', 'poloniex'] exchanges = dict((e, getattr(importlib.import_module( diff --git a/tests/exchange/test_suite_bundle.py b/tests/exchange/test_suite_bundle.py index 0a3a8796..07e94e4f 100644 --- a/tests/exchange/test_suite_bundle.py +++ b/tests/exchange/test_suite_bundle.py @@ -7,9 +7,9 @@ from pandas.util.testing import assert_frame_equal from catalyst import get_calendar from catalyst.exchange.exchange_asset_finder import ExchangeAssetFinder from catalyst.exchange.exchange_data_portal import DataPortalExchangeBacktest -from catalyst.exchange.exchange_utils import get_candles_df -from catalyst.exchange.factory import get_exchange -from catalyst.exchange.test_utils import output_df, \ +from catalyst.exchange.utils.exchange_utils import get_candles_df +from catalyst.exchange.utils.factory import get_exchange +from catalyst.exchange.utils.test_utils import output_df, \ select_random_assets log = Logger('TestSuiteExchange') diff --git a/tests/exchange/test_suite_exchange.py b/tests/exchange/test_suite_exchange.py index 239ee939..cf92845e 100644 --- a/tests/exchange/test_suite_exchange.py +++ b/tests/exchange/test_suite_exchange.py @@ -8,8 +8,8 @@ import pandas as pd from catalyst.exchange.exchange_errors import ExchangeRequestError from catalyst.exchange.exchange_execution import ExchangeLimitOrder -from catalyst.exchange.exchange_utils import get_exchange_folder -from catalyst.exchange.test_utils import select_random_exchanges, \ +from catalyst.exchange.utils.exchange_utils import get_exchange_folder +from catalyst.exchange.utils.test_utils import select_random_exchanges, \ handle_exchange_error, select_random_assets log = Logger('TestSuiteExchange')