mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-17 11:25:55 +08:00
BLD: paper trading adjustments
This commit is contained in:
@@ -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,
|
||||
# )
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
@@ -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
|
||||
)
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user