Skip to content

Commit

Permalink
feat: add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
fibonacci998 committed Oct 15, 2024
1 parent 1b205f3 commit a7b37a6
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 42 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/docker_build_aura.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion hummingbot/connector/exchange/mexc/mexc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
88 changes: 47 additions & 41 deletions scripts/create_mid_volumn.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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
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()

0 comments on commit a7b37a6

Please sign in to comment.