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

how to set a stop loss order with python api ? #159

Open
swiinger opened this issue Feb 4, 2024 · 2 comments
Open

how to set a stop loss order with python api ? #159

swiinger opened this issue Feb 4, 2024 · 2 comments

Comments

@swiinger
Copy link

swiinger commented Feb 4, 2024

Hello,

I've looked at the python example which is nice but I can't figure out how to create a stop loss order
Do I need to use the Order class and how to use the parameters ?
I have tried this but I can't give all needed parameters for the stop loss like rule or expiration

spot_price_trigger_order = Order(
        type='limit',
        side = 'sell',
        price= "10",
        amount= "50",
        account= "normal",
        time_in_force= "gtc",
        currency_pair="CSPR_USDT"
    )
created = spot_api.create_spot_price_triggered_order(spot_price_trigger_order)

and I have an error
HTTP response body: {"label":"INVALID_PARAM_VALUE","message":"invalid argument: put.account"}

Thanks a lot

Chris

@revilwang
Copy link
Collaborator

You don't need to create an Order object. Refer to the model doc for corresponding Class you need

@swiinger
Copy link
Author

swiinger commented Feb 7, 2024

ok got it

from gate_api import ApiClient, Configuration, Order, SpotApi, AccountApi, SpotPriceTriggeredOrder, SpotPriceTrigger, SpotPricePutOrder # import classes we'll need

currency_pair = "CSPR_USDT"
sell_price = "0.035"
order_amount = "100"
trigger_price = "0.033"

spot_price_put_order = SpotPricePutOrder (
type="limit",
side= "sell",
price= sell_price, # stop-loss price
amount=order_amount
)

spot_price_trigger = SpotPriceTrigger (
price=trigger_price,
rule= '<=',
expiration= 604800 #86400*number of days
)

spot_price_trigger_order = SpotPriceTriggeredOrder(
trigger=spot_price_trigger,put=spot_price_put_order,market=currency_pair
)

created = spot_api.create_spot_price_triggered_order(spot_price_trigger_order) # here is the stop loss !
logger.info("order created with id %s", created.id)
print (created)

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