-
Notifications
You must be signed in to change notification settings - Fork 109
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 work with stop loss effectively with API #146
Comments
Can anyone help, please? |
What is the problem actually? I think you need to go though your business logic once again. It seems you’re trying to set the stop-loss price even when the market price has already gone down. |
Okay, Let me give you one example, Users want to buy the crypto at $15 So, When the last price crosses the stop-loss price(Latest last price is $8), So when last price is less than or less than equal to stop loss price I want to sell the crypto immediately but the problem is when I send a request for sell the crypto (I'm using I always want to sell the crypto immediately when the last price is <= stop loss. |
If the current price has already goes down below your stop-loss price, and you want to sell it ASAP, you need to place a plain |
It means that if the last price is lower than the stop-loss price, it will sell immediately rather than waiting until it touches the stop-loss price. Is it correct? Below is the snippet code of the |
When I do trading directly from gate.io, even when it's very fast when the last price touches the stop-loss price, it sells immediately, So may I know, if is there any strategy that gate.io follows? |
I'm sorry I still do not get your point. Take your example above:
You want to:
Is that correct? If I'm not mistaken, in the first case, you can create a stop-loss triggered order and wait until the triggered happened. That's how it works, avoid your loss automatically for you. For the second case, if current price has already gone down, there is no point in creating a stop-loss triggered order. Why not try to create a plain order with current price to make sure the order can be sold as soon as possible? |
Yes, You're right. Because currently, When current_price = stop-loss, at that I create the stop-loss trigger but I get the error saying "Trigger. price must < last price." because current_price changes frequently so when the trigger order executes at that time possibly trigger price >= last price. So this is what the error saying. |
Hello @revilwang, I've implemented the above things in my code and noticed one thing. I'll go ahead and explain that thing with one example. Users want to buy the crypto at $15 I'm creating the buy order, and along with that, I'm creating the stop-loss trigger order. I want to ask, is your stop loss order been executed when the stop loss gets to 10 or immediately when the crypto is bought? Below is a code snippet of the trigger order
|
Hi @revilwang, Can you help, please? |
I'm not sure what you mean, but |
Yes, but I'm not sure why a new sell order is created because I'm using trigger orders, and once the triggers execute at whatever price they should sell at that time. |
I think you misunderstand something here. The price triggered order will place an order with parameters you defined in |
I expect the order to sell at whatever price I've set as the trigger price. |
No, the order only sells with the price you set in |
Okay, So Is there a method to sell the order right away? This means that when I ask to sell something for $10 and the current price is $12 and it has dropped from $12 to $9, I don't want to wait for the current price to reach $10; I just want to sell for $10 right away. |
It depends on your own need, either you can sell it with market price, or you can set your |
Okay |
Is there any way to know when my triggered order was executed? I mean any callback or webhook event is there in the trigger order API when the trigger order executes? So if is there any event that occurs based on that I can take action. |
No, there is no obvious way to do so currently. But you can try to use a custom order id with |
Okay, Basically what I want to do is that when my trigger order is finished I want to run my code automatically and want to sell the crypto. So will it be possible to do it through you mentioned above? |
I'm using the
POST /spot/orders
API to sell the crypto.Let's say,
The stop-loss price is $10.
The last price of the crypto was $11.
I'm checking, and when stop-loss >= last price is True (say stop-loss is $10 and last price is $10), at that point I'm calling the
POST /spot/orders
to sell the crypto, but the moment I'm calling the API, the last price of the crypto went down from $10 to $8, So, in this case, my selling request will be in open status in gate.io, and it will sell when last price again touch $10 but I want to sell the crypto when it's gets to my price for stop-loss price.I also tried the
POST /spot/price_orders
trigger API, The condition is also the same as above (stop-loss >= last price), but the problem is that when I set the trigger price to $10 (which is the stop-loss price, and the last price is $9) in this API, I get the error saying that "Trigger. price must < last price." because the last price is less than the stop-loss price in our case.I also attempted to pass the trigger price as 9$ (last price), but in some cases, the last price dropped from 9 to 8, so gate. IO will raise the same error.
Snippet code as below for trigger API
Is there any solution to this problem?
The text was updated successfully, but these errors were encountered: