Kucoin / kucoin-python-sdk

MIT License
40 stars 11 forks source link

How Put buy/sell cost in API call #81

Open Mas313 opened 1 year ago

Mas313 commented 1 year ago

I am using the example given here to place a market order. I need to know what parameter ( 'fund' )value I need to put to buy with all available USDT in my account and then sell all purchased tokens when required. I am unable to find any specific value in API for the 'funds' parameter in documentation to fulfill my requirement. I have tried this before

from kucoin.client import Trade
api_key = ''  
api_secret = ''
api_passphrase = ''
def buy():
   client = Trade(key=api_secret, secret=api_secret, passphrase=api_passphrase , is_sandbox=False, url='')
   order_id = client .create_market_order('ADA-USDT', 'buy', funds='20') #  to purchase with 20 USDT
   print(order_id)

def sell()
  client = Trade(key=api_secret, secret=api_secret, passphrase=api_passphrase , is_sandbox=False, url='')
   order_id = client .create_market_order('ADA-USDT', 'sell' ) #  would removing 'funds' parameter sell all coins purchased
   print(order_id)
#function call
buy()
sell()
progressivehed commented 1 year ago

Hello there

In order to consume all USDT you have, You can use Funds. It it pointing to your USDT amount that you have. First check amount of USDT you have and then specify the portion of it that you want to use as USDT, in Funds parameter:

Param type Description
size String [Optional] Desired amount in base currency
funds String [Optional] The desired amount of quote currency to use

But please note that Funds is useable for Market type only (As in your above example code)

https://docs.kucoin.com/#place-a-new-order

Mas313 commented 1 year ago

Thanks for the reply, for the buy order its working fine as I put funds='20' and coins of 20 USDT worth are bought ( 27.11 ADA) . For the sale order, I need to sell all coins I got for 20 USDT. I retrieved the coin balance through API which was correct. however, when putting size="27.11" I get exception related to coin increment value

progressivehed commented 1 year ago

For selling, it is better to go ahead with size (as you said above).

But you need to calculate size correctly (and also consider the fee). I guess the issue is in calculation of Size.