Skip to content

Commit

Permalink
Merge pull request #1155 from Drakkar-Software/dev
Browse files Browse the repository at this point in the history
Dev merge
  • Loading branch information
GuillaumeDSM authored Jan 10, 2024
2 parents 31d44dd + b2f56cb commit e92b36c
Show file tree
Hide file tree
Showing 33 changed files with 217 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Triggers on a Telegram signal from any channel your personal account joined.

Signal parsing is configurable according to the name of the channel.

See [OctoBot docs about Telegram API service](https://www.octobot.cloud/guides/octobot-interfaces/telegram/telegram-api?utm_source=octobot&utm_medium=dk&utm_campaign=regular_open_source_content&utm_content=telegramChannelSignalEvaluator) for more information.
See [OctoBot docs about Telegram API service](https://www.octobot.cloud/en/guides/octobot-interfaces/telegram/telegram-api?utm_source=octobot&utm_medium=dk&utm_campaign=regular_open_source_content&utm_content=telegramChannelSignalEvaluator) for more information.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Remember that OctoBot can only see messages from a
chat/group where its Telegram bot (in OctoBot configuration) has been invited. Keep also in mind that you
need to disable the privacy mode of your Telegram bot to allow it to see group messages.

See [OctoBot docs about Telegram interface](https://www.octobot.cloud/guides/octobot-interfaces/telegram?utm_source=octobot&utm_medium=dk&utm_campaign=regular_open_source_content&utm_content=telegramSignalEvaluator) for more information.
See [OctoBot docs about Telegram interface](https://www.octobot.cloud/en/guides/octobot-interfaces/telegram?utm_source=octobot&utm_medium=dk&utm_campaign=regular_open_source_content&utm_content=telegramSignalEvaluator) for more information.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<meta name="robots" content="noindex">

<!-- Favicon -->
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.png') }}">

{% block additional_meta %}
{% endblock additional_meta %}
Expand Down
1 change: 1 addition & 0 deletions Services/Interfaces/web_interface/models/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
for result, merged in (
(ccxt.async_support.kucoin, (ccxt.async_support.kucoinfutures, )),
(ccxt.async_support.binance, (ccxt.async_support.binanceusdm, ccxt.async_support.binancecoinm)),
(ccxt.async_support.htx, (ccxt.async_support.huobi, )),
)
}
REMOVED_CCXT_EXCHANGES = set().union(*(set(v) for v in MERGED_CCXT_EXCHANGES.values()))
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Services/Interfaces/web_interface/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<meta name="robots" content="noindex">

<!-- Favicon -->
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.png') }}">

{% block additional_meta %}
{% endblock additional_meta %}
Expand Down
29 changes: 19 additions & 10 deletions Services/Services_bases/gpt_service/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import octobot_services.constants as services_constants
import octobot_services.services as services
import octobot_services.errors as errors
import octobot_services.util

import octobot_commons.enums as commons_enums
import octobot_commons.constants as commons_constants
import octobot_commons.time_frame_manager as time_frame_manager
import octobot_commons.authentication as authentication
import octobot_commons.tree as tree
Expand All @@ -33,6 +33,9 @@
import octobot.community as community


octobot_services.util.patch_openai_proxies()


class GPTService(services.AbstractService):
BACKTESTING_ENABLED = True
DEFAULT_MODEL = "gpt-3.5-turbo"
Expand Down Expand Up @@ -92,6 +95,9 @@ async def get_chat_completion(
return await self._fetch_signal_from_stored_signals(exchange, symbol, time_frame, version, candle_open_time)
return await self._get_signal_from_gpt(messages, model, max_tokens, n, stop, temperature)

def _get_client(self) -> openai.AsyncOpenAI:
return openai.AsyncOpenAI(api_key=self._get_api_key())

async def _get_signal_from_gpt(
self,
messages,
Expand All @@ -104,21 +110,23 @@ async def _get_signal_from_gpt(
self._ensure_rate_limit()
try:
model = model or self.model
completions = await openai.ChatCompletion.acreate(
api_key=self._get_api_key(),
completions = await self._get_client().chat.completions.create(
model=model,
max_tokens=max_tokens,
n=n,
stop=stop,
temperature=temperature,
messages=messages
)
self._update_token_usage(completions['usage']['total_tokens'])
return completions["choices"][0]["message"]["content"]
except openai.error.InvalidRequestError as err:
self._update_token_usage(completions.usage.total_tokens)
return completions.choices[0].message.content
except openai.BadRequestError as err:
raise errors.InvalidRequestError(
f"Error when running request with model {model} (invalid request): {err}"
) from err
except openai.AuthenticationError as err:
self.logger.error(f"Invalid OpenAI api key: {err}")
self.creation_error_message = err
except Exception as err:
raise errors.InvalidRequestError(
f"Unexpected error when running request with model {model}: {err}"
Expand Down Expand Up @@ -303,13 +311,14 @@ async def prepare(self) -> None:
if self.use_stored_signals_only():
self.logger.info(f"Skipping GPT - OpenAI models fetch as self.use_stored_signals_only() is True")
return
fetched_models = await openai.Model.alist(api_key=self._get_api_key())
self.models = [d["id"] for d in fetched_models["data"]]
fetched_models = await self._get_client().models.list()
self.models = [d.id for d in fetched_models.data]
if self.model not in self.models:
self.logger.warning(f"Warning: selected '{self.model}' model is not in GPT available models. "
f"Available models are: {self.models}")
except openai.error.AuthenticationError as err:
self.logger.error(f"Error when checking api key: {err}")
except openai.AuthenticationError as err:
self.logger.error(f"Invalid OpenAI api key: {err}")
self.creation_error_message = err
except Exception as err:
self.logger.error(f"Unexpected error when checking api key: {err}")

Expand Down
13 changes: 13 additions & 0 deletions Trading/Exchange/bitfinex/bitfinex_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import octobot_commons.enums
import octobot_commons.constants
import octobot_trading.exchanges as exchanges
import octobot_trading.enums as trading_enums


class Bitfinex(exchanges.RestExchange):
Expand All @@ -32,6 +33,9 @@ class Bitfinex(exchanges.RestExchange):
def get_name(cls):
return 'bitfinex2'

def get_adapter_class(self):
return BitfinexCCXTAdapter

async def get_symbol_prices(self, symbol, time_frame, limit: int = 500, **kwargs: dict):
if "since" not in kwargs:
# prevent bitfinex from getting candles from 2014
Expand All @@ -50,3 +54,12 @@ async def get_order_book(self, symbol, limit=DEFAULT_ORDER_BOOK_LIMIT, **kwargs)
self.logger.debug(f"Trying to get_order_book with limit not {self.SUPPORTED_ORDER_BOOK_LIMITS} : ({limit})")
limit = self.DEFAULT_ORDER_BOOK_LIMIT
return await super().get_recent_trades(symbol=symbol, limit=limit, **kwargs)


class BitfinexCCXTAdapter(exchanges.CCXTAdapter):

def fix_ticker(self, raw, **kwargs):
fixed = super().fix_ticker(raw, **kwargs)
fixed[trading_enums.ExchangeConstantsTickersColumns.TIMESTAMP.value] = \
fixed.get(trading_enums.ExchangeConstantsTickersColumns.TIMESTAMP.value) or self.connector.client.seconds()
return fixed
1 change: 0 additions & 1 deletion Trading/Exchange/bittrex/__init__.py

This file was deleted.

54 changes: 0 additions & 54 deletions Trading/Exchange/bittrex/bittrex_exchange.py

This file was deleted.

1 change: 0 additions & 1 deletion Trading/Exchange/bittrex/resources/bittrex.md

This file was deleted.

15 changes: 0 additions & 15 deletions Trading/Exchange/bittrex/tests/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion Trading/Exchange/bittrex_websocket_feed/__init__.py

This file was deleted.

15 changes: 0 additions & 15 deletions Trading/Exchange/bittrex_websocket_feed/tests/__init__.py

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions Trading/Exchange/cryptocom/cryptocom_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class CryptoCom(exchanges.RestExchange):

FIX_MARKET_STATUS = True

REQUIRE_CLOSED_ORDERS_FROM_RECENT_TRADES = True # set True when get_closed_orders is not supported

@classmethod
def get_name(cls):
return 'cryptocom'
15 changes: 15 additions & 0 deletions Trading/Exchange/hollaex/hollaex_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ccxt

import octobot_commons.enums as commons_enums
import octobot_trading.enums as trading_enums
import octobot_trading.exchanges as exchanges
import octobot_trading.exchanges.connectors.ccxt.enums as ccxt_enums

Expand All @@ -39,6 +40,9 @@ def __init__(self, config, exchange_manager):
self.HAS_WEBSOCKETS_KEY, not self.exchange_manager.rest_only
)

def get_adapter_class(self):
return HollaexCCXTAdapter

@classmethod
def init_user_inputs_from_class(cls, inputs: dict) -> None:
"""
Expand Down Expand Up @@ -91,3 +95,14 @@ async def get_closed_orders(self, symbol: str = None, since: int = None,
symbol=symbol, since=since, limit=limit, **kwargs
)
)


class HollaexCCXTAdapter(exchanges.CCXTAdapter):

def fix_order(self, raw, symbol=None, **kwargs):
raw_order_info = raw[ccxt_enums.ExchangePositionCCXTColumns.INFO.value]
# average is not supported by ccxt
fixed = super().fix_order(raw, **kwargs)
if not fixed[trading_enums.ExchangeConstantsOrderColumns.PRICE.value] and "average" in raw_order_info:
fixed[trading_enums.ExchangeConstantsOrderColumns.PRICE.value] = raw_order_info.get("average", 0)
return fixed
1 change: 1 addition & 0 deletions Trading/Exchange/htx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .htx_exchange import Htx
Loading

0 comments on commit e92b36c

Please sign in to comment.