Get Stop Orders List (Implementation)
Source:R/impl_spottrading_orders_stop.R
get_stop_order_list_impl.RdRetrieves a paginated list of untriggered stop orders from the KuCoin Spot trading system asynchronously.
This function constructs a GET request to the KuCoin API and returns a promise that resolves to a data.table
containing details of stop orders, sorted by the latest update time in descending order.
Usage
get_stop_order_list_impl(
keys = get_api_keys(),
base_url = get_base_url(),
query = list(),
.__coro_env_parent__ = <environment>
)Arguments
- keys
List; API configuration parameters from
get_api_keys(). Defaults toget_api_keys().- base_url
Character string; base URL for the KuCoin API. Defaults to
get_base_url().- query
Named list; query parameters for filtering and pagination (e.g.,
list(symbol = "BTC-USDT", side = "buy", pageSize = 10)). Optional.
Value
Promise resolving to a data.table containing stop order details, with the following columns:
id(character): Unique order ID assigned by KuCoin.symbol(character): Trading pair (e.g., "KCS-USDT").userId(character): User ID associated with the order.status(character): Order status (e.g., "NEW", "TRIGGERED").type(character): Order type (e.g., "limit", "market").side(character): Order side ("buy" or "sell").price(character): Order price.size(character): Order size.funds(character or NA): Order funds (NULL for untriggered orders).stp(character or NA): Self Trade Prevention strategy (e.g., "DC", "CO", "CN", "CB").timeInForce(character): Time in force (e.g., "GTC", "GTT", "IOC", "FOK").cancelAfter(integer): Seconds until cancellation for GTT (-1 if not applicable).postOnly(logical): Whether the order is post-only.hidden(logical): Whether the order is hidden.iceberg(logical): Whether the order is an iceberg order.visibleSize(character or NA): Visible size for iceberg orders.channel(character): Order source (e.g., "API").clientOid(character): Client-assigned order ID.remark(character or NA): Order remarks.tags(character or NA): Order tags.orderTime(numeric): Order creation time in nanoseconds.domainId(character): Domain ID (e.g., "kucoin").tradeSource(character): Trade source (e.g., "USER").tradeType(character): Trade type (e.g., "TRADE").feeCurrency(character): Currency used for fees.takerFeeRate(character): Taker fee rate.makerFeeRate(character): Maker fee rate.createdAt(integer): Creation timestamp in milliseconds.stop(character): Stop order type (e.g., "loss", "entry").stopTriggerTime(integer or NA): Trigger time in milliseconds (NULL if untriggered).stopPrice(character): Stop price.createdAtDatetime(POSIXct): Creation time in UTC (derived fromcreatedAt).orderTimeDatetime(POSIXct): Order placement time in UTC (derived fromorderTime).
Details
Description
This endpoint fetches a list of stop orders that have not yet been triggered. Stop orders are conditional orders
that become active when the market price reaches a specified stopPrice. The list is paginated and sorted to show
the most recent orders first. Users can filter the results using various query parameters such as symbol, side,
type, and time range.
Workflow
Parameter Validation: Ensures that provided parameters are valid, such as
symbol,side,type, and pagination settings.Request Construction: Builds the endpoint URL with query parameters for filtering and pagination.
Authentication: Generates private API headers using
build_headers()with the GET method and endpoint.API Request: Sends a GET request to the KuCoin API with a 3-second timeout.
Response Processing: Parses the response, converts the
itemsarray to adata.table, and adds datetime columns forcreatedAtandorderTime.
API Details
Endpoint:
GET https://api.kucoin.com/api/v1/stop-orderDomain: Spot
API Channel: Private
API Permission: General
Rate Limit Pool: Spot
Rate Limit Weight: 8
SDK Service: Spot
SDK Sub-Service: Order
SDK Method Name: getStopOrdersList
Official Documentation: KuCoin Get Stop Orders List
Request
Query Parameters
symbol: String (optional) - Filter by trading pair (e.g., "BTC-USDT").side: Enum(optional) - Filter by order side: "buy" or "sell". type: Enum(optional) - Filter by order type: "limit", "market", "limit_stop", "market_stop". tradeType: Enum(optional) - Filter by trade type: "TRADE", "MARGIN_TRADE", "MARGIN_ISOLATED_TRADE". startAt: Integer(optional) - Start time in milliseconds. endAt: Integer(optional) - End time in milliseconds. currentPage: Integer (optional) - Current page number.orderIds: String (optional) - Comma-separated list of order IDs.pageSize: Integer (optional) - Number of orders per page.stop: String (optional) - Filter by stop order type: "stop" or "oco".
Response
Data Schema
code: String (required) - Response code ("200000" indicates success).data: Object (required) - Contains:currentPage: Integer - Current page number.pageSize: Integer - Number of orders per page.totalNum: Integer - Total number of stop orders.totalPage: Integer - Total number of pages.items: Array of objects - List of stop orders, each with fields such as:id: String - Order ID.symbol: String - Trading pair.userId: String - User ID.status: String - Order status.type: String - Order type.side: String - Order side.price: String - Order price.size: String - Order size.funds: String - Order funds.stp: String - Self Trade Prevention.timeInForce: String - Time in force.cancelAfter: Integer - Cancel after n seconds.postOnly: Boolean - Post-only flag.hidden: Boolean - Hidden order flag.iceberg: Boolean - Iceberg order flag.visibleSize: String - Visible size for iceberg orders.channel: String - Order channel.clientOid: String - Client order ID.remark: String - Order remarks.tags: String - Order tags.orderTime: Integer - Order time in nanoseconds.domainId: String - Domain ID.tradeSource: String - Trade source.tradeType: String - Trade type.feeCurrency: String - Fee currency.takerFeeRate: String - Taker fee rate.makerFeeRate: String - Maker fee rate.createdAt: Integer - Creation timestamp in milliseconds.stop: String - Stop order type.stopTriggerTime: Integer - Stop trigger time.stopPrice: String - Stop price.
JSON Response Example
{
"code": "200000",
"data": {
"currentPage": 1,
"pageSize": 50,
"totalNum": 1,
"totalPage": 1,
"items": [
{
"id": "vs8hoo8kqjnklv4m0038lrfq",
"symbol": "KCS-USDT",
"userId": "60fe4956c43cbc0006562c2c",
"status": "NEW",
"type": "limit",
"side": "buy",
"price": "0.01000000000000000000",
"size": "0.01000000000000000000",
"funds": null,
"stp": null,
"timeInForce": "GTC",
"cancelAfter": -1,
"postOnly": false,
"hidden": false,
"iceberg": false,
"visibleSize": null,
"channel": "API",
"clientOid": "404814a0fb4311eb9098acde48001122",
"remark": null,
"tags": null,
"orderTime": 1628755183702150167,
"domainId": "kucoin",
"tradeSource": "USER",
"tradeType": "TRADE",
"feeCurrency": "USDT",
"takerFeeRate": "0.00200000000000000000",
"makerFeeRate": "0.00200000000000000000",
"createdAt": 1628755183704,
"stop": "loss",
"stopTriggerTime": null,
"stopPrice": "10.00000000000000000000"
}
]
}
}Examples
if (FALSE) { # \dontrun{
library(coro)
library(data.table)
main_async <- coro::async(function() {
# Retrieve stop orders list for BTC-USDT
stop_orders <- await(get_stop_order_list_impl(
query = list(symbol = "BTC-USDT", side = "buy", pageSize = 10)
))
print(stop_orders)
})
# Run the async function
main_async()
while (!later::loop_empty()) later::run_now()
} # }