mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-29 09:04:17 +08:00
adding min_trade_size in TradingPair
This commit is contained in:
@@ -408,7 +408,8 @@ cdef class TradingPair(Asset):
|
||||
'exchange_full',
|
||||
'leverage',
|
||||
'market_currency',
|
||||
'base_currency'
|
||||
'base_currency',
|
||||
'min_trade_size',
|
||||
})
|
||||
def __init__(self,
|
||||
object symbol,
|
||||
@@ -420,7 +421,8 @@ cdef class TradingPair(Asset):
|
||||
object end_date=None,
|
||||
object first_traded=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
|
||||
and a new 'leverage' attribute.
|
||||
@@ -476,6 +478,7 @@ cdef class TradingPair(Asset):
|
||||
:param first_traded:
|
||||
:param auto_close_date:
|
||||
:param exchange_full:
|
||||
:param min_trade_size:
|
||||
"""
|
||||
|
||||
symbol = symbol.lower()
|
||||
@@ -509,6 +512,7 @@ cdef class TradingPair(Asset):
|
||||
first_traded=first_traded,
|
||||
auto_close_date=auto_close_date,
|
||||
exchange_full=exchange_full,
|
||||
min_trade_size=min_trade_size
|
||||
)
|
||||
|
||||
self.leverage = leverage
|
||||
@@ -518,14 +522,16 @@ cdef class TradingPair(Asset):
|
||||
'Introduced On: {start_date}, ' \
|
||||
'Market Currency: {market_currency}, ' \
|
||||
'Base Currency: {base_currency}, ' \
|
||||
'Exchange Leverage: {leverage}'.format(
|
||||
'Exchange Leverage: {leverage}, ' \
|
||||
'Minimum Trade Size: {min_trade_size}'.format(
|
||||
symbol=self.symbol,
|
||||
sid=self.sid,
|
||||
exchange=self.exchange,
|
||||
start_date=self.start_date,
|
||||
market_currency=self.market_currency,
|
||||
base_currency=self.base_currency,
|
||||
leverage=self.leverage
|
||||
leverage=self.leverage,
|
||||
min_trade_size=self.min_trade_size
|
||||
)
|
||||
|
||||
cpdef __reduce__(self):
|
||||
@@ -544,7 +550,8 @@ cdef class TradingPair(Asset):
|
||||
self.end_date,
|
||||
self.first_traded,
|
||||
self.auto_close_date,
|
||||
self.exchange_full))
|
||||
self.exchange_full,
|
||||
self.min_trade_size))
|
||||
|
||||
def make_asset_array(int size, Asset asset):
|
||||
cdef np.ndarray out = np.empty([size], dtype=object)
|
||||
|
||||
@@ -218,13 +218,19 @@ class Exchange:
|
||||
else:
|
||||
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(
|
||||
symbol=asset['symbol'],
|
||||
exchange=self.name,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
leverage=leverage,
|
||||
asset_name=asset_name
|
||||
asset_name=asset_name,
|
||||
min_trade_size=min_trade_size
|
||||
)
|
||||
|
||||
self.assets[exchange_symbol] = trading_pair
|
||||
|
||||
@@ -52,6 +52,7 @@ from catalyst.utils.api_support import (
|
||||
from catalyst.utils.input_validation import error_keywords, ensure_upper_case, \
|
||||
expect_types
|
||||
from catalyst.utils.preprocess import preprocess
|
||||
from catalyst.utils.math_utils import round_nearest
|
||||
|
||||
log = logbook.Logger('exchange_algorithm')
|
||||
|
||||
@@ -67,15 +68,14 @@ class ExchangeTradingAlgorithmBase(TradingAlgorithm):
|
||||
|
||||
super(ExchangeTradingAlgorithmBase, self).__init__(*args, **kwargs)
|
||||
|
||||
def round_order(self, amount):
|
||||
def round_order(self, amount, asset):
|
||||
"""
|
||||
We need fractions with cryptocurrencies
|
||||
|
||||
:param amount:
|
||||
:return:
|
||||
"""
|
||||
# TODO: is this good enough? Victor has a better solution.
|
||||
return amount
|
||||
return round_nearest(amount, asset.min_trade_size)
|
||||
|
||||
@api_method
|
||||
@preprocess(symbol_str=ensure_upper_case)
|
||||
|
||||
Reference in New Issue
Block a user