gateio / gateapi-python

243 stars 91 forks source link

Which API can I use to include the profit and loss for the cryptocurrency that a user purchased or set the profit and loss via an application by user? #130

Closed akashc-25 closed 1 year ago

akashc-25 commented 1 year ago

Let‘s imagine a customer needs to purchase one crypto for $100 with a 10% profit set. Once the crypto reaches that profit, in this case, $110, it will automatically sell. So, is there an API that accomplishes this?

I found this API "/spot/price_orders" (https://www.gate.io/docs/developers/apiv4/en/#create-a-price-triggered-order) but in this API Expiration time is required but Profit can be made at any time so. And in my view, we use this API for stop-limit purposes rather than stop-loss purposes.

revilwang commented 1 year ago

For now, you need to call POST /spot/orders to buy the crypto in $100, then call POST /spot/price_orders to set a rule to sell your crypto when it reaches $110, like the following:

POST /spot/orders

{
  "side": "buy",
  "price": "100",
  # any other parameters for creating the buy order 
}
POST /spot/price_orders

{
  "trigger": {
    "price": "110",
    "rule": ">=",
    "expiration": 2592000
  },
  "put": {
    "side": "sell",
    "price": "110",
    # any other parameters to create the sell order when condition is triggered.
  }
}

Note the expiration is required. And you have to set it between 60s and 30 days. Unlimited time is not supported at the momoent.

akashc-25 commented 1 year ago

Okay, if I don't want to use the "POST /spot/price orders" API, can I make all the calculations in the backend and then call the "POST /spot/orders" API to sell the order once the crypto amount has reached to the profit amount? Is this a valid/acceptable way? I need your opinion on this.

revilwang commented 1 year ago

Sure, actually /spot/price_orders follow the same logic.

akashc-25 commented 1 year ago

Okay, I appreciate your response, @revilwang.

akashc-25 commented 1 year ago

@revilwang, As you said before that need to call two APIs. One for creating Orders and another for setting price triggers, but Can you please tell me how can I set the price trigger for only newly created Orders if I use the Create Order API, as "/spot/price orders" does not take the order id as a parameter? So how can I set the price triggered for particular order/crypto?

akashc-25 commented 1 year ago

@revilwang, Please correct me if I'm incorrect if I am.

revilwang commented 1 year ago

They are not connected. The /spot/price_orders can only create new orders on condition triggered

akashc-25 commented 1 year ago

Okay, I can create the order with a trigger price using the /spot/price orders API(By using a single API). Correct? Additionally, is it possible to give two conditions to this API for the Buy amount and Sell amount triggers?

POST /spot/price_orders

{ "trigger": { "price": "110", "rule": ">=", "expiration": 2592000 }, "trigger": { "price": "90", "rule": "<=", "expiration": 2592000 }, "put": { "side": "sell", "price": "110",

any other parameters to create the sell order when condition is triggered.

} }

Like Above?

revilwang commented 1 year ago

For the first question, like what I mentioned above, you need to create your $100 buy orders with /spot/orders and set a $110 sell trigger with /spot/price_orders. The latter one will only create your trigger order on condition matched. You have to create the initial order by yourself using /spot/orders.

Second question, using one request, no. But you can create two price orders with different conditions to achieve the same thing except you have to associate the two orders manually.

akashc-25 commented 1 year ago

To continue the above discussion, I am using the POST /spot/orders API to create the Order, however, I'm not sure what to pass for the "amount" and "order price" arguments.

What value should I give to the amount and order price parameters if I wish to buy 10 qty of the ALEPH USDT crypto at its most recent price of $5.00?

akashc-25 commented 1 year ago

Can anyone please help me with my previous question?

revilwang commented 1 year ago

If you mean buy 10 ALEPH with price 5 USDT, then set your order like Order(currency_pair="ALEPH_USDT", side="buy", amount="10", price="5")

akashc-25 commented 1 year ago

Okay, So can I pass my custom price in the price parameter, So if I want to Buy ALEPH_USDT with 10 qty with the price of 100(This 100 amount is given by the end user, not the last/recent price of the crypto). So Is this possible, Yes then what do Order class attributes look like?

revilwang commented 1 year ago

Yes, you can set price to any price you wish to, if your minimum order amount is satisfied.