def get_exchange_symbol_data(self, exchange_name: str, exchange_id: str,
                              symbol: str):
     try:
         import octobot_trading.api as exchange_api
         exchange_manager = exchange_api.get_exchange_manager_from_exchange_name_and_id(
             exchange_name, exchange_id)
         return exchange_api.get_symbol_data(exchange_manager, symbol)
     except (ImportError, KeyError):
         self.logger.error(
             f"Can't get {exchange_name} from exchanges instances")
     return
Ejemplo n.º 2
0
    def _get_market_delta(symbol, exchange_manager, min_timeframe):
        market_data = trading_api.get_symbol_historical_candles(
            trading_api.get_symbol_data(exchange_manager, symbol), min_timeframe)
        market_begin = market_data[enums.PriceIndexes.IND_PRICE_CLOSE.value][0]
        market_end = market_data[enums.PriceIndexes.IND_PRICE_CLOSE.value][-1]

        if market_begin and market_end and market_begin > 0:
            market_delta = market_end / market_begin - 1 if market_end >= market_begin \
                else -1 * (1 - market_end / market_begin)
        else:
            market_delta = 0

        return market_delta
Ejemplo n.º 3
0
def get_currency_price_graph_update(exchange_id,
                                    symbol,
                                    time_frame,
                                    list_arrays=True,
                                    backtesting=False,
                                    minimal_candles=False,
                                    ignore_trades=False):
    bot_api = interfaces_util.get_bot_api()
    # TODO: handle on the fly backtesting price graph
    # if backtesting and WebInterface and WebInterface.tools[BOT_TOOLS_BACKTESTING]:
    #     bot = WebInterface.tools[BOT_TOOLS_BACKTESTING].get_bot()
    symbol = parse_get_symbol(symbol)
    in_backtesting = backtesting_api.is_backtesting_enabled(
        interfaces_util.get_global_config()) or backtesting
    exchange_manager = trading_api.get_exchange_manager_from_exchange_id(
        exchange_id)
    if time_frame is not None:
        try:
            symbol_data = trading_api.get_symbol_data(exchange_manager,
                                                      symbol,
                                                      allow_creation=False)
            limit = 1 if minimal_candles else -1
            historical_candles = trading_api.get_symbol_historical_candles(
                symbol_data, time_frame, limit=limit)
            kline = [math.nan]
            if trading_api.has_symbol_klines(symbol_data, time_frame):
                kline = trading_api.get_symbol_klines(symbol_data, time_frame)
            if historical_candles is not None:
                return _create_candles_data(symbol, time_frame,
                                            historical_candles, kline, bot_api,
                                            list_arrays, in_backtesting,
                                            ignore_trades)
        except KeyError:
            traded_pairs = trading_api.get_trading_pairs(exchange_manager)
            if not traded_pairs or symbol in traded_pairs:
                # not started yet
                return None
            else:
                return {"error": f"no data for {symbol}"}
    return None