Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) add okx spot candles + tests #7022

Merged
merged 14 commits into from May 20, 2024

Conversation

tomasgaudino
Copy link
Contributor

@tomasgaudino tomasgaudino commented May 10, 2024

Before submitting this PR, please make sure:

  • Your code builds clean without any errors or warnings
  • You are using approved title ("feat/", "fix/", "docs/", "refactor/")

A description of the changes proposed in the pull request:

  • Add OKX Spot Candles feed with unittests
  • Fix OKX Perpetual Candles Feed

Tests performed by the developer:

  • Compare with exchange values, no differences

Tips for QA testing:

  • Run the following script to compare shape and behaviour with kucoin:
from typing import Dict

import pandas as pd
import pandas_ta as ta  # noqa: F401

from hummingbot.connector.connector_base import ConnectorBase
from hummingbot.data_feed.candles_feed.candles_factory import CandlesConfig, CandlesFactory
from hummingbot.strategy.script_strategy_base import ScriptStrategyBase


class CandlesExample(ScriptStrategyBase):
    """
    This is a strategy that shows how to use the new Candlestick component.
    It acquires data from both Binance spot and Binance perpetuals to initialize three different timeframes
    of candlesticks.
    The candlesticks are then displayed in the status, which is coded using a custom format status that
    includes technical indicators.
    This strategy serves as a clear example for other users on how to effectively utilize candlesticks in their own
    trading strategies by utilizing the new Candlestick component. The integration of multiple timeframes and technical
    indicators provides a comprehensive view of market trends and conditions, making this strategy a valuable tool for
    informed trading decisions.
    """
    # Available intervals: |1s|1m|3m|5m|15m|30m|1h|2h|4h|6h|8h|12h|1d|3d|1w|1M|
    # Is possible to use the Candles Factory to create the candlestick that you want, and then you have to start it.
    # Also, you can use the class directly like BinancePerpetualsCandles(trading_pair, interval, max_records), but
    # this approach is better if you want to initialize multiple candles with a list or dict of configurations.
    okx_candles = CandlesFactory.get_candle(CandlesConfig(connector="okx", trading_pair="ETH-USDT", interval="1m", max_records=200))
    okx_perp_candles = CandlesFactory.get_candle(CandlesConfig(connector="okx_perpetual", trading_pair="ETH-USDT", interval="1m", max_records=200))
    binance_candles = CandlesFactory.get_candle(CandlesConfig(connector="binance", trading_pair="ETH-USDT", interval="1m", max_records=200))

    # The markets are the connectors that you can use to execute all the methods of the scripts strategy base
    # The candlesticks are just a component that provides the information of the candlesticks
    markets = {"binance_paper_trade": {"SOL-USDT"}}

    def __init__(self, connectors: Dict[str, ConnectorBase]):
        # Is necessary to start the Candles Feed.
        super().__init__(connectors)
        self.binance_candles.start()
        self.okx_perp_candles.start()
        self.okx_candles.start()

    def on_tick(self):
        pass

    def on_stop(self):
        """
        Without this functionality, the network iterator will continue running forever after stopping the strategy
        That's why is necessary to introduce this new feature to make a custom stop with the strategy.
        :return:
        """
        self.binance_candles.stop()
        self.okx_candles.stop()
        self.okx_perp_candles.stop()

    def format_status(self) -> str:
        """
        Displays the three candlesticks involved in the script with RSI, BBANDS and EMA.
        """
        if not self.ready_to_trade:
            return "Market connectors are not ready."
        lines = []
        lines.extend(["\n############################################ Market Data ############################################\n"])
        for candles in [self.binance_candles, self.okx_candles, self.okx_perp_candles]:
            candles_df = candles.candles_df
            # Let's add some technical indicators
            candles_df.ta.ema(length=14, offset=None, append=True)
            candles_df["timestamp"] = pd.to_datetime(candles_df["timestamp"], unit="ms")
            lines.extend([f"Candles: {candles.name} | Interval: {candles.interval}"])
            lines.extend(["    " + line for line in candles_df.tail().to_string(index=False).split("\n")])
            lines.extend(["\n-----------------------------------------------------------------------------------------------------------\n"])

        return "\n".join(lines)

@tomasgaudino tomasgaudino marked this pull request as ready for review May 10, 2024 15:18
@rapcmia rapcmia removed their request for review May 13, 2024 13:21
@tomasgaudino
Copy link
Contributor Author

tomasgaudino commented May 14, 2024

@nikspz now it's ready to test, i've added more tests and fix okx perpetual candle feed

note: i've updated the script to perform qa

Copy link
Contributor

@cardosofede cardosofede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@nikspz
Copy link
Contributor

nikspz commented May 15, 2024

Test performed:

  • Review that candles OHLC matched for
    • 1m
    • 5m
    • 15m

@tomasgaudino Volume and quote volume is the same for Okx Spot

Steps:

  • Cloned and installed PR7022, Start Client
  • start script provided by tomasgaudino
  • Review orders Volume and quote volume is the same for Okx Spot

image

Copy link

@tomasgaudino
Copy link
Contributor Author

@nikspz done, there was a minor error parsing the api

Copy link
Contributor

@nikspz nikspz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Tests performed:
    • Cloned and installed PR7022
    • started/edited script provided by tomasgaudino
    • Review that candles matched for
      • 1m
      • 5m
      • 15m
      • 1h
      • 4h
      • 1d

@nikspz nikspz merged commit d053013 into hummingbot:development May 20, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Development 1.28.0
Development

Successfully merging this pull request may close these issues.

None yet

4 participants