kucoin-python-sdk icon indicating copy to clipboard operation
kucoin-python-sdk copied to clipboard

How Put buy/sell cost in API call

Open Mas313 opened this issue 2 years ago • 3 comments

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()

Mas313 avatar Aug 07 '22 11:08 Mas313

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

progressivehed avatar Aug 09 '22 07:08 progressivehed

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

Mas313 avatar Aug 09 '22 13:08 Mas313

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.

progressivehed avatar Aug 10 '22 12:08 progressivehed

Since this issue has already been addressed and there have been no updates for a long time, we will now close it. If you need any further assistance, feel free to ask!

ISAAC-XXYYZZ avatar Jul 29 '24 09:07 ISAAC-XXYYZZ