adding min_trade_size in TradingPair

This commit is contained in:
Victor Grau Serrat
2017-09-26 13:32:23 -06:00
parent 2c2c861a8f
commit 87ecf6114d
3 changed files with 22 additions and 9 deletions
+12 -5
View File
@@ -408,7 +408,8 @@ cdef class TradingPair(Asset):
'exchange_full', 'exchange_full',
'leverage', 'leverage',
'market_currency', 'market_currency',
'base_currency' 'base_currency',
'min_trade_size',
}) })
def __init__(self, def __init__(self,
object symbol, object symbol,
@@ -420,7 +421,8 @@ cdef class TradingPair(Asset):
object end_date=None, object end_date=None,
object first_traded=None, object first_traded=None,
object auto_close_date=None, object auto_close_date=None,
object exchange_full=None): object exchange_full=None,
object min_trade_size=None):
""" """
Replicates the Asset constructor with some built-in conventions Replicates the Asset constructor with some built-in conventions
and a new 'leverage' attribute. and a new 'leverage' attribute.
@@ -476,6 +478,7 @@ cdef class TradingPair(Asset):
:param first_traded: :param first_traded:
:param auto_close_date: :param auto_close_date:
:param exchange_full: :param exchange_full:
:param min_trade_size:
""" """
symbol = symbol.lower() symbol = symbol.lower()
@@ -509,6 +512,7 @@ cdef class TradingPair(Asset):
first_traded=first_traded, first_traded=first_traded,
auto_close_date=auto_close_date, auto_close_date=auto_close_date,
exchange_full=exchange_full, exchange_full=exchange_full,
min_trade_size=min_trade_size
) )
self.leverage = leverage self.leverage = leverage
@@ -518,14 +522,16 @@ cdef class TradingPair(Asset):
'Introduced On: {start_date}, ' \ 'Introduced On: {start_date}, ' \
'Market Currency: {market_currency}, ' \ 'Market Currency: {market_currency}, ' \
'Base Currency: {base_currency}, ' \ 'Base Currency: {base_currency}, ' \
'Exchange Leverage: {leverage}'.format( 'Exchange Leverage: {leverage}, ' \
'Minimum Trade Size: {min_trade_size}'.format(
symbol=self.symbol, symbol=self.symbol,
sid=self.sid, sid=self.sid,
exchange=self.exchange, exchange=self.exchange,
start_date=self.start_date, start_date=self.start_date,
market_currency=self.market_currency, market_currency=self.market_currency,
base_currency=self.base_currency, base_currency=self.base_currency,
leverage=self.leverage leverage=self.leverage,
min_trade_size=self.min_trade_size
) )
cpdef __reduce__(self): cpdef __reduce__(self):
@@ -544,7 +550,8 @@ cdef class TradingPair(Asset):
self.end_date, self.end_date,
self.first_traded, self.first_traded,
self.auto_close_date, self.auto_close_date,
self.exchange_full)) self.exchange_full,
self.min_trade_size))
def make_asset_array(int size, Asset asset): def make_asset_array(int size, Asset asset):
cdef np.ndarray out = np.empty([size], dtype=object) cdef np.ndarray out = np.empty([size], dtype=object)
+7 -1
View File
@@ -218,13 +218,19 @@ class Exchange:
else: else:
asset_name = None asset_name = None
if 'min_trade_size' in asset:
min_trade_size = asset['min_trade_size']
else:
min_trade_size = 0.0000001
trading_pair = TradingPair( trading_pair = TradingPair(
symbol=asset['symbol'], symbol=asset['symbol'],
exchange=self.name, exchange=self.name,
start_date=start_date, start_date=start_date,
end_date=end_date, end_date=end_date,
leverage=leverage, leverage=leverage,
asset_name=asset_name asset_name=asset_name,
min_trade_size=min_trade_size
) )
self.assets[exchange_symbol] = trading_pair self.assets[exchange_symbol] = trading_pair
+3 -3
View File
@@ -52,6 +52,7 @@ from catalyst.utils.api_support import (
from catalyst.utils.input_validation import error_keywords, ensure_upper_case, \ from catalyst.utils.input_validation import error_keywords, ensure_upper_case, \
expect_types expect_types
from catalyst.utils.preprocess import preprocess from catalyst.utils.preprocess import preprocess
from catalyst.utils.math_utils import round_nearest
log = logbook.Logger('exchange_algorithm') log = logbook.Logger('exchange_algorithm')
@@ -67,15 +68,14 @@ class ExchangeTradingAlgorithmBase(TradingAlgorithm):
super(ExchangeTradingAlgorithmBase, self).__init__(*args, **kwargs) super(ExchangeTradingAlgorithmBase, self).__init__(*args, **kwargs)
def round_order(self, amount): def round_order(self, amount, asset):
""" """
We need fractions with cryptocurrencies We need fractions with cryptocurrencies
:param amount: :param amount:
:return: :return:
""" """
# TODO: is this good enough? Victor has a better solution. return round_nearest(amount, asset.min_trade_size)
return amount
@api_method @api_method
@preprocess(symbol_str=ensure_upper_case) @preprocess(symbol_str=ensure_upper_case)