Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
node_modules
__pycache__
jsconfig.json
.eslintrc.js
^\.*
*.md
.vscode
.devcontainer
.ini
.git
.github
.gitignore
.github/
docs/
ecosystem.config.js
.http
mongo_data
mongo_data.old
mongo_db
kafka_data
.DS_Store
.env.local
.env.prod
.env.development.local
.env.test.local
/.env
.vscode/settings.json
.venv/
.DS_Store
*.pyc
api/main/config/*.cfg
.mypy_cache
db.dump
.pytest_cache
tests/
*.md
!.dockerignore
!.gitignore
10 changes: 2 additions & 8 deletions algorithms/coinrule.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os

from shared.utils import round_numbers
from models.signals import SignalsConsumer
from shared.enums import KafkaTopics
from shared.utils import round_numbers


def fast_and_slow_macd(
Expand All @@ -20,13 +20,7 @@ def fast_and_slow_macd(
bb_high, bb_mid, bb_low = self.bb_spreads()

# If volatility is too low, dynamic trailling will close too early with bb_spreads
if (
macd > macd_signal
and ma_7 > ma_25
and bb_high < 1
and bb_high > 0.001
and trend
):
if macd > macd_signal and ma_7 > ma_25 and bb_high < 1 and bb_high > 0.001:
msg = f"""
- [{os.getenv('ENV')}] <strong>{algo} #algorithm</strong> #{symbol}
- Current price: {close_price}
Expand Down
3 changes: 2 additions & 1 deletion algorithms/ma_candlestick.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os

from models.signals import SignalsConsumer
from shared.enums import KafkaTopics
from shared.utils import round_numbers
from models.signals import SignalsConsumer

# Algorithms based on Bollinguer bands

Expand Down
29 changes: 13 additions & 16 deletions algorithms/price_changes.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,47 @@
import os

from shared.utils import round_numbers
from models.signals import SignalsConsumer
from shared.enums import KafkaTopics


def price_rise_15(
self,
close_price,
symbol,
run_autotrade,
prev_price,
p_value,
r_value,
btc_correlation
volatility
btc_correlation,
):
"""
Price increase/decrease algorithm

https://www.binance.com/en/support/faq/understanding-top-movers-statuses-on-binance-spot-trading-18c97e8ab67a4e1b824edd590cae9f16
"""

algo = "price_rise_15_rally_pullback"
price_diff = (float(close_price) - float(prev_price)) / close_price
volatility = round_numbers(volatility)
bb_high, bb_mid, bb_low = self.bb_spreads()
trend = self.define_strategy()

if 0.07 <= price_diff < 0.11:
first_line = "<strong>Price increase</strong> over 7%"

elif -0.07 <= price_diff < -0.11 :
elif -0.07 <= price_diff < -0.11:
first_line = f"<strong>{algo} #algorithm</strong> over 7%"

else:
return


msg = (f"""
msg = f"""
- [{os.getenv('ENV')}] {first_line} #{symbol}
- Current price: {close_price}
- Log volatility (log SD): {volatility}
- P-value: {p_value}
- Pearson correlation with BTC: {btc_correlation["close_price"]}
- https://www.binance.com/en/trade/{symbol}
- <a href='http://terminal.binbot.in/bots/new/{symbol}'>Dashboard trade</a>
""")
"""

value = SignalsConsumer(
spread=volatility,
current_price=close_price,
msg=msg,
symbol=symbol,
Expand All @@ -58,9 +51,13 @@ def price_rise_15(
"bb_high": bb_high,
"bb_mid": bb_mid,
"bb_low": bb_low,
}
},
)

self.producer.send(KafkaTopics.signals.value, value=value.model_dump_json()).add_callback(self.base_producer.on_send_success).add_errback(self.base_producer.on_send_error)
self.producer.send(
KafkaTopics.signals.value, value=value.model_dump_json()
).add_callback(self.base_producer.on_send_success).add_errback(
self.base_producer.on_send_error
)

return
94 changes: 43 additions & 51 deletions algorithms/rally.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from api.streaming.models import SignalsConsumer

from shared.enums import KafkaTopics
from models.signals import SignalsConsumer


def rally_or_pullback(
Expand All @@ -19,6 +20,8 @@ def rally_or_pullback(
"""
Rally algorithm

Key difference with other algorithms is the trend is determined not by market
but day or minute percentage change
https://www.binance.com/en/support/faq/understanding-top-movers-statuses-on-binance-spot-trading-18c97e8ab67a4e1b824edd590cae9f16
"""
data = self.get_24_ticker(symbol)
Expand All @@ -39,62 +42,51 @@ def rally_or_pullback(

if day_diff <= 0.08 and minute_diff >= 0.05:
algo_type = "Rally"
# trend = "uptrend"

if day_diff_pb >= 0.08 and minute_diff_pb <= 0.05:
algo_type = "Pullback"
# trend = "downtrend"

if not algo_type:
return

trend = self.define_strategy()
if not trend:
return

bb_high, bb_mid, bb_low = self.bb_spreads()

msg = f"""
- [{os.getenv('ENV')}] <strong>{algo_type} #algorithm</strong> #{symbol}
- Current price: {close_price}
- Log volatility (log SD): {volatility}
- Bollinguer bands spread: {(bb_high - bb_low) / bb_high }
- Reversal? {"Yes" if self.market_domination_reversal else "No"}
- https://www.binance.com/en/trade/{symbol}
- <a href='http://terminal.binbot.in/bots/new/{symbol}'>Dashboard trade</a>
"""

if algo_type == "Pullback":
algo = f"rally_{algo_type}"

if (
float(close_price) > float(open_price)
and volatility > 0.09
# and close_price < ma_25[len(ma_25) - 1]
# and close_price < ma_25[len(ma_25) - 2]
# and close_price < ma_25[len(ma_25) - 3]
and close_price < ma_100[len(ma_100) - 1]
and close_price < ma_100[len(ma_100) - 2]
and close_price < ma_100[len(ma_100) - 3]
):
value = SignalsConsumer(
spread=None,
current_price=close_price,
msg=msg,
symbol=symbol,
algo=algo,
trend=trend,
bb_spreads={
"bb_high": bb_high,
"bb_mid": bb_mid,
"bb_low": bb_low,
},
)

self.producer.send(
KafkaTopics.signals.value, value=value.model_dump_json()
).add_callback(self.base_producer.on_send_success).add_errback(
self.base_producer.on_send_error
)
if (
close_price < ma_25[len(ma_25) - 1]
and close_price < ma_25[len(ma_25) - 2]
and close_price < ma_25[len(ma_25) - 3]
and close_price < ma_100[len(ma_100) - 1]
and close_price < ma_100[len(ma_100) - 2]
and close_price < ma_100[len(ma_100) - 3]
):
bb_high, bb_mid, bb_low = self.bb_spreads()

msg = f"""
- [{os.getenv('ENV')}] <strong>{algo_type} #algorithm</strong> #{symbol}
- Current price: {close_price}
- Log volatility (log SD): {volatility}
- Bollinguer bands spread: {(bb_high - bb_low) / bb_high }
- Reversal? {"Yes" if self.market_domination_reversal else "No"}
- https://www.binance.com/en/trade/{symbol}
- <a href='http://terminal.binbot.in/bots/new/{symbol}'>Dashboard trade</a>
"""

value = SignalsConsumer(
spread=None,
current_price=close_price,
msg=msg,
symbol=symbol,
algo=algo_type,
trend=volatility,
bb_spreads={
"bb_high": bb_high,
"bb_mid": bb_mid,
"bb_low": bb_low,
},
)

self.producer.send(
KafkaTopics.signals.value, value=value.model_dump_json()
).add_callback(self.base_producer.on_send_success).add_errback(
self.base_producer.on_send_error
)

return
7 changes: 1 addition & 6 deletions algorithms/timeseries_gpt.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import json
import os
import pandas as pd
from shared.enums import KafkaTopics
from shared.utils import round_numbers
from models.signals import SignalsConsumer
from shared.enums import KafkaTopics

from nixtla import NixtlaClient

nixtla_client = NixtlaClient(os.environ.get("NIXTLA_API_KEY"))
Expand Down
63 changes: 34 additions & 29 deletions algorithms/top_gainer_drop.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import os

from shared.enums import KafkaTopics
from models.signals import SignalsConsumer
from shared.enums import KafkaTopics, TrendEnum


def top_gainers_drop(
self,
cls,
close_price,
open_price,
ma_7,
ma_100,
ma_25,
symbol,
lowest_price,
slope,
ma_100,
ma_7_prev,
ma_25_prev,
ma_100_prev,
volatility,
):
"""
Expand All @@ -21,34 +21,39 @@ def top_gainers_drop(
so create margin_short bot

"""
if float(close_price) < float(open_price) and symbol in self.top_coins_gainers:
if float(close_price) < float(open_price) and cls.symbol in cls.top_coins_gainers:
algo = "top_gainers_drop"

trend = self.define_strategy(self)
trend = cls.define_strategy()
if not trend:
return
trend = TrendEnum.down_trend

bb_high, bb_mid, bb_low = cls.bb_spreads()

msg = f"""
- [{os.getenv('ENV')}] Top gainers's drop <strong>#{algo} algorithm</strong> #{symbol}
- Current price: {close_price}
- Log volatility (log SD): {volatility}
- Slope: {slope}
- https://www.binance.com/en/trade/{symbol}
- <a href='http://terminal.binbot.in/bots/new/{symbol}'>Dashboard trade</a>
"""
value = {
"msg": msg,
"symbol": symbol,
"algo": algo,
"spread": volatility,
"current_price": close_price,
"trend": trend,
}

self.producer.send(
- [{os.getenv('ENV')}] Top gainers's drop <strong>#{algo} algorithm</strong> #{cls.symbol}
- Current price: {close_price}
- Log volatility (log SD): {volatility}
- Bollinguer bands spread: {(bb_high - bb_low) / bb_high }
- Reversal? {"Yes" if cls.market_domination_reversal else "No"}
- https://www.binance.com/en/trade/{cls.symbol}
- <a href='http://terminal.binbot.in/bots/new/{cls.symbol}'>Dashboard trade</a>
"""

value = SignalsConsumer(
spread=volatility,
current_price=close_price,
msg=msg,
symbol=cls.symbol,
algo=algo,
trend=trend,
bb_spreads=None,
)

cls.producer.send(
KafkaTopics.signals.value, value=value.model_dump_json()
).add_callback(self.base_producer.on_send_success).add_errback(
self.base_producer.on_send_error
).add_callback(cls.base_producer.on_send_success).add_errback(
cls.base_producer.on_send_error
)

return
Loading
Loading