Merge remote-tracking branch 'origin/master' into stock
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
language: python
|
language: python
|
||||||
dist: bionic
|
dist: bionic
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- $HOME/.cache/pip
|
||||||
|
- $HOME/ta-lib
|
||||||
python:
|
python:
|
||||||
- "3.7"
|
- "3.7"
|
||||||
- "3.8"
|
- "3.8"
|
||||||
@@ -7,11 +11,10 @@ python:
|
|||||||
before_install:
|
before_install:
|
||||||
- cd
|
- cd
|
||||||
- pip3 install Cython numpy
|
- pip3 install Cython numpy
|
||||||
- wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz -q
|
- if [ ! -f "$HOME/ta-lib/src" ]; then wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz -q && tar -xzf ta-lib-0.4.0-src.tar.gz; fi
|
||||||
- tar -xzf ta-lib-0.4.0-src.tar.gz
|
|
||||||
- cd ta-lib/
|
- cd ta-lib/
|
||||||
- ./configure --prefix=/usr
|
- ./configure --prefix=/usr
|
||||||
- make
|
- if [ ! -f "$HOME/ta-lib/src" ]; then make; fi
|
||||||
- sudo make install
|
- sudo make install
|
||||||
- cd
|
- cd
|
||||||
# command to install dependencies
|
# command to install dependencies
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ Here's an example output for a backtest simulation just to get you excited:
|
|||||||
|
|
||||||
exchange | symbol | timeframe | strategy | DNA
|
exchange | symbol | timeframe | strategy | DNA
|
||||||
------------+----------+-------------+------------------+-------
|
------------+----------+-------------+------------------+-------
|
||||||
Bitfinex | BTCUSD | 6h | TrendFollowing05 |
|
Bitfinex | BTC-USD | 6h | TrendFollowing05 |
|
||||||
|
|
||||||
|
|
||||||
Executing simulation... [####################################] 100%
|
Executing simulation... [####################################] 100%
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ import warnings
|
|||||||
warnings.simplefilter(action='ignore', category=FutureWarning)
|
warnings.simplefilter(action='ignore', category=FutureWarning)
|
||||||
|
|
||||||
# Python version validation.
|
# Python version validation.
|
||||||
if jh.python_version() < 3.6:
|
if jh.python_version() < 3.7:
|
||||||
print(
|
print(
|
||||||
jh.color(
|
jh.color(
|
||||||
'Jesse requires Python version above 3.6. Yours is {}'.format(jh.python_version()),
|
'Jesse requires Python version above 3.7. Yours is {}'.format(jh.python_version()),
|
||||||
'red'
|
'red'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ def fake_order(attributes=None):
|
|||||||
global first_timestamp
|
global first_timestamp
|
||||||
first_timestamp += 60000
|
first_timestamp += 60000
|
||||||
exchange = exchanges.SANDBOX
|
exchange = exchanges.SANDBOX
|
||||||
symbol = 'BTCUSD'
|
symbol = 'BTC-USD'
|
||||||
side = sides.BUY
|
side = sides.BUY
|
||||||
order_type = order_types.LIMIT
|
order_type = order_types.LIMIT
|
||||||
price = randint(40, 100)
|
price = randint(40, 100)
|
||||||
|
|||||||
@@ -28,13 +28,7 @@ def arrow_to_timestamp(arrow_time):
|
|||||||
|
|
||||||
|
|
||||||
def base_asset(symbol: str):
|
def base_asset(symbol: str):
|
||||||
if symbol.endswith('USDT'):
|
return symbol.split('-')[0]
|
||||||
return symbol[0:len(symbol) - 4]
|
|
||||||
|
|
||||||
if symbol.endswith('USD'):
|
|
||||||
return symbol[0:len(symbol) - 3]
|
|
||||||
|
|
||||||
return symbol[0:3]
|
|
||||||
|
|
||||||
|
|
||||||
def binary_search(arr: list, item) -> int:
|
def binary_search(arr: list, item) -> int:
|
||||||
@@ -98,14 +92,8 @@ def convert_number(old_max, old_min, new_max, new_min, old_value):
|
|||||||
|
|
||||||
return new_value
|
return new_value
|
||||||
|
|
||||||
|
|
||||||
def dashed_symbol(symbol):
|
|
||||||
return symbol[:3] + '-' + symbol[3:]
|
|
||||||
|
|
||||||
|
|
||||||
def dashless_symbol(symbol):
|
def dashless_symbol(symbol):
|
||||||
return symbol[:3] + symbol[4:]
|
return symbol.replace("-", "")
|
||||||
|
|
||||||
|
|
||||||
def date_diff_in_days(date1, date2):
|
def date_diff_in_days(date1, date2):
|
||||||
if type(date1) is not arrow.arrow.Arrow or type(
|
if type(date1) is not arrow.arrow.Arrow or type(
|
||||||
@@ -504,13 +492,11 @@ def python_version() -> float:
|
|||||||
|
|
||||||
|
|
||||||
def quote_asset(symbol: str):
|
def quote_asset(symbol: str):
|
||||||
if symbol.endswith('USDT'):
|
try:
|
||||||
return 'USDT'
|
return symbol.split('-')[1]
|
||||||
|
except IndexError:
|
||||||
if symbol.endswith('USD'):
|
from jesse.exceptions import InvalidRoutes
|
||||||
return 'USD'
|
raise InvalidRoutes("The symbol format is incorrect. Correct example: 'BTC-USDT'. Yours is '{}'".format(symbol))
|
||||||
|
|
||||||
return symbol[3:]
|
|
||||||
|
|
||||||
|
|
||||||
def random_str(num_characters=8):
|
def random_str(num_characters=8):
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class Exchange:
|
|||||||
if asset == self.settlement_currency:
|
if asset == self.settlement_currency:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
position = selectors.get_position(self.name, asset + self.settlement_currency)
|
position = selectors.get_position(self.name, asset + "-" + self.settlement_currency)
|
||||||
if position is None:
|
if position is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ from .interface import CandleExchange
|
|||||||
|
|
||||||
|
|
||||||
class Binance(CandleExchange):
|
class Binance(CandleExchange):
|
||||||
"""
|
|
||||||
|
|
||||||
"""
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('Binance', 1000, 0.5)
|
super().__init__('Binance', 1000, 0.5)
|
||||||
self.endpoint = 'https://www.binance.com/api/v1/klines'
|
self.endpoint = 'https://www.binance.com/api/v1/klines'
|
||||||
@@ -17,14 +14,11 @@ class Binance(CandleExchange):
|
|||||||
self.backup_exchange = None
|
self.backup_exchange = None
|
||||||
|
|
||||||
def get_starting_time(self, symbol):
|
def get_starting_time(self, symbol):
|
||||||
"""
|
dashless_symbol = jh.dashless_symbol(symbol)
|
||||||
|
|
||||||
:param symbol:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
payload = {
|
payload = {
|
||||||
'interval': '1d',
|
'interval': '1d',
|
||||||
'symbol': symbol,
|
'symbol': dashless_symbol,
|
||||||
'limit': 1500,
|
'limit': 1500,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +48,11 @@ class Binance(CandleExchange):
|
|||||||
"""
|
"""
|
||||||
end_timestamp = start_timestamp + (self.count - 1) * 60000
|
end_timestamp = start_timestamp + (self.count - 1) * 60000
|
||||||
|
|
||||||
|
dashless_symbol = jh.dashless_symbol(symbol)
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
'interval': '1m',
|
'interval': '1m',
|
||||||
'symbol': symbol,
|
'symbol': dashless_symbol,
|
||||||
'startTime': start_timestamp,
|
'startTime': start_timestamp,
|
||||||
'endTime': end_timestamp,
|
'endTime': end_timestamp,
|
||||||
'limit': self.count,
|
'limit': self.count,
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ from .interface import CandleExchange
|
|||||||
|
|
||||||
|
|
||||||
class BinanceFutures(CandleExchange):
|
class BinanceFutures(CandleExchange):
|
||||||
"""
|
|
||||||
|
|
||||||
"""
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('Binance Futures', 1000, 0.5)
|
super().__init__('Binance Futures', 1000, 0.5)
|
||||||
self.endpoint = 'https://fapi.binance.com/fapi/v1/klines'
|
self.endpoint = 'https://fapi.binance.com/fapi/v1/klines'
|
||||||
@@ -18,14 +15,11 @@ class BinanceFutures(CandleExchange):
|
|||||||
self.backup_exchange = Binance()
|
self.backup_exchange = Binance()
|
||||||
|
|
||||||
def get_starting_time(self, symbol):
|
def get_starting_time(self, symbol):
|
||||||
"""
|
dashless_symbol = jh.dashless_symbol(symbol)
|
||||||
|
|
||||||
:param symbol:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
payload = {
|
payload = {
|
||||||
'interval': '1d',
|
'interval': '1d',
|
||||||
'symbol': symbol,
|
'symbol': dashless_symbol,
|
||||||
'limit': 1500,
|
'limit': 1500,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,9 +49,11 @@ class BinanceFutures(CandleExchange):
|
|||||||
"""
|
"""
|
||||||
end_timestamp = start_timestamp + (self.count - 1) * 60000
|
end_timestamp = start_timestamp + (self.count - 1) * 60000
|
||||||
|
|
||||||
|
dashless_symbol = jh.dashless_symbol(symbol)
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
'interval': '1m',
|
'interval': '1m',
|
||||||
'symbol': symbol,
|
'symbol': dashless_symbol,
|
||||||
'startTime': start_timestamp,
|
'startTime': start_timestamp,
|
||||||
'endTime': end_timestamp,
|
'endTime': end_timestamp,
|
||||||
'limit': self.count,
|
'limit': self.count,
|
||||||
|
|||||||
@@ -15,10 +15,12 @@ class Bitfinex(CandleExchange):
|
|||||||
self.backup_exchange = Coinbase()
|
self.backup_exchange = Coinbase()
|
||||||
|
|
||||||
def get_starting_time(self, symbol: str):
|
def get_starting_time(self, symbol: str):
|
||||||
|
dashless_symbol = jh.dashless_symbol(symbol)
|
||||||
|
|
||||||
# hard-code few common symbols
|
# hard-code few common symbols
|
||||||
if symbol == 'BTCUSD':
|
if symbol == 'BTC-USD':
|
||||||
return jh.date_to_timestamp('2015-08-01')
|
return jh.date_to_timestamp('2015-08-01')
|
||||||
elif symbol == 'ETHUSD':
|
elif symbol == 'ETH-USD':
|
||||||
return jh.date_to_timestamp('2016-01-01')
|
return jh.date_to_timestamp('2016-01-01')
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
@@ -26,7 +28,7 @@ class Bitfinex(CandleExchange):
|
|||||||
'limit': 5000,
|
'limit': 5000,
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.get(self.endpoint + '/trade:1D:t{}/hist'.format(symbol), params=payload)
|
response = requests.get(self.endpoint + '/trade:1D:t{}/hist'.format(dashless_symbol), params=payload)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise Exception(response.content)
|
raise Exception(response.content)
|
||||||
@@ -56,8 +58,10 @@ class Bitfinex(CandleExchange):
|
|||||||
'sort': 1
|
'sort': 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dashless_symbol = jh.dashless_symbol(symbol)
|
||||||
|
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
self.endpoint + '/trade:1m:t{}/hist'.format(symbol),
|
self.endpoint + '/trade:1m:t{}/hist'.format(dashless_symbol),
|
||||||
params=payload
|
params=payload
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ from .interface import CandleExchange
|
|||||||
|
|
||||||
|
|
||||||
class Coinbase(CandleExchange):
|
class Coinbase(CandleExchange):
|
||||||
"""
|
|
||||||
|
|
||||||
"""
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('Coinbase', 300, 0.6)
|
super().__init__('Coinbase', 300, 0.6)
|
||||||
self.endpoint = 'https://api.pro.coinbase.com/products'
|
self.endpoint = 'https://api.pro.coinbase.com/products'
|
||||||
@@ -25,11 +22,11 @@ class Coinbase(CandleExchange):
|
|||||||
:param symbol: str
|
:param symbol: str
|
||||||
:return: int
|
:return: int
|
||||||
"""
|
"""
|
||||||
if symbol == 'BTCUSD':
|
if symbol == 'BTC-USD':
|
||||||
return 1438387200000
|
return 1438387200000
|
||||||
elif symbol == 'ETHUSD':
|
elif symbol == 'ETH-USD':
|
||||||
return 1464739200000
|
return 1464739200000
|
||||||
elif symbol == 'LTCUSD':
|
elif symbol == 'LTC-USD':
|
||||||
return 1477958400000
|
return 1477958400000
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@@ -47,9 +44,8 @@ class Coinbase(CandleExchange):
|
|||||||
'end': jh.timestamp_to_time(end_timestamp),
|
'end': jh.timestamp_to_time(end_timestamp),
|
||||||
}
|
}
|
||||||
|
|
||||||
dashed_symbol = symbol[:3] + '-' + symbol[3:]
|
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
self.endpoint + '/{}/candles'.format(dashed_symbol),
|
self.endpoint + '/{}/candles'.format(symbol),
|
||||||
params=payload
|
params=payload
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ from .interface import CandleExchange
|
|||||||
|
|
||||||
|
|
||||||
class TestnetBinanceFutures(CandleExchange):
|
class TestnetBinanceFutures(CandleExchange):
|
||||||
"""
|
|
||||||
|
|
||||||
"""
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('Testnet Binance Futures', 1000, 0.5)
|
super().__init__('Testnet Binance Futures', 1000, 0.5)
|
||||||
self.endpoint = 'https://testnet.binancefuture.com/fapi/v1/klines'
|
self.endpoint = 'https://testnet.binancefuture.com/fapi/v1/klines'
|
||||||
@@ -18,14 +15,11 @@ class TestnetBinanceFutures(CandleExchange):
|
|||||||
self.backup_exchange = Binance()
|
self.backup_exchange = Binance()
|
||||||
|
|
||||||
def get_starting_time(self, symbol):
|
def get_starting_time(self, symbol):
|
||||||
"""
|
dashless_symbol = jh.dashless_symbol(symbol)
|
||||||
|
|
||||||
:param symbol:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
payload = {
|
payload = {
|
||||||
'interval': '1d',
|
'interval': '1d',
|
||||||
'symbol': symbol,
|
'symbol': dashless_symbol,
|
||||||
'limit': 1500,
|
'limit': 1500,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,17 +43,13 @@ class TestnetBinanceFutures(CandleExchange):
|
|||||||
return second_timestamp
|
return second_timestamp
|
||||||
|
|
||||||
def fetch(self, symbol, start_timestamp):
|
def fetch(self, symbol, start_timestamp):
|
||||||
"""
|
|
||||||
|
|
||||||
:param symbol:
|
|
||||||
:param start_timestamp:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
end_timestamp = start_timestamp + (self.count - 1) * 60000
|
end_timestamp = start_timestamp + (self.count - 1) * 60000
|
||||||
|
|
||||||
|
dashless_symbol = jh.dashless_symbol(symbol)
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
'interval': '1m',
|
'interval': '1m',
|
||||||
'symbol': symbol,
|
'symbol': dashless_symbol,
|
||||||
'startTime': start_timestamp,
|
'startTime': start_timestamp,
|
||||||
'endTime': end_timestamp,
|
'endTime': end_timestamp,
|
||||||
'limit': self.count,
|
'limit': self.count,
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ from jesse.utils import anchor_timeframe
|
|||||||
|
|
||||||
# trading routes
|
# trading routes
|
||||||
routes = [
|
routes = [
|
||||||
('Binance', 'BTCUSDT', '4h', 'ExampleStrategy'),
|
('Binance', 'BTC-USDT', '4h', 'ExampleStrategy'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# in case your strategy requires extra candles, timeframes, ...
|
# in case your strategy requires extra candles, timeframes, ...
|
||||||
extra_candles = [
|
extra_candles = [
|
||||||
('Binance', 'BTCUSDT', anchor_timeframe('4h')),
|
('Binance', 'BTC-USDT', anchor_timeframe('4h')),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ class CandlesState:
|
|||||||
|
|
||||||
if jh.is_live():
|
if jh.is_live():
|
||||||
self.update_position(exchange, symbol, candle)
|
self.update_position(exchange, symbol, candle)
|
||||||
|
|
||||||
# initial
|
# initial
|
||||||
if len(arr) == 0:
|
if len(arr) == 0:
|
||||||
arr.append(candle)
|
arr.append(candle)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from jesse.strategies import Strategy
|
from jesse.strategies import Strategy
|
||||||
|
|
||||||
|
|
||||||
# test_on_route_open_position part 1 - BTCUSD
|
# test_on_route_open_position part 1 - BTC-USD
|
||||||
class Test21(Strategy):
|
class Test21(Strategy):
|
||||||
def should_long(self):
|
def should_long(self):
|
||||||
# buy on market at first candle, close when on_route_open_position event is fired
|
# buy on market at first candle, close when on_route_open_position event is fired
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from jesse.strategies import Strategy
|
from jesse.strategies import Strategy
|
||||||
|
|
||||||
|
|
||||||
# test_on_route_open_position part 2 - ETHUSD
|
# test_on_route_open_position part 2 - ETH-USD
|
||||||
class Test22(Strategy):
|
class Test22(Strategy):
|
||||||
def should_long(self):
|
def should_long(self):
|
||||||
return self.price == 10
|
return self.price == 10
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from jesse.strategies import Strategy
|
from jesse.strategies import Strategy
|
||||||
|
|
||||||
|
|
||||||
# test_on_route_take_profit part 1 - BTCUSD
|
# test_on_route_take_profit part 1 - BTC-USD
|
||||||
class Test23(Strategy):
|
class Test23(Strategy):
|
||||||
def should_long(self):
|
def should_long(self):
|
||||||
# buy on market at first candle, close when on_route_take_profit event is fired
|
# buy on market at first candle, close when on_route_take_profit event is fired
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from jesse.strategies import Strategy
|
from jesse.strategies import Strategy
|
||||||
|
|
||||||
|
|
||||||
# test_on_route_take_profit part 2 - ETHUSD
|
# test_on_route_take_profit part 2 - ETH-USD
|
||||||
class Test24(Strategy):
|
class Test24(Strategy):
|
||||||
def should_long(self):
|
def should_long(self):
|
||||||
return self.price == 10
|
return self.price == 10
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from jesse.strategies import Strategy
|
from jesse.strategies import Strategy
|
||||||
|
|
||||||
|
|
||||||
# test_on_route_stop_loss part 1 - BTCUSD
|
# test_on_route_stop_loss part 1 - BTC-USD
|
||||||
class Test25(Strategy):
|
class Test25(Strategy):
|
||||||
def should_long(self):
|
def should_long(self):
|
||||||
# buy on market at first candle, close when on_route_stop_loss event is fired
|
# buy on market at first candle, close when on_route_stop_loss event is fired
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from jesse.strategies import Strategy
|
from jesse.strategies import Strategy
|
||||||
|
|
||||||
|
|
||||||
# test_on_route_stop_loss part 2 - ETHUSD
|
# test_on_route_stop_loss part 2 - ETH-USD
|
||||||
class Test26(Strategy):
|
class Test26(Strategy):
|
||||||
def should_long(self):
|
def should_long(self):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from jesse.strategies import Strategy
|
from jesse.strategies import Strategy
|
||||||
|
|
||||||
|
|
||||||
# test_on_route_canceled part 1 - BTCUSD
|
# test_on_route_canceled part 1 - BTC-USD
|
||||||
class Test27(Strategy):
|
class Test27(Strategy):
|
||||||
def should_long(self):
|
def should_long(self):
|
||||||
# buy on market at first candle, close when on_route_stop_loss event is fired
|
# buy on market at first candle, close when on_route_stop_loss event is fired
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from jesse.strategies import Strategy
|
from jesse.strategies import Strategy
|
||||||
|
|
||||||
|
|
||||||
# test_on_route_canceled part 2 - ETHUSD
|
# test_on_route_canceled part 2 - ETH-USD
|
||||||
class Test28(Strategy):
|
class Test28(Strategy):
|
||||||
def should_long(self):
|
def should_long(self):
|
||||||
return self.price == 10
|
return self.price == 10
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from jesse.strategies import Strategy
|
from jesse.strategies import Strategy
|
||||||
|
|
||||||
|
|
||||||
# test_on_route_increased_position_and_on_route_reduced_position_and_strategy_vars part 1 - BTCUSD
|
# test_on_route_increased_position_and_on_route_reduced_position_and_strategy_vars part 1 - BTC-USD
|
||||||
class Test29(Strategy):
|
class Test29(Strategy):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from jesse.strategies import Strategy
|
from jesse.strategies import Strategy
|
||||||
|
|
||||||
|
|
||||||
# test_on_route_increased_position_and_on_route_reduced_position_and_strategy_vars part 2 - ETHUSD
|
# test_on_route_increased_position_and_on_route_reduced_position_and_strategy_vars part 2 - ETH-USD
|
||||||
class Test30(Strategy):
|
class Test30(Strategy):
|
||||||
def update_position(self):
|
def update_position(self):
|
||||||
# increase position size
|
# increase position size
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ psycopg2-binary~=2.8.6
|
|||||||
pydash~=4.9.0
|
pydash~=4.9.0
|
||||||
pytest==6.2.1
|
pytest==6.2.1
|
||||||
requests~=2.25.0
|
requests~=2.25.0
|
||||||
scipy~=1.5.4
|
scipy==1.6.0
|
||||||
TA-Lib~=0.4.19
|
TA-Lib~=0.4.19
|
||||||
tabulate~=0.8.7
|
tabulate~=0.8.7
|
||||||
timeloop~=1.0.2
|
timeloop~=1.0.2
|
||||||
|
|||||||
4
setup.py
4
setup.py
@@ -1,6 +1,6 @@
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
VERSION = '0.17.2'
|
VERSION = '0.18.1'
|
||||||
DESCRIPTION = "A trading framework for cryptocurrencies"
|
DESCRIPTION = "A trading framework for cryptocurrencies"
|
||||||
|
|
||||||
REQUIRED_PACKAGES = [
|
REQUIRED_PACKAGES = [
|
||||||
@@ -54,6 +54,6 @@ setup(
|
|||||||
"License :: OSI Approved :: MIT License",
|
"License :: OSI Approved :: MIT License",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
],
|
],
|
||||||
python_requires='>=3.6',
|
python_requires='>=3.7',
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,16 +12,16 @@ from jesse.config import config
|
|||||||
def test_backtesting_one_route():
|
def test_backtesting_one_route():
|
||||||
reset_config()
|
reset_config()
|
||||||
router.set_routes([
|
router.set_routes([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_5, 'Test19')
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_5, 'Test19')
|
||||||
])
|
])
|
||||||
config['env']['exchanges'][exchanges.SANDBOX]['type'] = 'margin'
|
config['env']['exchanges'][exchanges.SANDBOX]['type'] = 'margin'
|
||||||
store.reset(True)
|
store.reset(True)
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
key = jh.key(exchanges.SANDBOX, 'BTCUSDT')
|
key = jh.key(exchanges.SANDBOX, 'BTC-USDT')
|
||||||
candles[key] = {
|
candles[key] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'BTCUSDT',
|
'symbol': 'BTC-USDT',
|
||||||
'candles': fake_range_candle(5 * 20)
|
'candles': fake_range_candle(5 * 20)
|
||||||
}
|
}
|
||||||
routes = router.routes
|
routes = router.routes
|
||||||
@@ -32,8 +32,8 @@ def test_backtesting_one_route():
|
|||||||
# run backtest (dates are fake just to pass)
|
# run backtest (dates are fake just to pass)
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', candles)
|
backtest_mode.run('2019-04-01', '2019-04-02', candles)
|
||||||
|
|
||||||
one_min = store.candles.get_candles(exchanges.SANDBOX, 'BTCUSDT', '1m')
|
one_min = store.candles.get_candles(exchanges.SANDBOX, 'BTC-USDT', '1m')
|
||||||
five_min = store.candles.get_candles(exchanges.SANDBOX, 'BTCUSDT', '5m')
|
five_min = store.candles.get_candles(exchanges.SANDBOX, 'BTC-USDT', '5m')
|
||||||
|
|
||||||
# assert the count of present candles
|
# assert the count of present candles
|
||||||
assert len(five_min) == 20
|
assert len(five_min) == 20
|
||||||
@@ -53,7 +53,7 @@ def test_backtesting_one_route():
|
|||||||
|
|
||||||
# there must be only one positions present
|
# there must be only one positions present
|
||||||
assert len(store.positions.storage) == 1
|
assert len(store.positions.storage) == 1
|
||||||
p = selectors.get_position(exchanges.SANDBOX, 'BTCUSDT')
|
p = selectors.get_position(exchanges.SANDBOX, 'BTC-USDT')
|
||||||
assert p.is_close
|
assert p.is_close
|
||||||
assert p.current_price == last_1[2]
|
assert p.current_price == last_1[2]
|
||||||
assert p.current_price == last_5[2]
|
assert p.current_price == last_5[2]
|
||||||
@@ -61,7 +61,7 @@ def test_backtesting_one_route():
|
|||||||
# assert routes
|
# assert routes
|
||||||
assert len(routes) == 1
|
assert len(routes) == 1
|
||||||
assert routes[0].exchange == exchanges.SANDBOX
|
assert routes[0].exchange == exchanges.SANDBOX
|
||||||
assert routes[0].symbol == 'BTCUSDT'
|
assert routes[0].symbol == 'BTC-USDT'
|
||||||
assert routes[0].timeframe == '5m'
|
assert routes[0].timeframe == '5m'
|
||||||
assert routes[0].strategy_name == 'Test19'
|
assert routes[0].strategy_name == 'Test19'
|
||||||
# assert that the strategy has been initiated
|
# assert that the strategy has been initiated
|
||||||
@@ -71,9 +71,9 @@ def test_backtesting_one_route():
|
|||||||
def test_backtesting_three_routes():
|
def test_backtesting_three_routes():
|
||||||
reset_config()
|
reset_config()
|
||||||
router.set_routes([
|
router.set_routes([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_5, 'Test19'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_5, 'Test19'),
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test19'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test19'),
|
||||||
(exchanges.SANDBOX, 'XRPUSDT', timeframes.MINUTE_15, 'Test19'),
|
(exchanges.SANDBOX, 'XRP-USDT', timeframes.MINUTE_15, 'Test19'),
|
||||||
])
|
])
|
||||||
config['env']['exchanges'][exchanges.SANDBOX]['type'] = 'margin'
|
config['env']['exchanges'][exchanges.SANDBOX]['type'] = 'margin'
|
||||||
store.reset(True)
|
store.reset(True)
|
||||||
|
|||||||
@@ -29,16 +29,16 @@ def set_up_without_fee(is_margin_trading=False):
|
|||||||
config['env']['exchanges'][exchanges.SANDBOX]['settlement_currency'] = 'USDT'
|
config['env']['exchanges'][exchanges.SANDBOX]['settlement_currency'] = 'USDT'
|
||||||
config['app']['trading_mode'] = 'backtest'
|
config['app']['trading_mode'] = 'backtest'
|
||||||
config['app']['considering_exchanges'] = ['Sandbox']
|
config['app']['considering_exchanges'] = ['Sandbox']
|
||||||
router.set_routes([(exchanges.SANDBOX, 'BTCUSDT', '5m', 'Test19')])
|
router.set_routes([(exchanges.SANDBOX, 'BTC-USDT', '5m', 'Test19')])
|
||||||
store.reset(True)
|
store.reset(True)
|
||||||
|
|
||||||
global position
|
global position
|
||||||
global exchange
|
global exchange
|
||||||
global broker
|
global broker
|
||||||
position = selectors.get_position(exchanges.SANDBOX, 'BTCUSDT')
|
position = selectors.get_position(exchanges.SANDBOX, 'BTC-USDT')
|
||||||
position.current_price = 50
|
position.current_price = 50
|
||||||
exchange = selectors.get_exchange(exchanges.SANDBOX)
|
exchange = selectors.get_exchange(exchanges.SANDBOX)
|
||||||
broker = Broker(position, exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_5)
|
broker = Broker(position, exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_5)
|
||||||
|
|
||||||
|
|
||||||
def set_up_with_fee(is_margin_trading=False):
|
def set_up_with_fee(is_margin_trading=False):
|
||||||
@@ -56,16 +56,16 @@ def set_up_with_fee(is_margin_trading=False):
|
|||||||
config['env']['exchanges'][exchanges.SANDBOX]['settlement_currency'] = 'USDT'
|
config['env']['exchanges'][exchanges.SANDBOX]['settlement_currency'] = 'USDT'
|
||||||
config['app']['trading_mode'] = 'backtest'
|
config['app']['trading_mode'] = 'backtest'
|
||||||
config['app']['considering_exchanges'] = ['Sandbox']
|
config['app']['considering_exchanges'] = ['Sandbox']
|
||||||
router.set_routes([(exchanges.SANDBOX, 'BTCUSDT', '5m', 'Test19')])
|
router.set_routes([(exchanges.SANDBOX, 'BTC-USDT', '5m', 'Test19')])
|
||||||
store.reset(True)
|
store.reset(True)
|
||||||
|
|
||||||
global position
|
global position
|
||||||
global exchange
|
global exchange
|
||||||
global broker
|
global broker
|
||||||
position = selectors.get_position(exchanges.SANDBOX, 'BTCUSDT')
|
position = selectors.get_position(exchanges.SANDBOX, 'BTC-USDT')
|
||||||
position.current_price = 50
|
position.current_price = 50
|
||||||
exchange = selectors.get_exchange(exchanges.SANDBOX)
|
exchange = selectors.get_exchange(exchanges.SANDBOX)
|
||||||
broker = Broker(position, exchanges.SANDBOX, 'BTCUSDT',
|
broker = Broker(position, exchanges.SANDBOX, 'BTC-USDT',
|
||||||
timeframes.MINUTE_5)
|
timeframes.MINUTE_5)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ from jesse.config import config
|
|||||||
|
|
||||||
def get_btc_candles():
|
def get_btc_candles():
|
||||||
candles = {}
|
candles = {}
|
||||||
candles[jh.key(exchanges.SANDBOX, 'BTCUSDT')] = {
|
candles[jh.key(exchanges.SANDBOX, 'BTC-USDT')] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'BTCUSDT',
|
'symbol': 'BTC-USDT',
|
||||||
'candles': fake_range_candle_from_range_prices(range(1, 100))
|
'candles': fake_range_candle_from_range_prices(range(1, 100))
|
||||||
}
|
}
|
||||||
return candles
|
return candles
|
||||||
@@ -32,7 +32,7 @@ def set_up(routes, is_margin_trading=True):
|
|||||||
|
|
||||||
def test_can_handle_multiple_entry_orders_too_close_to_each_other():
|
def test_can_handle_multiple_entry_orders_too_close_to_each_other():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test34'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test34'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -57,7 +57,7 @@ def test_can_handle_multiple_entry_orders_too_close_to_each_other():
|
|||||||
assert t.orders[2].role == order_roles.INCREASE_POSITION
|
assert t.orders[2].role == order_roles.INCREASE_POSITION
|
||||||
def test_conflicting_orders():
|
def test_conflicting_orders():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test04'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test04'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -75,7 +75,7 @@ def test_conflicting_orders():
|
|||||||
|
|
||||||
def test_conflicting_orders_2():
|
def test_conflicting_orders_2():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test20'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test20'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -94,7 +94,7 @@ def test_conflicting_orders_2():
|
|||||||
#
|
#
|
||||||
# def test_can_handle_not_correctly_sorted_multiple_orders():
|
# def test_can_handle_not_correctly_sorted_multiple_orders():
|
||||||
# set_up([
|
# set_up([
|
||||||
# (exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test35'),
|
# (exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test35'),
|
||||||
# ])
|
# ])
|
||||||
#
|
#
|
||||||
# backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
# backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ def test_app_currency():
|
|||||||
from jesse.routes import router
|
from jesse.routes import router
|
||||||
from jesse.enums import exchanges, timeframes
|
from jesse.enums import exchanges, timeframes
|
||||||
router.set_routes([
|
router.set_routes([
|
||||||
(exchanges.BITFINEX, 'ETHUSD', timeframes.HOUR_3, 'Test19'),
|
(exchanges.BITFINEX, 'ETH-USD', timeframes.HOUR_3, 'Test19'),
|
||||||
])
|
])
|
||||||
assert jh.app_currency() == 'USD'
|
assert jh.app_currency() == 'USD'
|
||||||
|
|
||||||
@@ -24,10 +24,10 @@ def test_arrow_to_timestamp():
|
|||||||
|
|
||||||
|
|
||||||
def test_base_asset():
|
def test_base_asset():
|
||||||
assert jh.base_asset('BTCUSDT') == 'BTC'
|
assert jh.base_asset('BTC-USDT') == 'BTC'
|
||||||
assert jh.base_asset('BTCUSD') == 'BTC'
|
assert jh.base_asset('BTC-USD') == 'BTC'
|
||||||
assert jh.base_asset('DEFIUSDT') == 'DEFI'
|
assert jh.base_asset('DEFI-USDT') == 'DEFI'
|
||||||
assert jh.base_asset('DEFIUSD') == 'DEFI'
|
assert jh.base_asset('DEFI-USD') == 'DEFI'
|
||||||
|
|
||||||
|
|
||||||
def test_binary_search():
|
def test_binary_search():
|
||||||
@@ -71,12 +71,6 @@ def test_convert_number():
|
|||||||
|
|
||||||
assert jh.convert_number(old_max, old_min, new_max, new_min, old_value) == 0.5443037974683544
|
assert jh.convert_number(old_max, old_min, new_max, new_min, old_value) == 0.5443037974683544
|
||||||
|
|
||||||
|
|
||||||
def test_dashed_symbol():
|
|
||||||
assert jh.dashed_symbol('BTCUSD') == 'BTC-USD'
|
|
||||||
assert jh.dashed_symbol('BTCUSDT') == 'BTC-USDT'
|
|
||||||
|
|
||||||
|
|
||||||
def test_dashless_symbol():
|
def test_dashless_symbol():
|
||||||
assert jh.dashless_symbol('BTC-USD') == 'BTCUSD'
|
assert jh.dashless_symbol('BTC-USD') == 'BTCUSD'
|
||||||
assert jh.dashless_symbol('BTC-USDT') == 'BTCUSDT'
|
assert jh.dashless_symbol('BTC-USDT') == 'BTCUSDT'
|
||||||
@@ -290,10 +284,10 @@ def test_is_unit_testing():
|
|||||||
|
|
||||||
def test_key():
|
def test_key():
|
||||||
exchange = "Exchange"
|
exchange = "Exchange"
|
||||||
symbol = "BTCUSD"
|
symbol = "BTC-USD"
|
||||||
timeframe = "6h"
|
timeframe = "6h"
|
||||||
assert jh.key(exchange, symbol) == "Exchange-BTCUSD"
|
assert jh.key(exchange, symbol) == "Exchange-BTC-USD"
|
||||||
assert jh.key(exchange, symbol, timeframe) == "Exchange-BTCUSD-6h"
|
assert jh.key(exchange, symbol, timeframe) == "Exchange-BTC-USD-6h"
|
||||||
|
|
||||||
|
|
||||||
def test_max_timeframe():
|
def test_max_timeframe():
|
||||||
@@ -404,8 +398,9 @@ def test_python_version():
|
|||||||
|
|
||||||
|
|
||||||
def test_quote_asset():
|
def test_quote_asset():
|
||||||
assert jh.quote_asset('BTCUSDT') == 'USDT'
|
assert jh.quote_asset('BTC-USDT') == 'USDT'
|
||||||
assert jh.quote_asset('DEFIUSDT') == 'USDT'
|
assert jh.quote_asset('DEFI-USDT') == 'USDT'
|
||||||
|
assert jh.quote_asset('DEFI-EUR') == 'EUR'
|
||||||
|
|
||||||
|
|
||||||
def test_random_str():
|
def test_random_str():
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ test_object_candles = []
|
|||||||
for c in test_candles_0:
|
for c in test_candles_0:
|
||||||
test_object_candles.append({
|
test_object_candles.append({
|
||||||
'id': jh.generate_unique_id(),
|
'id': jh.generate_unique_id(),
|
||||||
'symbol': 'BTCUSD',
|
'symbol': 'BTC-USD',
|
||||||
'exchange': 'Sandbox',
|
'exchange': 'Sandbox',
|
||||||
'timestamp': c[0],
|
'timestamp': c[0],
|
||||||
'open': c[1],
|
'open': c[1],
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ from jesse.store import store
|
|||||||
|
|
||||||
def get_btc_and_eth_candles():
|
def get_btc_and_eth_candles():
|
||||||
candles = {}
|
candles = {}
|
||||||
candles[jh.key(exchanges.SANDBOX, 'BTCUSDT')] = {
|
candles[jh.key(exchanges.SANDBOX, 'BTC-USDT')] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'BTCUSDT',
|
'symbol': 'BTC-USDT',
|
||||||
'candles': fake_range_candle_from_range_prices(range(101, 200))
|
'candles': fake_range_candle_from_range_prices(range(101, 200))
|
||||||
}
|
}
|
||||||
candles[jh.key(exchanges.SANDBOX, 'ETHUSDT')] = {
|
candles[jh.key(exchanges.SANDBOX, 'ETH-USDT')] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'ETHUSDT',
|
'symbol': 'ETH-USDT',
|
||||||
'candles': fake_range_candle_from_range_prices(range(1, 100))
|
'candles': fake_range_candle_from_range_prices(range(1, 100))
|
||||||
}
|
}
|
||||||
return candles
|
return candles
|
||||||
@@ -24,9 +24,9 @@ def get_btc_and_eth_candles():
|
|||||||
|
|
||||||
def get_btc_candles():
|
def get_btc_candles():
|
||||||
candles = {}
|
candles = {}
|
||||||
candles[jh.key(exchanges.SANDBOX, 'BTCUSDT')] = {
|
candles[jh.key(exchanges.SANDBOX, 'BTC-USDT')] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'BTCUSDT',
|
'symbol': 'BTC-USDT',
|
||||||
'candles': fake_range_candle_from_range_prices(range(1, 100))
|
'candles': fake_range_candle_from_range_prices(range(1, 100))
|
||||||
}
|
}
|
||||||
return candles
|
return candles
|
||||||
@@ -46,7 +46,7 @@ def set_up(routes, fee=0):
|
|||||||
|
|
||||||
|
|
||||||
def test_open_pl_and_total_open_trades():
|
def test_open_pl_and_total_open_trades():
|
||||||
set_up([(exchanges.SANDBOX, 'BTCUSDT', '1m', 'Test40')])
|
set_up([(exchanges.SANDBOX, 'BTC-USDT', '1m', 'Test40')])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
|
|
||||||
@@ -56,14 +56,14 @@ def test_open_pl_and_total_open_trades():
|
|||||||
|
|
||||||
# def test_statistics_for_trades_without_fee():
|
# def test_statistics_for_trades_without_fee():
|
||||||
# set_up([
|
# set_up([
|
||||||
# (exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test06'),
|
# (exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test06'),
|
||||||
# ])
|
# ])
|
||||||
#
|
#
|
||||||
# candles = {}
|
# candles = {}
|
||||||
# key = jh.key(exchanges.SANDBOX, 'ETHUSDT')
|
# key = jh.key(exchanges.SANDBOX, 'ETH-USDT')
|
||||||
# candles[key] = {
|
# candles[key] = {
|
||||||
# 'exchange': exchanges.SANDBOX,
|
# 'exchange': exchanges.SANDBOX,
|
||||||
# 'symbol': 'ETHUSDT',
|
# 'symbol': 'ETH-USDT',
|
||||||
# 'candles': test_candles_1
|
# 'candles': test_candles_1
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
@@ -103,14 +103,14 @@ def test_open_pl_and_total_open_trades():
|
|||||||
#
|
#
|
||||||
# def test_stats_for_a_strategy_without_losing_trades():
|
# def test_stats_for_a_strategy_without_losing_trades():
|
||||||
# set_up([
|
# set_up([
|
||||||
# (exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test08'),
|
# (exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test08'),
|
||||||
# ])
|
# ])
|
||||||
#
|
#
|
||||||
# candles = {}
|
# candles = {}
|
||||||
# key = jh.key(exchanges.SANDBOX, 'ETHUSDT')
|
# key = jh.key(exchanges.SANDBOX, 'ETH-USDT')
|
||||||
# candles[key] = {
|
# candles[key] = {
|
||||||
# 'exchange': exchanges.SANDBOX,
|
# 'exchange': exchanges.SANDBOX,
|
||||||
# 'symbol': 'ETHUSDT',
|
# 'symbol': 'ETH-USDT',
|
||||||
# 'candles': test_candles_1
|
# 'candles': test_candles_1
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
@@ -147,14 +147,14 @@ def test_open_pl_and_total_open_trades():
|
|||||||
#
|
#
|
||||||
# def test_stats_for_a_strategy_without_any_trades():
|
# def test_stats_for_a_strategy_without_any_trades():
|
||||||
# set_up([
|
# set_up([
|
||||||
# (exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test09'),
|
# (exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test09'),
|
||||||
# ])
|
# ])
|
||||||
#
|
#
|
||||||
# candles = {}
|
# candles = {}
|
||||||
# key = jh.key(exchanges.SANDBOX, 'ETHUSDT')
|
# key = jh.key(exchanges.SANDBOX, 'ETH-USDT')
|
||||||
# candles[key] = {
|
# candles[key] = {
|
||||||
# 'exchange': exchanges.SANDBOX,
|
# 'exchange': exchanges.SANDBOX,
|
||||||
# 'symbol': 'ETHUSDT',
|
# 'symbol': 'ETH-USDT',
|
||||||
# 'candles': test_candles_1
|
# 'candles': test_candles_1
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
@@ -192,14 +192,14 @@ def test_open_pl_and_total_open_trades():
|
|||||||
# #
|
# #
|
||||||
# # def test_statistics_for_trades_with_fee():
|
# # def test_statistics_for_trades_with_fee():
|
||||||
# # set_up([
|
# # set_up([
|
||||||
# # (exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test06'),
|
# # (exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test06'),
|
||||||
# # ], 0.002)
|
# # ], 0.002)
|
||||||
# #
|
# #
|
||||||
# # candles = {}
|
# # candles = {}
|
||||||
# # key = jh.key(exchanges.SANDBOX, 'ETHUSDT')
|
# # key = jh.key(exchanges.SANDBOX, 'ETH-USDT')
|
||||||
# # candles[key] = {
|
# # candles[key] = {
|
||||||
# # 'exchange': exchanges.SANDBOX,
|
# # 'exchange': exchanges.SANDBOX,
|
||||||
# # 'symbol': 'ETHUSDT',
|
# # 'symbol': 'ETH-USDT',
|
||||||
# # 'candles': test_candles_1
|
# # 'candles': test_candles_1
|
||||||
# # }
|
# # }
|
||||||
# #
|
# #
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ def set_up_without_fee(is_margin_trading=False):
|
|||||||
config['env']['exchanges'][exchanges.SANDBOX]['settlement_currency'] = 'USDT'
|
config['env']['exchanges'][exchanges.SANDBOX]['settlement_currency'] = 'USDT'
|
||||||
config['app']['trading_mode'] = 'backtest'
|
config['app']['trading_mode'] = 'backtest'
|
||||||
config['app']['considering_exchanges'] = ['Sandbox']
|
config['app']['considering_exchanges'] = ['Sandbox']
|
||||||
router.set_routes([(exchanges.SANDBOX, 'BTCUSDT', '5m', 'Test19')])
|
router.set_routes([(exchanges.SANDBOX, 'BTC-USDT', '5m', 'Test19')])
|
||||||
store.reset(True)
|
store.reset(True)
|
||||||
|
|
||||||
global position
|
global position
|
||||||
global exchange
|
global exchange
|
||||||
position = selectors.get_position(exchanges.SANDBOX, 'BTCUSDT')
|
position = selectors.get_position(exchanges.SANDBOX, 'BTC-USDT')
|
||||||
position.current_price = 50
|
position.current_price = 50
|
||||||
exchange = selectors.get_exchange(exchanges.SANDBOX)
|
exchange = selectors.get_exchange(exchanges.SANDBOX)
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ def test_cancel_order():
|
|||||||
order = Order({
|
order = Order({
|
||||||
'id': jh.generate_unique_id(),
|
'id': jh.generate_unique_id(),
|
||||||
'exchange': exchange.name,
|
'exchange': exchange.name,
|
||||||
'symbol': 'BTCUSDT',
|
'symbol': 'BTC-USDT',
|
||||||
'type': order_types.LIMIT,
|
'type': order_types.LIMIT,
|
||||||
'price': 129.33,
|
'price': 129.33,
|
||||||
'qty': 10.2041,
|
'qty': 10.2041,
|
||||||
@@ -64,7 +64,7 @@ def test_execute_order():
|
|||||||
|
|
||||||
order = Order({
|
order = Order({
|
||||||
'id': jh.generate_unique_id(),
|
'id': jh.generate_unique_id(),
|
||||||
'symbol': 'BTCUSDT',
|
'symbol': 'BTC-USDT',
|
||||||
'exchange': exchange.name,
|
'exchange': exchange.name,
|
||||||
'type': order_types.LIMIT,
|
'type': order_types.LIMIT,
|
||||||
'price': 129.33,
|
'price': 129.33,
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ from tests.data import test_candles_1
|
|||||||
|
|
||||||
def get_btc_and_eth_candles():
|
def get_btc_and_eth_candles():
|
||||||
candles = {}
|
candles = {}
|
||||||
candles[jh.key(exchanges.SANDBOX, 'BTCUSDT')] = {
|
candles[jh.key(exchanges.SANDBOX, 'BTC-USDT')] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'BTCUSDT',
|
'symbol': 'BTC-USDT',
|
||||||
'candles': fake_range_candle_from_range_prices(range(101, 200))
|
'candles': fake_range_candle_from_range_prices(range(101, 200))
|
||||||
}
|
}
|
||||||
candles[jh.key(exchanges.SANDBOX, 'ETHUSDT')] = {
|
candles[jh.key(exchanges.SANDBOX, 'ETH-USDT')] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'ETHUSDT',
|
'symbol': 'ETH-USDT',
|
||||||
'candles': fake_range_candle_from_range_prices(range(1, 100))
|
'candles': fake_range_candle_from_range_prices(range(1, 100))
|
||||||
}
|
}
|
||||||
return candles
|
return candles
|
||||||
@@ -37,9 +37,9 @@ def get_btc_and_eth_candles():
|
|||||||
|
|
||||||
def get_btc_candles():
|
def get_btc_candles():
|
||||||
candles = {}
|
candles = {}
|
||||||
candles[jh.key(exchanges.SANDBOX, 'BTCUSDT')] = {
|
candles[jh.key(exchanges.SANDBOX, 'BTC-USDT')] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'BTCUSDT',
|
'symbol': 'BTC-USDT',
|
||||||
'candles': fake_range_candle_from_range_prices(range(1, 100))
|
'candles': fake_range_candle_from_range_prices(range(1, 100))
|
||||||
}
|
}
|
||||||
return candles
|
return candles
|
||||||
@@ -63,13 +63,13 @@ def set_up(routes, is_margin_trading=True):
|
|||||||
|
|
||||||
def single_route_backtest(strategy_name: str):
|
def single_route_backtest(strategy_name: str):
|
||||||
"""used to simplify simple tests"""
|
"""used to simplify simple tests"""
|
||||||
set_up([(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, strategy_name)])
|
set_up([(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, strategy_name)])
|
||||||
# dates are fake. just to pass required parameters
|
# dates are fake. just to pass required parameters
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
|
|
||||||
|
|
||||||
def test_average_stop_loss_exception():
|
def test_average_stop_loss_exception():
|
||||||
set_up([(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test39')])
|
set_up([(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test39')])
|
||||||
|
|
||||||
with pytest.raises(exceptions.InvalidStrategy):
|
with pytest.raises(exceptions.InvalidStrategy):
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -95,7 +95,7 @@ def test_average_take_profit_and_average_stop_loss():
|
|||||||
|
|
||||||
|
|
||||||
def test_average_take_profit_exception():
|
def test_average_take_profit_exception():
|
||||||
set_up([(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test38')])
|
set_up([(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test38')])
|
||||||
|
|
||||||
with pytest.raises(exceptions.InvalidStrategy):
|
with pytest.raises(exceptions.InvalidStrategy):
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -112,8 +112,8 @@ def test_can_close_a_long_position_and_go_short_at_the_same_candle():
|
|||||||
|
|
||||||
def test_can_perform_backtest_with_multiple_routes():
|
def test_can_perform_backtest_with_multiple_routes():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test01'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test01'),
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_5, 'Test02'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_5, 'Test02'),
|
||||||
])
|
])
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
@@ -178,32 +178,32 @@ def test_filters():
|
|||||||
def test_forming_candles():
|
def test_forming_candles():
|
||||||
reset_config()
|
reset_config()
|
||||||
router.set_routes([
|
router.set_routes([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_5, 'Test19')
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_5, 'Test19')
|
||||||
])
|
])
|
||||||
router.set_extra_candles([
|
router.set_extra_candles([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_15)
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_15)
|
||||||
])
|
])
|
||||||
store.reset(True)
|
store.reset(True)
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
key = jh.key(exchanges.SANDBOX, 'BTCUSDT')
|
key = jh.key(exchanges.SANDBOX, 'BTC-USDT')
|
||||||
candles[key] = {
|
candles[key] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'BTCUSDT',
|
'symbol': 'BTC-USDT',
|
||||||
'candles': test_candles_0
|
'candles': test_candles_0
|
||||||
}
|
}
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', candles)
|
backtest_mode.run('2019-04-01', '2019-04-02', candles)
|
||||||
|
|
||||||
# use math.ceil because it must include forming candle too
|
# use math.ceil because it must include forming candle too
|
||||||
assert len(store.candles.get_candles(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_5)) == math.ceil(1382 / 5)
|
assert len(store.candles.get_candles(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_5)) == math.ceil(1382 / 5)
|
||||||
assert len(store.candles.get_candles(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_15)) == math.ceil(
|
assert len(store.candles.get_candles(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_15)) == math.ceil(
|
||||||
1382 / 15)
|
1382 / 15)
|
||||||
|
|
||||||
|
|
||||||
def test_increasing_position_size_after_opening():
|
def test_increasing_position_size_after_opening():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test16'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test16'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -221,14 +221,14 @@ def test_increasing_position_size_after_opening():
|
|||||||
|
|
||||||
def test_is_smart_enough_to_open_positions_via_market_orders():
|
def test_is_smart_enough_to_open_positions_via_market_orders():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_1, 'Test05'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_1, 'Test05'),
|
||||||
])
|
])
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
key = jh.key(exchanges.SANDBOX, 'ETHUSDT')
|
key = jh.key(exchanges.SANDBOX, 'ETH-USDT')
|
||||||
candles[key] = {
|
candles[key] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'ETHUSDT',
|
'symbol': 'ETH-USDT',
|
||||||
'candles': test_candles_1
|
'candles': test_candles_1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,14 +267,14 @@ def test_is_smart_enough_to_open_positions_via_market_orders():
|
|||||||
|
|
||||||
def test_is_smart_enough_to_open_positions_via_stop_orders():
|
def test_is_smart_enough_to_open_positions_via_stop_orders():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test06'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test06'),
|
||||||
])
|
])
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
key = jh.key(exchanges.SANDBOX, 'ETHUSDT')
|
key = jh.key(exchanges.SANDBOX, 'ETH-USDT')
|
||||||
candles[key] = {
|
candles[key] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'ETHUSDT',
|
'symbol': 'ETH-USDT',
|
||||||
'candles': test_candles_1
|
'candles': test_candles_1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +313,7 @@ def test_is_smart_enough_to_open_positions_via_stop_orders():
|
|||||||
|
|
||||||
def test_liquidate():
|
def test_liquidate():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test31'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test31'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -337,7 +337,7 @@ def test_liquidate():
|
|||||||
|
|
||||||
def test_modifying_stop_loss_after_part_of_position_is_already_reduced_with_stop_loss():
|
def test_modifying_stop_loss_after_part_of_position_is_already_reduced_with_stop_loss():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test14'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test14'),
|
||||||
])
|
])
|
||||||
|
|
||||||
generated_candles = fake_range_candle_from_range_prices(
|
generated_candles = fake_range_candle_from_range_prices(
|
||||||
@@ -345,10 +345,10 @@ def test_modifying_stop_loss_after_part_of_position_is_already_reduced_with_stop
|
|||||||
)
|
)
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
key = jh.key(exchanges.SANDBOX, 'BTCUSDT')
|
key = jh.key(exchanges.SANDBOX, 'BTC-USDT')
|
||||||
candles[key] = {
|
candles[key] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'BTCUSDT',
|
'symbol': 'BTC-USDT',
|
||||||
'candles': generated_candles
|
'candles': generated_candles
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +367,7 @@ def test_modifying_stop_loss_after_part_of_position_is_already_reduced_with_stop
|
|||||||
|
|
||||||
def test_modifying_take_profit_after_opening_position():
|
def test_modifying_take_profit_after_opening_position():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_5, 'Test12'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_5, 'Test12'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -385,7 +385,7 @@ def test_modifying_take_profit_after_opening_position():
|
|||||||
|
|
||||||
def test_modifying_take_profit_after_part_of_position_is_already_reduced_with_profit():
|
def test_modifying_take_profit_after_part_of_position_is_already_reduced_with_profit():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test13'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test13'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -403,8 +403,8 @@ def test_modifying_take_profit_after_part_of_position_is_already_reduced_with_pr
|
|||||||
|
|
||||||
def test_multiple_routes_can_communicate_with_each_other():
|
def test_multiple_routes_can_communicate_with_each_other():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test03'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test03'),
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_5, 'Test03'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_5, 'Test03'),
|
||||||
])
|
])
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
@@ -450,8 +450,8 @@ def test_multiple_routes_can_communicate_with_each_other():
|
|||||||
def test_must_not_be_able_to_set_two_similar_routes():
|
def test_must_not_be_able_to_set_two_similar_routes():
|
||||||
reset_config()
|
reset_config()
|
||||||
router.set_routes([
|
router.set_routes([
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test01'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test01'),
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_30, 'Test02'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_30, 'Test02'),
|
||||||
])
|
])
|
||||||
with pytest.raises(Exception) as err:
|
with pytest.raises(Exception) as err:
|
||||||
store.reset(True)
|
store.reset(True)
|
||||||
@@ -461,7 +461,7 @@ def test_must_not_be_able_to_set_two_similar_routes():
|
|||||||
|
|
||||||
def test_on_reduced_position():
|
def test_on_reduced_position():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test18'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test18'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -479,15 +479,15 @@ def test_on_reduced_position():
|
|||||||
|
|
||||||
def test_on_route_canceled():
|
def test_on_route_canceled():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test27'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test27'),
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_1, 'Test28'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_1, 'Test28'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
||||||
|
|
||||||
t1 = store.completed_trades.trades[0]
|
t1 = store.completed_trades.trades[0]
|
||||||
|
|
||||||
assert t1.symbol == 'BTCUSDT'
|
assert t1.symbol == 'BTC-USDT'
|
||||||
assert t1.type == 'long'
|
assert t1.type == 'long'
|
||||||
assert t1.entry_price == 101
|
assert t1.entry_price == 101
|
||||||
assert t1.exit_price == 120
|
assert t1.exit_price == 120
|
||||||
@@ -498,20 +498,20 @@ def test_on_route_canceled():
|
|||||||
|
|
||||||
def test_on_route_increased_position_and_on_route_reduced_position_and_strategy_vars():
|
def test_on_route_increased_position_and_on_route_reduced_position_and_strategy_vars():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test29'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test29'),
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_1, 'Test30'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_1, 'Test30'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
||||||
|
|
||||||
# long BTCUSD
|
# long BTC-USD
|
||||||
t1 = store.completed_trades.trades[0]
|
t1 = store.completed_trades.trades[0]
|
||||||
# short BTCUSD
|
# short BTC-USD
|
||||||
t2 = store.completed_trades.trades[1]
|
t2 = store.completed_trades.trades[1]
|
||||||
# long ETHUSD
|
# long ETH-USD
|
||||||
t3 = store.completed_trades.trades[2]
|
t3 = store.completed_trades.trades[2]
|
||||||
|
|
||||||
assert t1.symbol == 'BTCUSDT'
|
assert t1.symbol == 'BTC-USDT'
|
||||||
assert t1.type == 'long'
|
assert t1.type == 'long'
|
||||||
assert t1.entry_price == 121
|
assert t1.entry_price == 121
|
||||||
assert t1.exit_price == 131
|
assert t1.exit_price == 131
|
||||||
@@ -519,7 +519,7 @@ def test_on_route_increased_position_and_on_route_reduced_position_and_strategy_
|
|||||||
assert t1.qty == 1
|
assert t1.qty == 1
|
||||||
assert np.isnan(t1.stop_loss_at)
|
assert np.isnan(t1.stop_loss_at)
|
||||||
|
|
||||||
assert t2.symbol == 'BTCUSDT'
|
assert t2.symbol == 'BTC-USDT'
|
||||||
assert t2.type == 'short'
|
assert t2.type == 'short'
|
||||||
assert t2.entry_price == 151
|
assert t2.entry_price == 151
|
||||||
assert t2.exit_price == 161
|
assert t2.exit_price == 161
|
||||||
@@ -527,7 +527,7 @@ def test_on_route_increased_position_and_on_route_reduced_position_and_strategy_
|
|||||||
assert t2.qty == 1
|
assert t2.qty == 1
|
||||||
assert np.isnan(t2.take_profit_at)
|
assert np.isnan(t2.take_profit_at)
|
||||||
|
|
||||||
assert t3.symbol == 'ETHUSDT'
|
assert t3.symbol == 'ETH-USDT'
|
||||||
assert t3.type == 'long'
|
assert t3.type == 'long'
|
||||||
# because we open at 10, and increase at 20, entry is the mean which is 15
|
# because we open at 10, and increase at 20, entry is the mean which is 15
|
||||||
assert t3.entry_price == 15
|
assert t3.entry_price == 15
|
||||||
@@ -540,8 +540,8 @@ def test_on_route_increased_position_and_on_route_reduced_position_and_strategy_
|
|||||||
|
|
||||||
def test_on_route_open_position():
|
def test_on_route_open_position():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test21'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test21'),
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_1, 'Test22'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_1, 'Test22'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
||||||
@@ -549,7 +549,7 @@ def test_on_route_open_position():
|
|||||||
t1 = store.completed_trades.trades[0]
|
t1 = store.completed_trades.trades[0]
|
||||||
t2 = store.completed_trades.trades[1]
|
t2 = store.completed_trades.trades[1]
|
||||||
|
|
||||||
assert t1.symbol == 'BTCUSDT'
|
assert t1.symbol == 'BTC-USDT'
|
||||||
assert t1.type == 'long'
|
assert t1.type == 'long'
|
||||||
assert t1.entry_price == 101
|
assert t1.entry_price == 101
|
||||||
assert t1.exit_price == 110
|
assert t1.exit_price == 110
|
||||||
@@ -557,7 +557,7 @@ def test_on_route_open_position():
|
|||||||
assert t1.qty == 1
|
assert t1.qty == 1
|
||||||
assert np.isnan(t1.stop_loss_at)
|
assert np.isnan(t1.stop_loss_at)
|
||||||
|
|
||||||
assert t2.symbol == 'ETHUSDT'
|
assert t2.symbol == 'ETH-USDT'
|
||||||
assert t2.type == 'long'
|
assert t2.type == 'long'
|
||||||
assert t2.entry_price == 10
|
assert t2.entry_price == 10
|
||||||
assert t2.exit_price == 20
|
assert t2.exit_price == 20
|
||||||
@@ -568,8 +568,8 @@ def test_on_route_open_position():
|
|||||||
|
|
||||||
def test_on_route_stop_loss():
|
def test_on_route_stop_loss():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test25'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test25'),
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_1, 'Test26'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_1, 'Test26'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
||||||
@@ -577,7 +577,7 @@ def test_on_route_stop_loss():
|
|||||||
t1 = store.completed_trades.trades[0]
|
t1 = store.completed_trades.trades[0]
|
||||||
t2 = store.completed_trades.trades[1]
|
t2 = store.completed_trades.trades[1]
|
||||||
|
|
||||||
assert t2.symbol == 'BTCUSDT'
|
assert t2.symbol == 'BTC-USDT'
|
||||||
assert t2.type == 'long'
|
assert t2.type == 'long'
|
||||||
assert t2.entry_price == 101
|
assert t2.entry_price == 101
|
||||||
assert t2.exit_price == 120
|
assert t2.exit_price == 120
|
||||||
@@ -585,7 +585,7 @@ def test_on_route_stop_loss():
|
|||||||
assert t2.qty == 1
|
assert t2.qty == 1
|
||||||
assert np.isnan(t2.stop_loss_at)
|
assert np.isnan(t2.stop_loss_at)
|
||||||
|
|
||||||
assert t1.symbol == 'ETHUSDT'
|
assert t1.symbol == 'ETH-USDT'
|
||||||
assert t1.type == 'short'
|
assert t1.type == 'short'
|
||||||
assert t1.entry_price == 10
|
assert t1.entry_price == 10
|
||||||
assert t1.exit_price == 20
|
assert t1.exit_price == 20
|
||||||
@@ -596,8 +596,8 @@ def test_on_route_stop_loss():
|
|||||||
|
|
||||||
def test_on_route_take_profit():
|
def test_on_route_take_profit():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test23'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test23'),
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_1, 'Test24'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_1, 'Test24'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
||||||
@@ -605,7 +605,7 @@ def test_on_route_take_profit():
|
|||||||
t1 = store.completed_trades.trades[0]
|
t1 = store.completed_trades.trades[0]
|
||||||
t2 = store.completed_trades.trades[1]
|
t2 = store.completed_trades.trades[1]
|
||||||
|
|
||||||
assert t2.symbol == 'BTCUSDT'
|
assert t2.symbol == 'BTC-USDT'
|
||||||
assert t2.type == 'long'
|
assert t2.type == 'long'
|
||||||
assert t2.entry_price == 101
|
assert t2.entry_price == 101
|
||||||
assert t2.exit_price == 120
|
assert t2.exit_price == 120
|
||||||
@@ -613,7 +613,7 @@ def test_on_route_take_profit():
|
|||||||
assert t2.qty == 1
|
assert t2.qty == 1
|
||||||
assert np.isnan(t2.stop_loss_at)
|
assert np.isnan(t2.stop_loss_at)
|
||||||
|
|
||||||
assert t1.symbol == 'ETHUSDT'
|
assert t1.symbol == 'ETH-USDT'
|
||||||
assert t1.type == 'long'
|
assert t1.type == 'long'
|
||||||
assert t1.entry_price == 10
|
assert t1.entry_price == 10
|
||||||
assert t1.exit_price == 20
|
assert t1.exit_price == 20
|
||||||
@@ -624,7 +624,7 @@ def test_on_route_take_profit():
|
|||||||
|
|
||||||
def test_opening_position_in_multiple_points():
|
def test_opening_position_in_multiple_points():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test15'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test15'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -642,7 +642,7 @@ def test_opening_position_in_multiple_points():
|
|||||||
|
|
||||||
def test_reducing_position_size_after_opening():
|
def test_reducing_position_size_after_opening():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test17'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test17'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -660,15 +660,15 @@ def test_reducing_position_size_after_opening():
|
|||||||
|
|
||||||
def test_shared_vars():
|
def test_shared_vars():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test32'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test32'),
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_1, 'Test33'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_1, 'Test33'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_and_eth_candles())
|
||||||
|
|
||||||
t1 = store.completed_trades.trades[0]
|
t1 = store.completed_trades.trades[0]
|
||||||
|
|
||||||
assert t1.symbol == 'ETHUSDT'
|
assert t1.symbol == 'ETH-USDT'
|
||||||
assert t1.type == 'long'
|
assert t1.type == 'long'
|
||||||
assert t1.entry_price == 11
|
assert t1.entry_price == 11
|
||||||
assert t1.exit_price == 21
|
assert t1.exit_price == 21
|
||||||
@@ -679,7 +679,7 @@ def test_shared_vars():
|
|||||||
|
|
||||||
def test_should_buy_and_execute_buy():
|
def test_should_buy_and_execute_buy():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test01'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test01'),
|
||||||
])
|
])
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
@@ -724,7 +724,7 @@ def test_should_buy_and_execute_buy():
|
|||||||
|
|
||||||
def test_should_sell_and_execute_sell():
|
def test_should_sell_and_execute_sell():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test02'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test02'),
|
||||||
])
|
])
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
@@ -762,7 +762,7 @@ def test_should_sell_and_execute_sell():
|
|||||||
|
|
||||||
def test_stop_loss_at_multiple_points():
|
def test_stop_loss_at_multiple_points():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'Test11'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test11'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -780,8 +780,8 @@ def test_stop_loss_at_multiple_points():
|
|||||||
|
|
||||||
def test_strategy_properties():
|
def test_strategy_properties():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_5, 'Test19'),
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_5, 'Test19'),
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_5, 'Test19'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_5, 'Test19'),
|
||||||
])
|
])
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
@@ -815,7 +815,7 @@ def test_strategy_properties():
|
|||||||
|
|
||||||
def test_taking_profit_at_multiple_points():
|
def test_taking_profit_at_multiple_points():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_5, 'Test10'),
|
(exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_5, 'Test10'),
|
||||||
])
|
])
|
||||||
|
|
||||||
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
backtest_mode.run('2019-04-01', '2019-04-02', get_btc_candles())
|
||||||
@@ -859,20 +859,20 @@ def test_terminate_closes_trades_at_the_end_of_backtest():
|
|||||||
|
|
||||||
assert {
|
assert {
|
||||||
'time': 1552315246171.0,
|
'time': 1552315246171.0,
|
||||||
'message': 'Closed open Sandbox-BTCUSDT position at 99.0 with PNL: 97.0(4850.0%) because we reached the end of the backtest session.'
|
'message': 'Closed open Sandbox-BTC-USDT position at 99.0 with PNL: 97.0(4850.0%) because we reached the end of the backtest session.'
|
||||||
} in store.logs.info
|
} in store.logs.info
|
||||||
|
|
||||||
|
|
||||||
def test_updating_stop_loss_and_take_profit_after_opening_the_position():
|
def test_updating_stop_loss_and_take_profit_after_opening_the_position():
|
||||||
set_up([
|
set_up([
|
||||||
(exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_1, 'Test07')
|
(exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_1, 'Test07')
|
||||||
])
|
])
|
||||||
|
|
||||||
candles = {}
|
candles = {}
|
||||||
key = jh.key(exchanges.SANDBOX, 'ETHUSDT')
|
key = jh.key(exchanges.SANDBOX, 'ETH-USDT')
|
||||||
candles[key] = {
|
candles[key] = {
|
||||||
'exchange': exchanges.SANDBOX,
|
'exchange': exchanges.SANDBOX,
|
||||||
'symbol': 'ETHUSDT',
|
'symbol': 'ETH-USDT',
|
||||||
'candles': test_candles_1
|
'candles': test_candles_1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -934,8 +934,8 @@ def test_after():
|
|||||||
# def test_route_capital_isolation():
|
# def test_route_capital_isolation():
|
||||||
# set_up(
|
# set_up(
|
||||||
# [
|
# [
|
||||||
# (exchanges.SANDBOX, 'BTCUSDT', timeframes.MINUTE_1, 'TestRouteCapitalIsolation1'),
|
# (exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'TestRouteCapitalIsolation1'),
|
||||||
# (exchanges.SANDBOX, 'ETHUSDT', timeframes.MINUTE_1, 'TestRouteCapitalIsolation2'),
|
# (exchanges.SANDBOX, 'ETH-USDT', timeframes.MINUTE_1, 'TestRouteCapitalIsolation2'),
|
||||||
# ],
|
# ],
|
||||||
# )
|
# )
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ def set_up():
|
|||||||
reset_config()
|
reset_config()
|
||||||
config['app']['considering_exchanges'] = [exchanges.SANDBOX]
|
config['app']['considering_exchanges'] = [exchanges.SANDBOX]
|
||||||
config['app']['trading_exchanges'] = [exchanges.SANDBOX]
|
config['app']['trading_exchanges'] = [exchanges.SANDBOX]
|
||||||
config['app']['trading_symbols'] = ['BTCUSD']
|
config['app']['trading_symbols'] = ['BTC-USD']
|
||||||
config['app']['trading_timeframes'] = ['5m']
|
config['app']['trading_timeframes'] = ['5m']
|
||||||
store.reset()
|
store.reset()
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ def set_up():
|
|||||||
def test_close_position():
|
def test_close_position():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 50,
|
'entry_price': 50,
|
||||||
'current_price': 50,
|
'current_price': 50,
|
||||||
'qty': 2,
|
'qty': 2,
|
||||||
@@ -34,7 +34,7 @@ def test_close_position():
|
|||||||
def test_increase_a_long_position():
|
def test_increase_a_long_position():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 50,
|
'entry_price': 50,
|
||||||
'current_price': 50,
|
'current_price': 50,
|
||||||
'qty': 2,
|
'qty': 2,
|
||||||
@@ -49,7 +49,7 @@ def test_increase_a_long_position():
|
|||||||
def test_increase_a_short_position():
|
def test_increase_a_short_position():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 50,
|
'entry_price': 50,
|
||||||
'current_price': 50,
|
'current_price': 50,
|
||||||
'qty': -2,
|
'qty': -2,
|
||||||
@@ -62,13 +62,13 @@ def test_increase_a_short_position():
|
|||||||
|
|
||||||
|
|
||||||
def test_initiating_position():
|
def test_initiating_position():
|
||||||
position = Position(exchanges.SANDBOX, 'BTCUSD', {
|
position = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'current_price': 100,
|
'current_price': 100,
|
||||||
'qty': 0
|
'qty': 0
|
||||||
})
|
})
|
||||||
|
|
||||||
assert position.exchange_name == 'Sandbox'
|
assert position.exchange_name == 'Sandbox'
|
||||||
assert position.symbol == 'BTCUSD'
|
assert position.symbol == 'BTC-USD'
|
||||||
assert position.current_price == 100
|
assert position.current_price == 100
|
||||||
assert position.qty == 0
|
assert position.qty == 0
|
||||||
assert position.closed_at is None
|
assert position.closed_at is None
|
||||||
@@ -80,7 +80,7 @@ def test_initiating_position():
|
|||||||
def test_is_able_to_close_via_reduce_postion_too():
|
def test_is_able_to_close_via_reduce_postion_too():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 50,
|
'entry_price': 50,
|
||||||
'current_price': 50,
|
'current_price': 50,
|
||||||
'qty': 2,
|
'qty': 2,
|
||||||
@@ -94,7 +94,7 @@ def test_is_able_to_close_via_reduce_postion_too():
|
|||||||
def test_open_position():
|
def test_open_position():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD')
|
p = Position(exchanges.SANDBOX, 'BTC-USD')
|
||||||
|
|
||||||
assert p.qty == 0
|
assert p.qty == 0
|
||||||
assert p.entry_price is None
|
assert p.entry_price is None
|
||||||
@@ -109,7 +109,7 @@ def test_open_position():
|
|||||||
|
|
||||||
|
|
||||||
def test_position_is_close():
|
def test_position_is_close():
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 50,
|
'entry_price': 50,
|
||||||
'current_price': 60,
|
'current_price': 60,
|
||||||
'qty': 0,
|
'qty': 0,
|
||||||
@@ -121,7 +121,7 @@ def test_position_is_close():
|
|||||||
|
|
||||||
|
|
||||||
def test_position_is_open():
|
def test_position_is_open():
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 50,
|
'entry_price': 50,
|
||||||
'current_price': 60,
|
'current_price': 60,
|
||||||
'qty': 2,
|
'qty': 2,
|
||||||
@@ -134,7 +134,7 @@ def test_position_is_open():
|
|||||||
|
|
||||||
def test_position_pnl():
|
def test_position_pnl():
|
||||||
# long winning position
|
# long winning position
|
||||||
p1: Position = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p1: Position = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 100,
|
'entry_price': 100,
|
||||||
'current_price': 110,
|
'current_price': 110,
|
||||||
'qty': 2,
|
'qty': 2,
|
||||||
@@ -142,7 +142,7 @@ def test_position_pnl():
|
|||||||
assert p1.pnl == 20
|
assert p1.pnl == 20
|
||||||
|
|
||||||
# long losing position
|
# long losing position
|
||||||
p2: Position = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p2: Position = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 100,
|
'entry_price': 100,
|
||||||
'current_price': 90,
|
'current_price': 90,
|
||||||
'qty': 2,
|
'qty': 2,
|
||||||
@@ -150,7 +150,7 @@ def test_position_pnl():
|
|||||||
assert p2.pnl == -20
|
assert p2.pnl == -20
|
||||||
|
|
||||||
# short winning position
|
# short winning position
|
||||||
p3: Position = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p3: Position = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 100,
|
'entry_price': 100,
|
||||||
'current_price': 90,
|
'current_price': 90,
|
||||||
'qty': -2,
|
'qty': -2,
|
||||||
@@ -158,7 +158,7 @@ def test_position_pnl():
|
|||||||
assert p3.pnl == 20
|
assert p3.pnl == 20
|
||||||
|
|
||||||
# short losing position
|
# short losing position
|
||||||
p3: Position = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p3: Position = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 100,
|
'entry_price': 100,
|
||||||
'current_price': 110,
|
'current_price': 110,
|
||||||
'qty': -2,
|
'qty': -2,
|
||||||
@@ -167,7 +167,7 @@ def test_position_pnl():
|
|||||||
|
|
||||||
|
|
||||||
def test_position_pnl_percentage():
|
def test_position_pnl_percentage():
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 50,
|
'entry_price': 50,
|
||||||
'current_price': 60,
|
'current_price': 60,
|
||||||
'qty': 2,
|
'qty': 2,
|
||||||
@@ -187,13 +187,13 @@ def test_position_pnl_percentage():
|
|||||||
|
|
||||||
|
|
||||||
def test_position_type():
|
def test_position_type():
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {'current_price': 100, 'qty': 0})
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {'current_price': 100, 'qty': 0})
|
||||||
assert p.type == 'close'
|
assert p.type == 'close'
|
||||||
|
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {'current_price': 100, 'qty': 1})
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {'current_price': 100, 'qty': 1})
|
||||||
assert p.type == 'long'
|
assert p.type == 'long'
|
||||||
|
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'current_price': 100,
|
'current_price': 100,
|
||||||
'qty': -1
|
'qty': -1
|
||||||
})
|
})
|
||||||
@@ -201,8 +201,8 @@ def test_position_type():
|
|||||||
|
|
||||||
|
|
||||||
def test_position_value():
|
def test_position_value():
|
||||||
long_position = Position(exchanges.SANDBOX, 'BTCUSD', {'current_price': 100, 'qty': 1})
|
long_position = Position(exchanges.SANDBOX, 'BTC-USD', {'current_price': 100, 'qty': 1})
|
||||||
short_position = Position(exchanges.SANDBOX, 'BTCUSD', {'current_price': 100, 'qty': -1})
|
short_position = Position(exchanges.SANDBOX, 'BTC-USD', {'current_price': 100, 'qty': -1})
|
||||||
|
|
||||||
assert long_position.value == 100
|
assert long_position.value == 100
|
||||||
assert short_position.value == 100
|
assert short_position.value == 100
|
||||||
@@ -211,7 +211,7 @@ def test_position_value():
|
|||||||
def test_reduce_a_long_position():
|
def test_reduce_a_long_position():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 50,
|
'entry_price': 50,
|
||||||
'current_price': 50,
|
'current_price': 50,
|
||||||
'qty': 2,
|
'qty': 2,
|
||||||
@@ -225,7 +225,7 @@ def test_reduce_a_long_position():
|
|||||||
def test_reduce_a_short_position():
|
def test_reduce_a_short_position():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
p = Position(exchanges.SANDBOX, 'BTCUSD', {
|
p = Position(exchanges.SANDBOX, 'BTC-USD', {
|
||||||
'entry_price': 50,
|
'entry_price': 50,
|
||||||
'current_price': 50,
|
'current_price': 50,
|
||||||
'qty': -2,
|
'qty': -2,
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ from jesse.store import store
|
|||||||
def test_routes():
|
def test_routes():
|
||||||
# re-define routes
|
# re-define routes
|
||||||
router.set_routes([
|
router.set_routes([
|
||||||
(exchanges.BITFINEX, 'ETHUSD', timeframes.HOUR_3, 'Test19'),
|
(exchanges.BITFINEX, 'ETH-USD', timeframes.HOUR_3, 'Test19'),
|
||||||
(exchanges.SANDBOX, 'BTCUSD', timeframes.MINUTE_15, 'Test19'),
|
(exchanges.SANDBOX, 'BTC-USD', timeframes.MINUTE_15, 'Test19'),
|
||||||
])
|
])
|
||||||
|
|
||||||
router.set_extra_candles([
|
router.set_extra_candles([
|
||||||
(exchanges.BITFINEX, 'EOSUSD', timeframes.HOUR_3),
|
(exchanges.BITFINEX, 'EOS-USD', timeframes.HOUR_3),
|
||||||
(exchanges.BITFINEX, 'EOSUSD', timeframes.HOUR_1),
|
(exchanges.BITFINEX, 'EOS-USD', timeframes.HOUR_1),
|
||||||
])
|
])
|
||||||
|
|
||||||
# reset store for new routes to take affect
|
# reset store for new routes to take affect
|
||||||
@@ -21,9 +21,9 @@ def test_routes():
|
|||||||
|
|
||||||
# now assert it's working as expected
|
# now assert it's working as expected
|
||||||
assert set(config['app']['trading_exchanges']) == set([exchanges.SANDBOX, exchanges.BITFINEX])
|
assert set(config['app']['trading_exchanges']) == set([exchanges.SANDBOX, exchanges.BITFINEX])
|
||||||
assert set(config['app']['trading_symbols']) == set(['BTCUSD', 'ETHUSD'])
|
assert set(config['app']['trading_symbols']) == set(['BTC-USD', 'ETH-USD'])
|
||||||
assert set(config['app']['trading_timeframes']) == set([timeframes.HOUR_3, timeframes.MINUTE_15])
|
assert set(config['app']['trading_timeframes']) == set([timeframes.HOUR_3, timeframes.MINUTE_15])
|
||||||
assert set(config['app']['considering_exchanges']) == set([exchanges.SANDBOX, exchanges.BITFINEX])
|
assert set(config['app']['considering_exchanges']) == set([exchanges.SANDBOX, exchanges.BITFINEX])
|
||||||
assert set(config['app']['considering_symbols']) == set(['BTCUSD', 'ETHUSD', 'EOSUSD'])
|
assert set(config['app']['considering_symbols']) == set(['BTC-USD', 'ETH-USD', 'EOS-USD'])
|
||||||
assert set(config['app']['considering_timeframes']) == set(
|
assert set(config['app']['considering_timeframes']) == set(
|
||||||
[timeframes.MINUTE_1, timeframes.HOUR_3, timeframes.MINUTE_15, timeframes.HOUR_1])
|
[timeframes.MINUTE_1, timeframes.HOUR_3, timeframes.MINUTE_15, timeframes.HOUR_1])
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ def set_up():
|
|||||||
"""
|
"""
|
||||||
reset_config()
|
reset_config()
|
||||||
config['app']['considering_timeframes'] = ['1m', '5m']
|
config['app']['considering_timeframes'] = ['1m', '5m']
|
||||||
config['app']['considering_symbols'] = ['BTCUSD']
|
config['app']['considering_symbols'] = ['BTC-USD']
|
||||||
config['app']['considering_exchanges'] = ['Sandbox']
|
config['app']['considering_exchanges'] = ['Sandbox']
|
||||||
store.reset()
|
store.reset()
|
||||||
store.candles.init_storage()
|
store.candles.init_storage()
|
||||||
@@ -21,74 +21,74 @@ def set_up():
|
|||||||
def test_batch_add_candles():
|
def test_batch_add_candles():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
assert len(store.candles.get_candles('Sandbox', 'BTCUSD', '1m')) == 0
|
assert len(store.candles.get_candles('Sandbox', 'BTC-USD', '1m')) == 0
|
||||||
|
|
||||||
# create 100 candles
|
# create 100 candles
|
||||||
candles_to_add = fake_range_candle(100)
|
candles_to_add = fake_range_candle(100)
|
||||||
assert len(candles_to_add) == 100
|
assert len(candles_to_add) == 100
|
||||||
|
|
||||||
store.candles.batch_add_candle(candles_to_add, 'Sandbox', 'BTCUSD', '1m')
|
store.candles.batch_add_candle(candles_to_add, 'Sandbox', 'BTC-USD', '1m')
|
||||||
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m'), candles_to_add)
|
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTC-USD', '1m'), candles_to_add)
|
||||||
|
|
||||||
|
|
||||||
def test_can_add_new_candle():
|
def test_can_add_new_candle():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m'), np.zeros((0, 6)))
|
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTC-USD', '1m'), np.zeros((0, 6)))
|
||||||
|
|
||||||
c1 = fake_candle()
|
c1 = fake_candle()
|
||||||
store.candles.add_candle(c1, 'Sandbox', 'BTCUSD', '1m')
|
store.candles.add_candle(c1, 'Sandbox', 'BTC-USD', '1m')
|
||||||
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m')[0], c1)
|
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTC-USD', '1m')[0], c1)
|
||||||
# try to add duplicate
|
# try to add duplicate
|
||||||
store.candles.add_candle(c1, 'Sandbox', 'BTCUSD', '1m')
|
store.candles.add_candle(c1, 'Sandbox', 'BTC-USD', '1m')
|
||||||
# assert to make sure it's the same
|
# assert to make sure it's the same
|
||||||
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m')[0], c1)
|
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTC-USD', '1m')[0], c1)
|
||||||
|
|
||||||
c2 = fake_candle()
|
c2 = fake_candle()
|
||||||
store.candles.add_candle(c2, 'Sandbox', 'BTCUSD', '1m')
|
store.candles.add_candle(c2, 'Sandbox', 'BTC-USD', '1m')
|
||||||
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m'), np.array([c1, c2]))
|
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTC-USD', '1m'), np.array([c1, c2]))
|
||||||
|
|
||||||
|
|
||||||
def test_can_update_candle():
|
def test_can_update_candle():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTCUSD', '1m'), np.zeros((0, 6)))
|
np.testing.assert_equal(store.candles.get_candles('Sandbox', 'BTC-USD', '1m'), np.zeros((0, 6)))
|
||||||
|
|
||||||
# add it
|
# add it
|
||||||
c1 = fake_candle()
|
c1 = fake_candle()
|
||||||
store.candles.add_candle(c1, 'Sandbox', 'BTCUSD', '1m')
|
store.candles.add_candle(c1, 'Sandbox', 'BTC-USD', '1m')
|
||||||
np.testing.assert_equal(store.candles.get_current_candle('Sandbox', 'BTCUSD', '1m'), c1)
|
np.testing.assert_equal(store.candles.get_current_candle('Sandbox', 'BTC-USD', '1m'), c1)
|
||||||
|
|
||||||
# now update it with another candle which has the same timestamp
|
# now update it with another candle which has the same timestamp
|
||||||
c2 = c1.copy()
|
c2 = c1.copy()
|
||||||
c2[1] = 1000
|
c2[1] = 1000
|
||||||
store.candles.add_candle(c2, 'Sandbox', 'BTCUSD', '1m')
|
store.candles.add_candle(c2, 'Sandbox', 'BTC-USD', '1m')
|
||||||
np.testing.assert_equal(store.candles.get_current_candle('Sandbox', 'BTCUSD', '1m'), c2)
|
np.testing.assert_equal(store.candles.get_current_candle('Sandbox', 'BTC-USD', '1m'), c2)
|
||||||
assert len(store.candles.get_candles('Sandbox', 'BTCUSD', '1m')) == 1
|
assert len(store.candles.get_candles('Sandbox', 'BTC-USD', '1m')) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_get_candles_including_forming():
|
def test_get_candles_including_forming():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
candles_to_add = fake_range_candle(14)
|
candles_to_add = fake_range_candle(14)
|
||||||
store.candles.batch_add_candle(candles_to_add, 'Sandbox', 'BTCUSD', '1m')
|
store.candles.batch_add_candle(candles_to_add, 'Sandbox', 'BTC-USD', '1m')
|
||||||
store.candles.add_candle(
|
store.candles.add_candle(
|
||||||
generate_candle_from_one_minutes(
|
generate_candle_from_one_minutes(
|
||||||
'5m', candles_to_add[0:5], False
|
'5m', candles_to_add[0:5], False
|
||||||
),
|
),
|
||||||
'Sandbox', 'BTCUSD', '5m'
|
'Sandbox', 'BTC-USD', '5m'
|
||||||
)
|
)
|
||||||
store.candles.add_candle(
|
store.candles.add_candle(
|
||||||
generate_candle_from_one_minutes(
|
generate_candle_from_one_minutes(
|
||||||
'5m', candles_to_add[5:10], False
|
'5m', candles_to_add[5:10], False
|
||||||
),
|
),
|
||||||
'Sandbox', 'BTCUSD', '5m'
|
'Sandbox', 'BTC-USD', '5m'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(store.candles.get_candles('Sandbox', 'BTCUSD', '5m')) == 3
|
assert len(store.candles.get_candles('Sandbox', 'BTC-USD', '5m')) == 3
|
||||||
assert len(store.candles.get_candles('Sandbox', 'BTCUSD', '1m')) == 14
|
assert len(store.candles.get_candles('Sandbox', 'BTC-USD', '1m')) == 14
|
||||||
|
|
||||||
candles = store.candles.get_candles('Sandbox', 'BTCUSD', '5m')
|
candles = store.candles.get_candles('Sandbox', 'BTC-USD', '5m')
|
||||||
assert candles[0][0] == candles_to_add[0][0]
|
assert candles[0][0] == candles_to_add[0][0]
|
||||||
assert candles[-1][2] == candles_to_add[13][2]
|
assert candles[-1][2] == candles_to_add[13][2]
|
||||||
assert candles[-1][0] == candles_to_add[10][0]
|
assert candles[-1][0] == candles_to_add[10][0]
|
||||||
@@ -100,29 +100,29 @@ def test_get_candles_including_forming():
|
|||||||
generate_candle_from_one_minutes(
|
generate_candle_from_one_minutes(
|
||||||
'5m', candles_to_add[10:14], True
|
'5m', candles_to_add[10:14], True
|
||||||
),
|
),
|
||||||
'Sandbox', 'BTCUSD', '5m'
|
'Sandbox', 'BTC-USD', '5m'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(store.candles.get_candles('Sandbox', 'BTCUSD', '5m')) == 3
|
assert len(store.candles.get_candles('Sandbox', 'BTC-USD', '5m')) == 3
|
||||||
assert candles[-1][2] == candles_to_add[13][2]
|
assert candles[-1][2] == candles_to_add[13][2]
|
||||||
assert candles[-1][0] == candles_to_add[10][0]
|
assert candles[-1][0] == candles_to_add[10][0]
|
||||||
def test_get_forming_candle():
|
def test_get_forming_candle():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
candles_to_add = fake_range_candle(13)
|
candles_to_add = fake_range_candle(13)
|
||||||
store.candles.batch_add_candle(candles_to_add[0:4], 'Sandbox', 'BTCUSD', '1m')
|
store.candles.batch_add_candle(candles_to_add[0:4], 'Sandbox', 'BTC-USD', '1m')
|
||||||
forming_candle = store.candles.get_current_candle('Sandbox', 'BTCUSD', '5m')
|
forming_candle = store.candles.get_current_candle('Sandbox', 'BTC-USD', '5m')
|
||||||
assert forming_candle[0] == candles_to_add[0][0]
|
assert forming_candle[0] == candles_to_add[0][0]
|
||||||
assert forming_candle[1] == candles_to_add[0][1]
|
assert forming_candle[1] == candles_to_add[0][1]
|
||||||
assert forming_candle[2] == candles_to_add[3][2]
|
assert forming_candle[2] == candles_to_add[3][2]
|
||||||
|
|
||||||
# add the rest of 1m candles
|
# add the rest of 1m candles
|
||||||
store.candles.batch_add_candle(candles_to_add[4:], 'Sandbox', 'BTCUSD', '1m')
|
store.candles.batch_add_candle(candles_to_add[4:], 'Sandbox', 'BTC-USD', '1m')
|
||||||
# add 5m candles
|
# add 5m candles
|
||||||
store.candles.batch_add_candle(candles_to_add[0:5], 'Sandbox', 'BTCUSD', '5m')
|
store.candles.batch_add_candle(candles_to_add[0:5], 'Sandbox', 'BTC-USD', '5m')
|
||||||
store.candles.batch_add_candle(candles_to_add[5:10], 'Sandbox', 'BTCUSD', '5m')
|
store.candles.batch_add_candle(candles_to_add[5:10], 'Sandbox', 'BTC-USD', '5m')
|
||||||
|
|
||||||
forming_candle = store.candles.get_current_candle('Sandbox', 'BTCUSD', '5m')
|
forming_candle = store.candles.get_current_candle('Sandbox', 'BTC-USD', '5m')
|
||||||
assert forming_candle[0] == candles_to_add[10][0]
|
assert forming_candle[0] == candles_to_add[10][0]
|
||||||
assert forming_candle[1] == candles_to_add[10][1]
|
assert forming_candle[1] == candles_to_add[10][1]
|
||||||
assert forming_candle[2] == candles_to_add[12][2]
|
assert forming_candle[2] == candles_to_add[12][2]
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ def set_up():
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
reset_config()
|
reset_config()
|
||||||
config['app']['considering_candles'] = [('Sandbox', 'BTCUSD')]
|
config['app']['considering_candles'] = [('Sandbox', 'BTC-USD')]
|
||||||
store.reset()
|
store.reset()
|
||||||
store.orderbooks.init_storage()
|
store.orderbooks.init_storage()
|
||||||
|
|
||||||
@@ -51,24 +51,24 @@ def test_add_orderbook_and_orderbook_getters():
|
|||||||
[6280.56, 0.085], [6277.79, 0.01], [6246.4, 0.01], [6220.0, 200.0], [6215.16, 0.01], [6184.08, 0.01],
|
[6280.56, 0.085], [6277.79, 0.01], [6246.4, 0.01], [6220.0, 200.0], [6215.16, 0.01], [6184.08, 0.01],
|
||||||
[6153.15, 0.01], [6122.38, 0.01], [6091.76, 0.01], [6061.3, 0.01], [6030.99, 0.01], [6021.0, 30.0],
|
[6153.15, 0.01], [6122.38, 0.01], [6091.76, 0.01], [6061.3, 0.01], [6030.99, 0.01], [6021.0, 30.0],
|
||||||
[6000.83, 0.01], [6000.0, 16.701]]
|
[6000.83, 0.01], [6000.0, 16.701]]
|
||||||
store.orderbooks.add_orderbook('Sandbox', 'BTCUSD', asks, bids)
|
store.orderbooks.add_orderbook('Sandbox', 'BTC-USD', asks, bids)
|
||||||
|
|
||||||
# test get_best_ask
|
# test get_best_ask
|
||||||
np.testing.assert_equal(
|
np.testing.assert_equal(
|
||||||
store.orderbooks.get_best_ask('Sandbox', 'BTCUSD'),
|
store.orderbooks.get_best_ask('Sandbox', 'BTC-USD'),
|
||||||
np.array(
|
np.array(
|
||||||
[9189.0, 52.66]
|
[9189.0, 52.66]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# test get_current_asks
|
# test get_current_asks
|
||||||
np.testing.assert_equal(
|
np.testing.assert_equal(
|
||||||
store.orderbooks.get_current_asks('Sandbox', 'BTCUSD')[0],
|
store.orderbooks.get_current_asks('Sandbox', 'BTC-USD')[0],
|
||||||
np.array(
|
np.array(
|
||||||
[9189.0, 52.66]
|
[9189.0, 52.66]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
np.testing.assert_equal(
|
np.testing.assert_equal(
|
||||||
store.orderbooks.get_current_asks('Sandbox', 'BTCUSD')[1],
|
store.orderbooks.get_current_asks('Sandbox', 'BTC-USD')[1],
|
||||||
np.array(
|
np.array(
|
||||||
[9190.0, 27.58]
|
[9190.0, 27.58]
|
||||||
)
|
)
|
||||||
@@ -76,20 +76,20 @@ def test_add_orderbook_and_orderbook_getters():
|
|||||||
|
|
||||||
# test get_best_bid
|
# test get_best_bid
|
||||||
np.testing.assert_equal(
|
np.testing.assert_equal(
|
||||||
store.orderbooks.get_best_bid('Sandbox', 'BTCUSD'),
|
store.orderbooks.get_best_bid('Sandbox', 'BTC-USD'),
|
||||||
np.array(
|
np.array(
|
||||||
[9188.0, 53.43]
|
[9188.0, 53.43]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# test get_current_bids
|
# test get_current_bids
|
||||||
np.testing.assert_equal(
|
np.testing.assert_equal(
|
||||||
store.orderbooks.get_current_bids('Sandbox', 'BTCUSD')[0],
|
store.orderbooks.get_current_bids('Sandbox', 'BTC-USD')[0],
|
||||||
np.array(
|
np.array(
|
||||||
[9188.0, 53.43]
|
[9188.0, 53.43]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
np.testing.assert_equal(
|
np.testing.assert_equal(
|
||||||
store.orderbooks.get_current_bids('Sandbox', 'BTCUSD')[1],
|
store.orderbooks.get_current_bids('Sandbox', 'BTC-USD')[1],
|
||||||
np.array(
|
np.array(
|
||||||
[9187.0, 21.68]
|
[9187.0, 21.68]
|
||||||
)
|
)
|
||||||
@@ -97,7 +97,7 @@ def test_add_orderbook_and_orderbook_getters():
|
|||||||
|
|
||||||
# test get_current_orderbook
|
# test get_current_orderbook
|
||||||
np.testing.assert_equal(
|
np.testing.assert_equal(
|
||||||
store.orderbooks.get_current_orderbook('Sandbox', 'BTCUSD')[0][0],
|
store.orderbooks.get_current_orderbook('Sandbox', 'BTC-USD')[0][0],
|
||||||
np.array(
|
np.array(
|
||||||
[9189.0, 52.66]
|
[9189.0, 52.66]
|
||||||
)
|
)
|
||||||
@@ -105,7 +105,7 @@ def test_add_orderbook_and_orderbook_getters():
|
|||||||
|
|
||||||
# test get_orderbooks
|
# test get_orderbooks
|
||||||
np.testing.assert_equal(
|
np.testing.assert_equal(
|
||||||
store.orderbooks.get_orderbooks('Sandbox', 'BTCUSD')[-1][0][0],
|
store.orderbooks.get_orderbooks('Sandbox', 'BTC-USD')[-1][0][0],
|
||||||
np.array(
|
np.array(
|
||||||
[9189.0, 52.66]
|
[9189.0, 52.66]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,18 +10,18 @@ def set_up():
|
|||||||
"""
|
"""
|
||||||
reset_config()
|
reset_config()
|
||||||
config['app']['trading_exchanges'] = [exchanges.SANDBOX, exchanges.BITFINEX]
|
config['app']['trading_exchanges'] = [exchanges.SANDBOX, exchanges.BITFINEX]
|
||||||
config['app']['trading_symbols'] = ['BTCUSD', 'ETHUSD']
|
config['app']['trading_symbols'] = ['BTC-USD', 'ETH-USD']
|
||||||
store.reset()
|
store.reset()
|
||||||
|
|
||||||
|
|
||||||
def test_add_new_order():
|
def test_add_new_order():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
o1 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETHUSD'})
|
o1 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETH-USD'})
|
||||||
o2 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETHUSD'})
|
o2 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETH-USD'})
|
||||||
store.orders.add_order(o1)
|
store.orders.add_order(o1)
|
||||||
store.orders.add_order(o2)
|
store.orders.add_order(o2)
|
||||||
assert store.orders.storage['Sandbox-ETHUSD'] == [o1, o2]
|
assert store.orders.storage['Sandbox-ETH-USD'] == [o1, o2]
|
||||||
|
|
||||||
|
|
||||||
def test_order_state_init():
|
def test_order_state_init():
|
||||||
@@ -33,38 +33,37 @@ def test_order_state_init():
|
|||||||
def test_state_order_count():
|
def test_state_order_count():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
assert store.orders.count(exchanges.SANDBOX, 'BTCUSD') == 0
|
assert store.orders.count(exchanges.SANDBOX, 'BTC-USD') == 0
|
||||||
store.orders.add_order(fake_order())
|
store.orders.add_order(fake_order())
|
||||||
assert store.orders.count(exchanges.SANDBOX, 'BTCUSD') == 1
|
assert store.orders.count(exchanges.SANDBOX, 'BTC-USD') == 1
|
||||||
store.orders.add_order(fake_order())
|
store.orders.add_order(fake_order())
|
||||||
assert store.orders.count(exchanges.SANDBOX, 'BTCUSD') == 2
|
assert store.orders.count(exchanges.SANDBOX, 'BTC-USD') == 2
|
||||||
|
|
||||||
|
|
||||||
def test_state_order_get_order_by_id():
|
def test_state_order_get_order_by_id():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
o0 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETHUSD'})
|
o0 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETH-USD'})
|
||||||
o1 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETHUSD'})
|
o1 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETH-USD'})
|
||||||
o2 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETHUSD'})
|
o2 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETH-USD'})
|
||||||
|
|
||||||
store.orders.get_order_by_id(exchanges.SANDBOX, 'ETHUSD', o2.id)
|
store.orders.get_order_by_id(exchanges.SANDBOX, 'ETH-USD', o2.id)
|
||||||
|
|
||||||
# return None if does not exist
|
# return None if does not exist
|
||||||
assert store.orders.get_order_by_id(exchanges.SANDBOX, 'ETHUSD',
|
assert store.orders.get_order_by_id(exchanges.SANDBOX, 'ETH-USD',
|
||||||
o0.id) == None
|
o0.id) == None
|
||||||
|
|
||||||
store.orders.add_order(o1)
|
store.orders.add_order(o1)
|
||||||
store.orders.add_order(o2)
|
store.orders.add_order(o2)
|
||||||
assert store.orders.get_order_by_id(exchanges.SANDBOX, 'ETHUSD',
|
assert store.orders.get_order_by_id(exchanges.SANDBOX, 'ETH-USD',
|
||||||
o2.id) == o2
|
o2.id) == o2
|
||||||
def test_state_order_get_orders():
|
def test_state_order_get_orders():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
o1 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETHUSD'})
|
o1 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETH-USD'})
|
||||||
o2 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETHUSD'})
|
o2 = fake_order({'exchange': exchanges.SANDBOX, 'symbol': 'ETH-USD'})
|
||||||
store.orders.add_order(o1)
|
store.orders.add_order(o1)
|
||||||
store.orders.add_order(o2)
|
store.orders.add_order(o2)
|
||||||
assert store.orders.get_orders(exchanges.SANDBOX,
|
assert store.orders.get_orders(exchanges.SANDBOX,'ETH-USD') == [o1, o2]
|
||||||
'ETHUSD') == [o1, o2]
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ def set_up():
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
reset_config()
|
reset_config()
|
||||||
config['app']['considering_candles'] = [('Sandbox', 'BTCUSD')]
|
config['app']['considering_candles'] = [('Sandbox', 'BTC-USD')]
|
||||||
store.reset()
|
store.reset()
|
||||||
store.tickers.init_storage()
|
store.tickers.init_storage()
|
||||||
|
|
||||||
@@ -18,20 +18,20 @@ def set_up():
|
|||||||
def test_can_add_new_ticker():
|
def test_can_add_new_ticker():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
np.testing.assert_equal(store.tickers.get_tickers('Sandbox', 'BTCUSD'), np.zeros((0, 5)))
|
np.testing.assert_equal(store.tickers.get_tickers('Sandbox', 'BTC-USD'), np.zeros((0, 5)))
|
||||||
|
|
||||||
# add first ticker
|
# add first ticker
|
||||||
t1 = np.array([jh.now_to_timestamp(), 1, 2, 3, 4], dtype=np.float64)
|
t1 = np.array([jh.now_to_timestamp(), 1, 2, 3, 4], dtype=np.float64)
|
||||||
store.tickers.add_ticker(t1, 'Sandbox', 'BTCUSD')
|
store.tickers.add_ticker(t1, 'Sandbox', 'BTC-USD')
|
||||||
np.testing.assert_equal(store.tickers.get_tickers('Sandbox', 'BTCUSD')[0], t1)
|
np.testing.assert_equal(store.tickers.get_tickers('Sandbox', 'BTC-USD')[0], t1)
|
||||||
|
|
||||||
# fake 1 second
|
# fake 1 second
|
||||||
store.app.time += 1000
|
store.app.time += 1000
|
||||||
|
|
||||||
# add second ticker
|
# add second ticker
|
||||||
t2 = np.array([jh.now_to_timestamp() + 1, 11, 22, 33, 44], dtype=np.float64)
|
t2 = np.array([jh.now_to_timestamp() + 1, 11, 22, 33, 44], dtype=np.float64)
|
||||||
store.tickers.add_ticker(t2, 'Sandbox', 'BTCUSD')
|
store.tickers.add_ticker(t2, 'Sandbox', 'BTC-USD')
|
||||||
np.testing.assert_equal(store.tickers.get_tickers('Sandbox', 'BTCUSD'), np.array([t1, t2]))
|
np.testing.assert_equal(store.tickers.get_tickers('Sandbox', 'BTC-USD'), np.array([t1, t2]))
|
||||||
|
|
||||||
|
|
||||||
def test_get_current_and_past_ticker():
|
def test_get_current_and_past_ticker():
|
||||||
@@ -42,17 +42,17 @@ def test_get_current_and_past_ticker():
|
|||||||
t2 = np.array([jh.now_to_timestamp() + 1000, 2, 2, 3, 4], dtype=np.float64)
|
t2 = np.array([jh.now_to_timestamp() + 1000, 2, 2, 3, 4], dtype=np.float64)
|
||||||
t3 = np.array([jh.now_to_timestamp() + 2000, 3, 2, 3, 4], dtype=np.float64)
|
t3 = np.array([jh.now_to_timestamp() + 2000, 3, 2, 3, 4], dtype=np.float64)
|
||||||
t4 = np.array([jh.now_to_timestamp() + 3000, 4, 2, 3, 4], dtype=np.float64)
|
t4 = np.array([jh.now_to_timestamp() + 3000, 4, 2, 3, 4], dtype=np.float64)
|
||||||
store.tickers.add_ticker(t1, 'Sandbox', 'BTCUSD')
|
store.tickers.add_ticker(t1, 'Sandbox', 'BTC-USD')
|
||||||
store.app.time += 1000
|
store.app.time += 1000
|
||||||
store.tickers.add_ticker(t2, 'Sandbox', 'BTCUSD')
|
store.tickers.add_ticker(t2, 'Sandbox', 'BTC-USD')
|
||||||
store.app.time += 1000
|
store.app.time += 1000
|
||||||
store.tickers.add_ticker(t3, 'Sandbox', 'BTCUSD')
|
store.tickers.add_ticker(t3, 'Sandbox', 'BTC-USD')
|
||||||
store.app.time += 1000
|
store.app.time += 1000
|
||||||
store.tickers.add_ticker(t4, 'Sandbox', 'BTCUSD')
|
store.tickers.add_ticker(t4, 'Sandbox', 'BTC-USD')
|
||||||
np.testing.assert_equal(store.tickers.get_tickers('Sandbox', 'BTCUSD'), np.array([t1, t2, t3, t4]))
|
np.testing.assert_equal(store.tickers.get_tickers('Sandbox', 'BTC-USD'), np.array([t1, t2, t3, t4]))
|
||||||
|
|
||||||
# get the previous one
|
# get the previous one
|
||||||
np.testing.assert_equal(store.tickers.get_past_ticker('Sandbox', 'BTCUSD', 1), t3)
|
np.testing.assert_equal(store.tickers.get_past_ticker('Sandbox', 'BTC-USD', 1), t3)
|
||||||
|
|
||||||
# get current
|
# get current
|
||||||
np.testing.assert_equal(store.tickers.get_current_ticker('Sandbox', 'BTCUSD'), t4)
|
np.testing.assert_equal(store.tickers.get_current_ticker('Sandbox', 'BTC-USD'), t4)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ def set_up():
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
reset_config()
|
reset_config()
|
||||||
config['app']['considering_candles'] = [('Sandbox', 'BTCUSD')]
|
config['app']['considering_candles'] = [('Sandbox', 'BTC-USD')]
|
||||||
store.reset()
|
store.reset()
|
||||||
store.trades.init_storage()
|
store.trades.init_storage()
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ def set_up():
|
|||||||
def test_can_add_add_trade():
|
def test_can_add_add_trade():
|
||||||
set_up()
|
set_up()
|
||||||
|
|
||||||
np.testing.assert_equal(store.trades.get_trades('Sandbox', 'BTCUSD'), np.zeros((0, 6)))
|
np.testing.assert_equal(store.trades.get_trades('Sandbox', 'BTC-USD'), np.zeros((0, 6)))
|
||||||
|
|
||||||
# add first trade
|
# add first trade
|
||||||
t1 = np.array([jh.now_to_timestamp(), 100, 2, 1], dtype=np.float64)
|
t1 = np.array([jh.now_to_timestamp(), 100, 2, 1], dtype=np.float64)
|
||||||
@@ -26,20 +26,20 @@ def test_can_add_add_trade():
|
|||||||
t3 = np.array([jh.now_to_timestamp(), 98, 2, 0], dtype=np.float64)
|
t3 = np.array([jh.now_to_timestamp(), 98, 2, 0], dtype=np.float64)
|
||||||
t4 = np.array([jh.now_to_timestamp(), 98, 2, 0], dtype=np.float64)
|
t4 = np.array([jh.now_to_timestamp(), 98, 2, 0], dtype=np.float64)
|
||||||
t5 = np.array([jh.now_to_timestamp(), 98, 2, 0], dtype=np.float64)
|
t5 = np.array([jh.now_to_timestamp(), 98, 2, 0], dtype=np.float64)
|
||||||
store.trades.add_trade(t1, 'Sandbox', 'BTCUSD')
|
store.trades.add_trade(t1, 'Sandbox', 'BTC-USD')
|
||||||
store.trades.add_trade(t2, 'Sandbox', 'BTCUSD')
|
store.trades.add_trade(t2, 'Sandbox', 'BTC-USD')
|
||||||
store.trades.add_trade(t3, 'Sandbox', 'BTCUSD')
|
store.trades.add_trade(t3, 'Sandbox', 'BTC-USD')
|
||||||
store.trades.add_trade(t4, 'Sandbox', 'BTCUSD')
|
store.trades.add_trade(t4, 'Sandbox', 'BTC-USD')
|
||||||
store.trades.add_trade(t5, 'Sandbox', 'BTCUSD')
|
store.trades.add_trade(t5, 'Sandbox', 'BTC-USD')
|
||||||
|
|
||||||
assert len(store.trades.get_trades('Sandbox', 'BTCUSD')) == 0
|
assert len(store.trades.get_trades('Sandbox', 'BTC-USD')) == 0
|
||||||
|
|
||||||
t6 = np.array([jh.now_to_timestamp() + 1000, 98, 2, 1], dtype=np.float64)
|
t6 = np.array([jh.now_to_timestamp() + 1000, 98, 2, 1], dtype=np.float64)
|
||||||
store.trades.add_trade(t6, 'Sandbox', 'BTCUSD')
|
store.trades.add_trade(t6, 'Sandbox', 'BTC-USD')
|
||||||
|
|
||||||
assert len(store.trades.get_trades('Sandbox', 'BTCUSD')) == 1
|
assert len(store.trades.get_trades('Sandbox', 'BTC-USD')) == 1
|
||||||
|
|
||||||
np.testing.assert_equal(store.trades.get_current_trade('Sandbox', 'BTCUSD'), np.array([
|
np.testing.assert_equal(store.trades.get_current_trade('Sandbox', 'BTC-USD'), np.array([
|
||||||
jh.now_to_timestamp(),
|
jh.now_to_timestamp(),
|
||||||
# price
|
# price
|
||||||
(100 * 2 + 98 * 2 + 98 * 2 + 98 * 2 + 98 * 2) / 10,
|
(100 * 2 + 98 * 2 + 98 * 2 + 98 * 2 + 98 * 2) / 10,
|
||||||
@@ -55,9 +55,9 @@ def test_can_add_add_trade():
|
|||||||
|
|
||||||
# add another after two seconds
|
# add another after two seconds
|
||||||
t7 = np.array([jh.now_to_timestamp() + 3000, 98, 2, 1], dtype=np.float64)
|
t7 = np.array([jh.now_to_timestamp() + 3000, 98, 2, 1], dtype=np.float64)
|
||||||
store.trades.add_trade(t7, 'Sandbox', 'BTCUSD')
|
store.trades.add_trade(t7, 'Sandbox', 'BTC-USD')
|
||||||
|
|
||||||
np.testing.assert_equal(store.trades.get_current_trade('Sandbox', 'BTCUSD'), np.array([
|
np.testing.assert_equal(store.trades.get_current_trade('Sandbox', 'BTC-USD'), np.array([
|
||||||
jh.now_to_timestamp() + 1000,
|
jh.now_to_timestamp() + 1000,
|
||||||
# price
|
# price
|
||||||
98,
|
98,
|
||||||
@@ -72,7 +72,7 @@ def test_can_add_add_trade():
|
|||||||
]))
|
]))
|
||||||
|
|
||||||
# test get_past_trade
|
# test get_past_trade
|
||||||
np.testing.assert_equal(store.trades.get_past_trade('Sandbox', 'BTCUSD', 1), np.array([
|
np.testing.assert_equal(store.trades.get_past_trade('Sandbox', 'BTC-USD', 1), np.array([
|
||||||
jh.now_to_timestamp(),
|
jh.now_to_timestamp(),
|
||||||
# price
|
# price
|
||||||
(100 * 2 + 98 * 2 + 98 * 2 + 98 * 2 + 98 * 2) / 10,
|
(100 * 2 + 98 * 2 + 98 * 2 + 98 * 2 + 98 * 2) / 10,
|
||||||
@@ -87,7 +87,7 @@ def test_can_add_add_trade():
|
|||||||
]))
|
]))
|
||||||
|
|
||||||
# test get_trades
|
# test get_trades
|
||||||
np.testing.assert_equal(store.trades.get_trades('Sandbox', 'BTCUSD'), np.array([
|
np.testing.assert_equal(store.trades.get_trades('Sandbox', 'BTC-USD'), np.array([
|
||||||
[
|
[
|
||||||
jh.now_to_timestamp(),
|
jh.now_to_timestamp(),
|
||||||
# price
|
# price
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ def test_can_add_trade_to_store():
|
|||||||
'stop_loss_at': 5,
|
'stop_loss_at': 5,
|
||||||
'qty': 1,
|
'qty': 1,
|
||||||
'orders': [],
|
'orders': [],
|
||||||
'symbol': 'BTCUSD',
|
'symbol': 'BTC-USD',
|
||||||
'opened_at': 1552309186171,
|
'opened_at': 1552309186171,
|
||||||
'closed_at': 1552309186171 + 60000
|
'closed_at': 1552309186171 + 60000
|
||||||
})
|
})
|
||||||
@@ -53,7 +53,7 @@ def test_holding_period():
|
|||||||
'stop_loss_at': 5,
|
'stop_loss_at': 5,
|
||||||
'qty': 1,
|
'qty': 1,
|
||||||
'orders': [],
|
'orders': [],
|
||||||
'symbol': 'BTCUSD',
|
'symbol': 'BTC-USD',
|
||||||
'opened_at': 1552309186171,
|
'opened_at': 1552309186171,
|
||||||
'closed_at': 1552309186171 + 60000
|
'closed_at': 1552309186171 + 60000
|
||||||
})
|
})
|
||||||
@@ -74,7 +74,7 @@ def test_PNL_percentage():
|
|||||||
'stop_loss_at': 5,
|
'stop_loss_at': 5,
|
||||||
'qty': 1,
|
'qty': 1,
|
||||||
'orders': [],
|
'orders': [],
|
||||||
'symbol': 'BTCUSD',
|
'symbol': 'BTC-USD',
|
||||||
'opened_at': jh.now_to_timestamp(),
|
'opened_at': jh.now_to_timestamp(),
|
||||||
'closed_at': jh.now_to_timestamp()
|
'closed_at': jh.now_to_timestamp()
|
||||||
})
|
})
|
||||||
@@ -94,7 +94,7 @@ def test_PNL_with_fee():
|
|||||||
'stop_loss_at': 5,
|
'stop_loss_at': 5,
|
||||||
'qty': 1,
|
'qty': 1,
|
||||||
'orders': [],
|
'orders': [],
|
||||||
'symbol': 'BTCUSD',
|
'symbol': 'BTC-USD',
|
||||||
'opened_at': jh.now_to_timestamp(),
|
'opened_at': jh.now_to_timestamp(),
|
||||||
'closed_at': jh.now_to_timestamp()
|
'closed_at': jh.now_to_timestamp()
|
||||||
})
|
})
|
||||||
@@ -115,7 +115,7 @@ def test_PNL_without_fee():
|
|||||||
'stop_loss_at': 5,
|
'stop_loss_at': 5,
|
||||||
'qty': 1,
|
'qty': 1,
|
||||||
'orders': [],
|
'orders': [],
|
||||||
'symbol': 'BTCUSD',
|
'symbol': 'BTC-USD',
|
||||||
'opened_at': jh.now_to_timestamp(),
|
'opened_at': jh.now_to_timestamp(),
|
||||||
'closed_at': jh.now_to_timestamp()
|
'closed_at': jh.now_to_timestamp()
|
||||||
})
|
})
|
||||||
@@ -134,7 +134,7 @@ def test_R():
|
|||||||
'stop_loss_at': 5,
|
'stop_loss_at': 5,
|
||||||
'qty': 1,
|
'qty': 1,
|
||||||
'orders': [],
|
'orders': [],
|
||||||
'symbol': 'BTCUSD',
|
'symbol': 'BTC-USD',
|
||||||
'opened_at': jh.now_to_timestamp(),
|
'opened_at': jh.now_to_timestamp(),
|
||||||
'closed_at': jh.now_to_timestamp()
|
'closed_at': jh.now_to_timestamp()
|
||||||
})
|
})
|
||||||
@@ -153,7 +153,7 @@ def test_risk_percentage():
|
|||||||
'stop_loss_at': 5,
|
'stop_loss_at': 5,
|
||||||
'qty': 1,
|
'qty': 1,
|
||||||
'orders': [],
|
'orders': [],
|
||||||
'symbol': 'BTCUSD',
|
'symbol': 'BTC-USD',
|
||||||
'opened_at': jh.now_to_timestamp(),
|
'opened_at': jh.now_to_timestamp(),
|
||||||
'closed_at': jh.now_to_timestamp()
|
'closed_at': jh.now_to_timestamp()
|
||||||
})
|
})
|
||||||
@@ -170,7 +170,7 @@ def test_trade_size():
|
|||||||
'stop_loss_at': 5,
|
'stop_loss_at': 5,
|
||||||
'qty': 1,
|
'qty': 1,
|
||||||
'orders': [],
|
'orders': [],
|
||||||
'symbol': 'BTCUSD',
|
'symbol': 'BTC-USD',
|
||||||
'opened_at': jh.now_to_timestamp(),
|
'opened_at': jh.now_to_timestamp(),
|
||||||
'closed_at': jh.now_to_timestamp()
|
'closed_at': jh.now_to_timestamp()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user