Kucoin / kucoin-php-sdk

PHP SDK for KuCoin API.
https://docs.kucoin.com
MIT License
79 stars 41 forks source link

Q: How can set the type of starting an order? (LONG or SHORT) #127

Closed BaseMax closed 2 years ago

BaseMax commented 2 years ago
<?php
// ....
$order = [
    'clientOid' => uniqid(),
    'price'     => '1',
    'size'      => '1',
    'symbol'    => 'BTC-USDT',
    'type'      => 'limit',
    'side'      => 'sell',
    'remark'    => 'ORDER#' . time(),
];
try {
    $result = $api->create($order);
    var_dump($result);
} catch (\Throwable $e) {
    var_dump($e->getMessage());
}

Here, I am trying to start order with the SELL type.

Does everything correct and my code should work? or do I miss understanding something?

Does this only work in FEATURES mode? not normal mode?

Any kind of help is welcome. Thanks in advance.

codewc commented 2 years ago

<?php // .... $order = [ 'clientOid' => uniqid(), 'price' => '1', 'size' => '1', 'symbol' => 'BTC-USDT', 'type' => 'limit', 'side' => 'sell', 'remark' => 'ORDER#' . time(), ]; try { $result = $api->create($order); var_dump($result); } catch (\Throwable $e) { var_dump($e->getMessage()); }


Here, I am trying to start order with the SELL type.
Does everything correct and my code should work? or do I miss understanding something?
Does this only work in FEATURES mode? not normal mode?
Any kind of help is welcome. Thanks in advance.

You are using the Spot SDK now, I think the parameters are ok. Any questions ? Could you please give me the whole error that KuCoin sent to you?

BaseMax commented 2 years ago

Thank you for your message, here is the full details:

Debug

<?php
$body = [
    "clientOid" => uniqid(),
    "price" => (string) $close,
    "size" => (string) $size,
    "symbol" => $ticker_name,
    "type" => "limit",
    "side" => $type === ORDER_BUY ? "buy" : "sell",
    'remark' => 'ORDER#' . time(),
];
$endpoint = 'https://api.kucoin.com';
function request(bool $isTest = false, string $method, string $endpoint, string $route, array $body = []) : string {...}
$res = request(false, "POST", $endpoint, "/api/v1/orders", $body);

Post body

Array
(
    [clientOid] => 6294eb11426e5
    [price] => 1.0817
    [size] => 5
    [symbol] => GMT-USDT
    [type] => limit
    [side] => sell
    [remark] => ORDER#1653926673
)

Output

{"code":"200004","msg":"Balance insufficient!"}

https://www.kucoin.com/trade/KCS-USDT?spm=....:

image

It seems it's not possible to open order with a SELL position.

Q: Opening order with a SELL position only allowed in features MODE?

BaseMax commented 2 years ago

My problem is fixed, Opening an order with the Sell position is only allowed in Features mode. I switched to features and the error was solved.

Thanks.