Skip to content

Commit

Permalink
feat: create new script
Browse files Browse the repository at this point in the history
  • Loading branch information
fibonacci998 committed Oct 14, 2024
1 parent 691913f commit 1b205f3
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 48 deletions.
81 changes: 81 additions & 0 deletions scripts/create_mid_volumn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

from hummingbot.strategy.script_strategy_base import ScriptStrategyBase
from hummingbot.core.data_type.common import OrderType
from decimal import Decimal
from datetime import datetime, timezone
import croniter
from hummingbot.strategy.strategy_py_base import (
BuyOrderCompletedEvent,
SellOrderCompletedEvent,
)
class CreateMidVolumn(ScriptStrategyBase):
base = 'AURA'
quote = 'USDT'
trading_pair = f"{base}-{quote}"
markets = {
"gate_io": {f"{base}-{quote}"}
# "mexc": {f"{base}-{quote}"}
}

numberBuyOrder = 0
numberSellOrder = 0

# minimum limit = 3 USDT
miminumLimit = 3
amount = Decimal(400)
cron_expression = "* * * * *"
cron = croniter.croniter(cron_expression)
next_time = None

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))
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,
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,
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)
self.next_time = cron.get_next()
self.logger().debug(f"Next time is {self.next_time}")
else:
self.logger().debug('Not satisfy cron')

def did_complete_buy_order(self, event: BuyOrderCompletedEvent):
self.numberBuyOrder -= 1

def did_complete_sell_order(self, event: SellOrderCompletedEvent):
self.numberSellOrder -=1
97 changes: 49 additions & 48 deletions setup/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,52 @@ dependencies:
- ujson
- zlib
- pip:
- aiohttp==3.*
- aioprocessing==2.0
- aioresponses
- aiounittest
- appdirs==1.4.3
- async-timeout
- asyncssh==2.13.1
- pyOpenSSL==21.0.0
- appnope==0.1.3
- base58==2.1.1
- cachetools==4.0.0
- commlib-py==0.10.6
- cryptography==3.4.7
- diff-cover
- docker==5.0.3
- eth_abi==4.0.0
- eth-account==0.8.0
- eth-utils==2.2.0
- eip712-structs==1.1.0
- dotmap==1.3.30
- flake8==3.7.9
- gql
- grpcio-tools
- importlib-metadata==0.23
- injective-py==1.5.*
- jsonpickle==3.0.1
- mypy-extensions==0.4.3
- msgpack
- pandas_ta==0.3.14b
- pre-commit==2.18.1
- psutil==5.7.2
- ptpython==3.0.20
- pyjwt==1.7.1
- pyperclip==1.7.0
- python-telegram-bot==12.8
- requests==2.*
- rsa==4.7
- ruamel-yaml==0.16.10
- signalr-client-aio==0.0.1.6.2
- substrate-interface==1.6.2
- solders==0.1.4
- vega-python-sdk==0.1.3
- web3
- websockets
- yarl==1.*
- git+https://github.com/CoinAlpha/python-signalr-client.git
- git+https://github.com/konichuvak/dydx-v3-python.git@web3
- xrpl-py
- aiohttp==3.*
- aioprocessing==2.0
- aioresponses
- aiounittest
- appdirs==1.4.3
- async-timeout
- asyncssh==2.13.1
- pyOpenSSL==21.0.0
- appnope==0.1.3
- base58==2.1.1
- cachetools==4.0.0
- commlib-py==0.10.6
- cryptography==3.4.7
- diff-cover
- docker==5.0.3
- eth_abi==4.0.0
- eth-account==0.8.0
- eth-utils==2.2.0
- eip712-structs==1.1.0
- dotmap==1.3.30
- flake8==3.7.9
- gql
- grpcio-tools
- importlib-metadata==0.23
- injective-py==1.5.*
- jsonpickle==3.0.1
- mypy-extensions==0.4.3
- msgpack
- pandas_ta==0.3.14b
- pre-commit==2.18.1
- psutil==5.7.2
- ptpython==3.0.20
- pyjwt==1.7.1
- pyperclip==1.7.0
- python-telegram-bot==12.8
- requests==2.*
- rsa==4.7
- ruamel-yaml==0.16.10
- signalr-client-aio==0.0.1.6.2
- substrate-interface==1.6.2
- solders==0.1.4
- vega-python-sdk==0.1.3
- web3
- websockets
- yarl==1.*
- git+https://github.com/CoinAlpha/python-signalr-client.git
- git+https://github.com/konichuvak/dydx-v3-python.git@web3
- xrpl-py
- cronitor

0 comments on commit 1b205f3

Please sign in to comment.