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

Request for Example Script: Grouped Orders with Take Profit and Stop Market in Python SDK #86

Open
PowerGrb opened this issue Dec 25, 2024 · 1 comment

Comments

@PowerGrb
Copy link

Hello,

I am currently exploring the Hyperliquid Python SDK but struggled to create a grouped order consisting of:

A buy or sell order,
A take profit order, and
A stop market order.
The available API documentation lacks sufficient details to help implement this functionality effectively. Could you kindly provide an example script in the examples directory to demonstrate how to achieve this?

Specifically, it would be immensely helpful if the example could showcase the necessary steps to group these orders together and manage their relationships as expected within the Hyperliquid system.

Thank you in advance for your support!

Best regards,
PowerGrb

@PowerGrb
Copy link
Author

This is the best I could achieve in terms of scripting without successfully grouping and linking the orders. The buy order and the take profit order are sent correctly, but they are not grouped or linked together.

`import argparse
import json
import example_utils
from hyperliquid.utils import constants

def main():
parser = argparse.ArgumentParser(description="basic_tpsl")
parser.add_argument("--is_buy", action="store_true")
args = parser.parse_args()

# Setup the connection
address, info, exchange = example_utils.setup(base_url=constants.TESTNET_API_URL, skip_ws=True)

# Prepare the orders
orders = [
    {
        "coin": "ETH",  # Coin symbol
        "is_buy": True,  # Buy order
        "sz": 0.01,  # Size
        "limit_px": 2500,  # Price
        "order_type": {"limit": {"tif": "Gtc"}},  # Limit order with time in force
        "reduce_only": False,  # Explicitly set reduce_only to False
        "grouping": "normalTpsl"  # Grouping for the orders
    },
    {
        "coin": "ETH",  # Coin symbol
        "is_buy": args.is_buy,  # Take profit order, depends on is_buy flag
        "sz": 0.01,  # Size
        "limit_px": 4500,  # Take profit price
        "order_type": {
            "trigger": {"triggerPx": 4000, "isMarket": True, "tpsl": "tp"}
        },
        "reduce_only": True,  # Reduce-only order
        "grouping": "normalTpsl"  # Grouping for the orders
    }
]

# Send both orders in a single request
order_result = exchange.bulk_orders(orders)
print(order_result)

if name == "main":
main()`
Capture d'écran 2024-12-25 172216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@PowerGrb and others