kucoin-python-sdk
kucoin-python-sdk copied to clipboard
How Put buy/sell cost in API call
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()
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
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
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.
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!