BLD: paper trading adjustments

This commit is contained in:
fredfortier
2017-12-01 00:06:11 -05:00
parent 207bce6216
commit 4db8131397
6 changed files with 51 additions and 51 deletions
+17 -17
View File
@@ -107,25 +107,25 @@ def analyze(context, perf):
pass
# run_algorithm(
# capital_base=250,
# start=pd.to_datetime('2017-11-1 0:00', utc=True),
# end=pd.to_datetime('2017-11-10 23:59', utc=True),
# data_frequency='daily',
# initialize=initialize,
# handle_data=handle_data,
# analyze=analyze,
# exchange_name='bitfinex',
# algo_namespace='simple_loop',
# base_currency='usd'
# )
run_algorithm(
capital_base=250,
start=pd.to_datetime('2017-11-1 0:00', utc=True),
end=pd.to_datetime('2017-11-10 23:59', utc=True),
data_frequency='daily',
initialize=initialize,
handle_data=handle_data,
analyze=None,
exchange_name='binance',
live=True,
analyze=analyze,
exchange_name='bitfinex',
algo_namespace='simple_loop',
base_currency='eth',
live_graph=False,
base_currency='usd'
)
# run_algorithm(
# initialize=initialize,
# handle_data=handle_data,
# analyze=None,
# exchange_name='binance',
# live=True,
# algo_namespace='simple_loop',
# base_currency='eth',
# live_graph=False,
# )
+10 -5
View File
@@ -28,6 +28,8 @@ SUPPORTED_EXCHANGES = dict(
bitfinex=ccxt.bitfinex,
bittrex=ccxt.bittrex,
poloniex=ccxt.poloniex,
bitmex=ccxt.bitmex,
gdax=ccxt.gdax,
)
@@ -88,12 +90,15 @@ class CCXT(Exchange):
return '{}/{}'.format(parts[0].upper(), parts[1].upper())
def get_catalyst_symbol(self, market_or_symbol):
symbol = market_or_symbol if isinstance(
market_or_symbol, string_types
) else market_or_symbol['symbol']
if isinstance(market_or_symbol, string_types):
parts = market_or_symbol.split('/')
return '{}_{}'.format(parts[0].lower(), parts[1].lower())
parts = symbol.split('/')
return '{}_{}'.format(parts[0].lower(), parts[1].lower())
else:
return '{}_{}'.format(
market_or_symbol['base'].lower(),
market_or_symbol['quote'].lower(),
)
def get_timeframe(self, freq):
freq_match = re.match(r'([0-9].*)?(m|M|d|D|h|H|T)', freq, re.M | re.I)
+1
View File
@@ -289,6 +289,7 @@ class ExchangeTradingAlgorithmLive(ExchangeTradingAlgorithmBase):
def __init__(self, *args, **kwargs):
self.algo_namespace = kwargs.pop('algo_namespace', None)
self.live_graph = kwargs.pop('live_graph', None)
self.simulate_orders = kwargs.pop('simulate_orders', None)
self._clock = None
self.frame_stats = deque(maxlen=60)
+8 -5
View File
@@ -594,12 +594,15 @@ def mixin_market_params(exchange_name, params, market):
params['maker'] = 0.001
params['taker'] = 0.002
else:
if 'maker' in market:
params['maker'] = market['maker']
elif 'maker' in market and 'taker' in market \
and market['maker'] is not None and market['taker'] is not None:
params['maker'] = market['maker']
params['taker'] = market['taker']
if 'taker' in market:
params['taker'] = market['taker']
else:
# TODO: default commission, make configurable
params['maker'] = 0.0015
params['taker'] = 0.0025
info = market['info'] if 'info' in market else None
if info:
+10 -11
View File
@@ -11,10 +11,7 @@ import pandas as pd
from catalyst.data.bundles import load
from catalyst.data.data_portal import DataPortal
from catalyst.exchange.bittrex.bittrex import Bittrex
from catalyst.exchange.bitfinex.bitfinex import Bitfinex
from catalyst.exchange.factory import get_exchange
from catalyst.exchange.poloniex.poloniex import Poloniex
try:
from pygments import highlight
@@ -40,11 +37,9 @@ from catalyst.exchange.exchange_data_portal import DataPortalExchangeLive, \
from catalyst.exchange.asset_finder_exchange import AssetFinderExchange
from catalyst.exchange.exchange_portfolio import ExchangePortfolio
from catalyst.exchange.exchange_errors import (
ExchangeRequestError, ExchangeAuthEmpty,
ExchangeRequestErrorTooManyAttempts,
BaseCurrencyNotFoundError, ExchangeNotFoundError)
from catalyst.exchange.exchange_utils import get_exchange_auth, \
get_algo_object, get_exchange_folder
ExchangeRequestError, ExchangeRequestErrorTooManyAttempts,
BaseCurrencyNotFoundError)
from catalyst.exchange.exchange_utils import get_algo_object
from logbook import Logger
from catalyst.constants import LOG_LEVEL
@@ -95,7 +90,8 @@ def _run(handle_data,
exchange,
algo_namespace,
base_currency,
live_graph):
live_graph,
simulate_orders):
"""Run a backtest for the given algorithm.
This is shared between the cli and :func:`catalyst.run_algo`.
@@ -282,7 +278,8 @@ def _run(handle_data,
ExchangeTradingAlgorithmLive,
exchanges=exchanges,
algo_namespace=algo_namespace,
live_graph=live_graph
live_graph=live_graph,
simulate_orders=simulate_orders
)
elif exchanges:
# Removed the existing Poloniex fork to keep things simple
@@ -444,6 +441,7 @@ def run_algorithm(initialize,
base_currency=None,
algo_namespace=None,
live_graph=False,
simulate_orders=True,
output=os.devnull):
"""Run a trading algorithm.
@@ -565,5 +563,6 @@ def run_algorithm(initialize,
exchange=exchange_name,
algo_namespace=algo_namespace,
base_currency=base_currency,
live_graph=live_graph
live_graph=live_graph,
simulate_orders=simulate_orders
)
+5 -13
View File
@@ -15,7 +15,7 @@ log = Logger('test_ccxt')
class TestCCXT(BaseExchangeTestCase):
@classmethod
def setup(self):
exchange_name = 'binance'
exchange_name = 'gdax'
auth = get_exchange_auth(exchange_name)
self.exchange = CCXT(
exchange_name=exchange_name,
@@ -64,25 +64,17 @@ class TestCCXT(BaseExchangeTestCase):
start_dt=pd.to_datetime('2017-01-01', utc=True)
)
df = pd.DataFrame(candles)
df.set_index('last_traded', drop=True, inplace=True)
folder = os.path.join(
tempfile.gettempdir(), 'catalyst', self.exchange.name, 'eth_btc'
)
ensure_directory(folder)
path = os.path.join(folder, 'output.csv')
df.to_csv(path)
for asset in candles:
df = pd.DataFrame(candles[asset])
df.set_index('last_traded', drop=True, inplace=True)
pass
def test_tickers(self):
log.info('retrieving tickers')
tickers = self.exchange.tickers([
self.exchange.get_asset('eth_btc'),
self.exchange.get_asset('etc_btc')
])
assert len(tickers) == 2
assert len(tickers) == 1
pass
def test_get_balances(self):