From a7b37a66034df960667a22b95da147f6e1fa28da Mon Sep 17 00:00:00 2001 From: fibonacci998 Date: Tue, 15 Oct 2024 10:51:52 +0700 Subject: [PATCH] feat: add ci --- .github/workflows/docker_build_aura.yaml | 39 ++++++++ .../connector/exchange/mexc/mexc_utils.py | 2 +- scripts/create_mid_volumn.py | 88 ++++++++++--------- 3 files changed, 87 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/docker_build_aura.yaml diff --git a/.github/workflows/docker_build_aura.yaml b/.github/workflows/docker_build_aura.yaml new file mode 100644 index 0000000000..d55762fc3e --- /dev/null +++ b/.github/workflows/docker_build_aura.yaml @@ -0,0 +1,39 @@ +name: Build Development Docker image + +on: + workflow_dispatch: + push: + branches: [feat/create-new-strategy] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set environment variable + run: | + SHORT_SHA_COMMIT=$(git rev-parse --short HEAD) + echo CONTAINER_RELEASE_IMAGE=ghcr.io/aura-nw/hummingbot:aura_supported_${SHORT_SHA_COMMIT} >> $GITHUB_ENV + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ env.CONTAINER_RELEASE_IMAGE }} diff --git a/hummingbot/connector/exchange/mexc/mexc_utils.py b/hummingbot/connector/exchange/mexc/mexc_utils.py index 0acf5520f6..5852362054 100644 --- a/hummingbot/connector/exchange/mexc/mexc_utils.py +++ b/hummingbot/connector/exchange/mexc/mexc_utils.py @@ -22,7 +22,7 @@ def is_exchange_information_valid(exchange_info: Dict[str, Any]) -> bool: :param exchange_info: the exchange information for a trading pair :return: True if the trading pair is enabled, False otherwise """ - return exchange_info.get("status", None) == "ENABLED" and "SPOT" in exchange_info.get("permissions", list()) \ + return exchange_info.get("status", None) == "1" and "SPOT" in exchange_info.get("permissions", list()) \ and exchange_info.get("isSpotTradingAllowed", True) is True diff --git a/scripts/create_mid_volumn.py b/scripts/create_mid_volumn.py index 80598e3c6a..c8a18cd56e 100644 --- a/scripts/create_mid_volumn.py +++ b/scripts/create_mid_volumn.py @@ -1,4 +1,5 @@ +from typing import Dict from hummingbot.strategy.script_strategy_base import ScriptStrategyBase from hummingbot.core.data_type.common import OrderType from decimal import Decimal @@ -8,67 +9,65 @@ BuyOrderCompletedEvent, SellOrderCompletedEvent, ) -class CreateMidVolumn(ScriptStrategyBase): - base = 'AURA' - quote = 'USDT' - trading_pair = f"{base}-{quote}" - markets = { - "gate_io": {f"{base}-{quote}"} - # "mexc": {f"{base}-{quote}"} - } - +from hummingbot.connector.connector_base import ConnectorBase +from hummingbot.client.config.config_data_types import BaseClientModel, ClientFieldData +from pydantic import Field +import random +import os + +class CreateMidVolumnConfig(BaseClientModel): + script_file_name: str = Field(default_factory=lambda: os.path.basename(__file__)) + + exchange: str = Field("gate_io_paper_trade", client_data=ClientFieldData(prompt_on_new=True, prompt=lambda mi: "Exchange where the bot will trade")) + + trading_pair: str = Field("AURA-USDT", client_data=ClientFieldData( + prompt_on_new=True, prompt=lambda mi: "Trading pair in which the bot will place orders")) + + minimum_amount_limit : int = Field(400, client_data=ClientFieldData(prompt_on_new=True, prompt=lambda mi: "Minimum amount limit to random")) + + maximum_amount_limit : int = Field(400, client_data=ClientFieldData(prompt_on_new=True, prompt=lambda mi: "Maximum amount limit to random")) + + cron_expression: str = Field("* * * * *", client_data=ClientFieldData(prompt_on_new=True, prompt=lambda mi: "Cron expression to run")) +class CreateMidVolumn(ScriptStrategyBase): numberBuyOrder = 0 numberSellOrder = 0 - - # minimum limit = 3 USDT - miminumLimit = 3 - amount = Decimal(400) - cron_expression = "* * * * *" - cron = croniter.croniter(cron_expression) next_time = None + def __init__(self, connectors: Dict[str, ConnectorBase], config: CreateMidVolumnConfig): + super().__init__(connectors) + self.config = config + + @classmethod + def init_markets(cls, config: CreateMidVolumnConfig): + cls.markets = {config.exchange: {config.trading_pair}} def on_tick(self): for connector_name, connector in self.connectors.items(): - # self.logger().info(f"Connector: {connector_name}") - # self.logger().info(f"Best ask: {connector.get_price(self.trading_pair, True)}") - # self.logger().info(f"Best bid: {connector.get_price(self.trading_pair, False)}") current_time = datetime.now(tz=timezone.utc).timestamp() - # previous_time = self.cron.get_prev(datetime) - # next_time = self.cron.get_next(datetime) self.logger().debug(f"Current time: {current_time}, Next time: ${self.next_time}") if (self.next_time == None or current_time >= self.next_time): self.logger().debug('Satisfiy cron') - active_orders = self.get_active_orders( - connector_name=connector_name, - ) - for order in active_orders: - self.cancel(connector_name=connector_name, - trading_pair=self.trading_pair, - order_id=order) - mid_price = Decimal(connector.get_mid_price(self.trading_pair)) + # Cancel all active orders + self.cancel_all_orders() + mid_price = Decimal(connector.get_mid_price(self.config.trading_pair)) self.logger().info(f"Mid price: {mid_price}") - if (self.numberBuyOrder == 0 & self.numberSellOrder == 0): - buyId = self.buy(connector_name=connector_name, - amount=self.amount, - trading_pair=self.trading_pair, + amount = Decimal(random.randint(self.config.minimum_amount_limit, self.config.maximum_amount_limit)) + self.buy(connector_name=connector_name, + amount=amount, + trading_pair=self.config.trading_pair, order_type=OrderType.LIMIT, price=mid_price, ) self.numberBuyOrder += 1 - sellId = self.sell(connector_name=connector_name, - amount=self.amount, - trading_pair=self.trading_pair, + self.sell(connector_name=connector_name, + amount=amount, + trading_pair=self.config.trading_pair, order_type=OrderType.LIMIT, price=mid_price) self.numberSellOrder += 1 - # await asyncio.sleep(2) - # self.numberBuyOrder -=1 - # self.numberSellOrder -=1 - - cron = croniter.croniter(self.cron_expression, current_time) + cron = croniter.croniter(self.config.cron_expression, current_time) self.next_time = cron.get_next() self.logger().debug(f"Next time is {self.next_time}") else: @@ -78,4 +77,11 @@ def did_complete_buy_order(self, event: BuyOrderCompletedEvent): self.numberBuyOrder -= 1 def did_complete_sell_order(self, event: SellOrderCompletedEvent): - self.numberSellOrder -=1 \ No newline at end of file + self.numberSellOrder -=1 + + def cancel_all_orders(self): + for order in self.get_active_orders(connector_name=self.config.exchange): + self.cancel(self.config.exchange, order.trading_pair, order.client_order_id) + + def on_stop(self): + self.cancel_all_orders() \ No newline at end of file