Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jesse-ai/jesse
Browse files Browse the repository at this point in the history
  • Loading branch information
kakulukia committed Apr 6, 2024
2 parents 8e805c8 + 6065d12 commit 4a957db
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 20 deletions.
21 changes: 6 additions & 15 deletions jesse/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,21 +1034,12 @@ def get_candle_start_timestamp_based_on_timeframe(timeframe: str, num_candles_to
return finish_date - (num_candles_to_fetch * one_min_count * 60_000)


def is_price_near(order_price, price_to_compare):
def is_price_near(order_price, price_to_compare, percentage_threshold=0.0001):
"""
Check if given order price is near the specified price.
This function checks a range of price values and applies the associated threshold.
:param order_price: float
:param price_to_compare: float
:return: bool
Check if the given order price is near the specified price.
Default percentage_threshold is 0.01% (0.0001)
We calculate percentage difference between the two prices rounded to 4 decimal places,
so low-priced orders can be properly compared within 0.01% range.
"""
# Define the price ranges and associated thresholds
conditions = [order_price < 0.01, order_price < 1, order_price < 100, order_price < 10000, order_price >= 10000]
threshold_ratios = [0.015, 0.01, 0.005, 0.001, 0.0001]

# Use np.select to choose the threshold ratio based on the conditions
threshold_ratio = np.select(conditions, threshold_ratios)
return round(abs(1 - (order_price / price_to_compare)), 4) <= percentage_threshold

threshold = threshold_ratio * order_price
return abs(order_price - price_to_compare) <= threshold
42 changes: 42 additions & 0 deletions jesse/indicators/ma.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,48 @@ def ma(candles: np.ndarray, period: int = 30, matype: int = 0, source_type: str
:param sequential: bool - default: False
:return: float | np.ndarray
0: sma (simple)
1: ema (exponential)
2: wma (weighted)
3: dema (double exponential)
4: tema (triple exponential)
5: trima (triangular)
6: kama (Kaufman adaptive)
7: mama (Mesa adaptive)
8: T3 (triple exponential T3)
9: fwma (Fibonacci's Weighted Moving Average)
10: hma (Hull Moving Average)
11: linearreg (Linear Regression)
12: wilders (Wilders Smoothing)
13: sinwma (Sine Weighted Moving Average)
14: supersmoother (Super Smoother Filter 2pole Butterworth)
15: supersmoother\_3\_pole(Super Smoother Filter 3pole Butterworth)
16: gauss (Gaussian Filter)
17: high\_pass (1-pole High Pass Filter by John F. Ehlers)
18: high\_pass\_2\_pole (2-pole High Pass Filter by John F. Ehlers)
19: ht\_trendline (Hilbert Transform - Instantaneous Trendline)
20: jma (Jurik Moving Average)
21: reflex (Reflex indicator by John F. Ehlers)
22: trendflex (Trendflex indicator by John F. Ehlers)
23: smma (Smoothed Moving Average)
24: vwma (Volume Weighted Moving Average)
25: pwma (Pascals Weighted Moving Average)
26: swma (Symmetric Weighted Moving Average)
27: alma (Arnaud Legoux Moving Average)
28: hwma (Holt-Winter Moving Average)
29: vwap (Volume weighted average price)
30: nma (Natural Moving Average)
31: edcf (Ehlers Distance Coefficient Filter)
32: mwdx (MWDX Average)
33: maaq (Moving Average Adaptive Q)
34: srwma (Square Root Weighted Moving Average)
35: sqwma (Square Weighted Moving Average)
36: vpwma (Variable Power Weighted Moving Average)
37: cwma (Cubed Weighted Moving Average)
38: jsa (Jsa Moving Average)
39: epma (End Point Moving Average)
"""

candles = slice_candles(candles, sequential)
Expand Down
2 changes: 1 addition & 1 deletion jesse/modes/optimize_mode/Optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def evolve(self) -> list:
self.generate_initial_population()

if len(self.population) < 0.5 * self.population_size:
msg = f'Too many errors! less than half of the expected population size could be generated. Only {len(self.population)} indviduals from planned {self.population_size} are usable.'
msg = f'Too many errors! less than half of the expected population size could be generated. Only {len(self.population)} individuals from planned {self.population_size} are usable.'
logger.log_optimize_mode(msg)
raise ValueError(msg)

Expand Down
2 changes: 1 addition & 1 deletion jesse/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.46.0'
__version__ = '0.46.1'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

# also change in version.py
VERSION = '0.46.0'
VERSION = '0.46.1'
DESCRIPTION = "A trading framework for cryptocurrencies"
with open("requirements.txt", "r", encoding="utf-8") as f:
REQUIRED_PACKAGES = f.read().splitlines()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_stop_loss():
assert position.entry_price == 50
assert position.qty == 1
assert exchange.available_margin == 950
# even executed orders should not affect wallet_balance unless it's for reducing positon
# even executed orders should not affect wallet_balance unless it's for reducing position
assert exchange.wallet_balance == 1000

order = broker.reduce_position_at(1, 40, 50)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ def test_round_or_none():

def test_is_price_near():
assert jh.is_price_near(0.007386, 0.007385) == True
assert jh.is_price_near(0.007386, 0.007396) == True
assert jh.is_price_near(0.007386, 0.007396) == False
assert jh.is_price_near(0.0250, 0.0249) == False
assert jh.is_price_near(60000, 60000) == True
assert jh.is_price_near(60000, 60000.1) == True
assert jh.is_price_near(60000, 60100) == False
Expand Down

0 comments on commit 4a957db

Please sign in to comment.