Kucoin / kucoin-python-sdk

MIT License
45 stars 15 forks source link

Using mod'd client.create_limit_stop_order() to post to margin account #54

Closed SirBricksALot closed 1 month ago

SirBricksALot commented 2 years ago

Love the sdk and making some good progress as a noob Pythoner. I'm currently using modified client.create_limit_stop_order() in Trade.py to post stop limit orders in a margin account. So far so good BUT, the orders are going in as SPOT, not default cross.

I've never done git pull requests and not set up on GH just yet but could we get an update to Trade.py to make a new method? client.create_limit_stop_margin_order()

with a cross, isolated and spot option selection would be very slick.

Thank you!

` def create_limit_stop_order(self, symbol, side, size, price, stopPrice, clientOid="", **kwargs):

    """ Modified limit stop order for margin """

    params = {
        'symbol': symbol,
        'side': side,
        'size': size,
        'price': price,
        'stopPrice': stopPrice,
        'type': "limit",
        'remark': 'API testing',
        'tradeType': 'MARGIN_TRADE',
        'marginMode' : 'cross'
    }

    if not clientOid:
        clientOid = self.return_unique_id

    params['clientOid'] = clientOid

    if kwargs:
        params.update(kwargs)

    return self._request('POST', '/api/v1/margin/stop-order', params=params)`
SirBricksALot commented 2 years ago

One other (noob Py question) - I'm trying to add functions to the Trade.py file but getting the following error when calling

AttributeError: 'Trade' object has no attribute

Not sure how to link this up.

Thanks!

SirBricksALot commented 2 years ago

SOLVED (partially) - The second part of my question re: adding functions to trade.py solved by grep'ing, locating and testing mods to the file located in path ~/.local/lib/python3.6/site-packages/kucoin/trade/trade.py

The MISTAKE I was making was in trying to modify the sdk files located in path ~/kucoin-python-sdk/kucoin/trade

Still trying to figure out how to POST a stop limit margin order with 'cross' option (default is spot). The endpoint in the sdk might be outdated, not sure. The Developer's docs aren't the best.

Lastly and final issue, can't seem to list out my open limit margin orders via client.get_order_list(isActive=True)

Only returns cancelled or filled orders from what I can tell.

I'm using this method to list out margin stop orders successfully for now. client.get_all_stop_order_details()

Everything else works pretty good and I'm able to at least trade off the CLI using limit margin orders and a xed notepad lol

Any input greatly appreciated.

SirBricksALot commented 2 years ago

So it looks like this sdk is pretty much unsupported? Too bad because Kucoin is referred to as the 4th largest exchange. Would be great to have real support for this (mostly great) sdk.

Current issues persist:

  1. client.cancel_all_orders() returns an empty list and doesn't actually cancel all orders, at least not the stop limit margin orders I had placed

  2. client.get_order_list() doesn't return any isActive=True orders whatsoever so can't actually get list of active limit orders in margin account

My app is at least working with some patches and I can accomplish everything I need to as far as fully utilizing a margin account.

Later

ISAAC-XXYYZZ commented 1 month ago

Sorry for the late reply. For stop-order, please refer to our documentation: https://www.kucoin.com/docs/rest/spot-trading/stop-order/place-order

Please note that there is no endpoint for /api/v1/margin/stop-order. If you need to place a stop-order for a margin account, set tradeType to margin.

Since this issue has been around for a while, many things have changed. Please try again, and if you still encounter any problems, please open a new issue. We will respond promptly.