KucoinFuturesAccount: Futures Account and Position Management
Source:R/KucoinFuturesAccount.R
KucoinFuturesAccount.RdKucoinFuturesAccount: Futures Account and Position Management
KucoinFuturesAccount: Futures Account and Position Management
Details
Provides methods for querying futures account details, managing positions, configuring margin mode and leverage, and tracking funding fee history. Inherits from KucoinBase.
Endpoints Covered
| Method | Endpoint | HTTP |
| get_account_overview | GET /api/v1/account-overview | GET |
| get_position | GET /api/v2/position | GET |
| get_positions | GET /api/v1/positions | GET |
| get_positions_history | GET /api/v1/history-positions | GET |
| get_margin_mode | GET /api/v1/marginMode | GET |
| set_margin_mode | POST /api/v1/marginMode | POST |
| get_cross_margin_leverage | GET /api/v1/crossMarginLeverage | GET |
| set_cross_margin_leverage | POST /api/v1/crossMarginLeverage | POST |
| get_max_open_size | GET /api/v1/maxOpenSize | GET |
| get_max_withdraw_margin | GET /api/v1/maxWithdrawMargin | GET |
| add_isolated_margin | POST /api/v1/marginDepositIn | POST |
| remove_isolated_margin | POST /api/v1/marginWithdrawOut | POST |
| get_risk_limit | GET /api/v1/contracts/risk-limit/{symbol} | GET |
| get_funding_history | GET /api/v1/funding-history | GET |
Super class
kucoin::KucoinBase -> KucoinFuturesAccount
Methods
Method new()
Create a new KucoinFuturesAccount instance.
Usage
KucoinFuturesAccount$new(
keys = get_api_keys(),
base_url = get_futures_base_url(),
async = FALSE,
time_source = c("local", "server")
)Arguments
keysList; API credentials from
get_api_keys().base_urlCharacter; Futures API base URL. Defaults to
get_futures_base_url().asyncLogical; if TRUE, methods return promises.
time_sourceCharacter;
"local"or"server".
Method get_account_overview()
Get Account Overview
Retrieves the futures account overview, including balance, equity, margin, and P&L.
Workflow
Request: Authenticated GET with
currencyquery parameter.Parsing: Returns a single-row
data.tablewith account balance details.
curl
curl --location --request GET \
'https://api-futures.kucoin.com/api/v1/account-overview?currency=USDT' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Returns
A single-row data.table with columns:
account_equity(numeric): Total account equity.unrealised_pnl(numeric): Unrealised profit and loss.margin_balance(numeric): Margin balance (equity + unrealised PNL).position_margin(numeric): Margin held by open positions.order_margin(numeric): Margin held by open orders.frozen_funds(numeric): Frozen funds.available_balance(numeric): Available balance for trading.currency(character): Settlement currency code.
Method get_position()
Get Position Details
Retrieves position details for a specific symbol.
Workflow
Request: Authenticated GET with
symbolquery parameter.Parsing: Returns a single-row
data.tablewith position details.Timestamp Conversion: Coerces
opening_timestampandcurrent_timestampfrom milliseconds to POSIXct.
curl
curl --location --request GET \
'https://api-futures.kucoin.com/api/v2/position?symbol=XBTUSDTM' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'JSON Response
{
"code": "200000",
"data": {
"id": "615ba79f27adbe000854c352",
"symbol": "XBTUSDTM",
"autoDeposit": false,
"realLeverage": 2.05,
"crossMode": false,
"delevPercentage": 0.66,
"currentQty": 1,
"currentCost": "40.008",
"currentComm": "0.0240048",
"unrealisedCost": "40.008",
"realisedGrossCost": "0.0",
"realisedCost": "0.0240048",
"isOpen": true,
"markPrice": 40014.93,
"markValue": "40.01493",
"posCost": "40.008",
"posInit": "20.004",
"posComm": "0.02400588",
"posMargin": "20.02800588",
"unrealisedPnl": 0.00693,
"unrealisedPnlPcnt": 0.0002,
"avgEntryPrice": "40008.0",
"liquidationPrice": "20332.0",
"bankruptPrice": "20012.0",
"settleCurrency": "USDT",
"marginMode": "ISOLATED",
"openingTimestamp": 1729176273859,
"currentTimestamp": 1729176573859
}
}Returns
A data.table with columns:
id(character): Position identifier.symbol(character): Contract symbol.real_leverage(numeric): Effective leverage.cross_mode(logical): Whether cross margin mode is active.current_qty(integer): Current position size in contracts.current_cost(character): Cost of the current position.is_open(logical): Whether the position is open.mark_price(numeric): Current mark price.mark_value(character): Mark value of the position.pos_margin(character): Position margin.unrealised_pnl(numeric): Unrealised profit and loss.avg_entry_price(character): Average entry price.liquidation_price(character): Estimated liquidation price.margin_mode(character):"ISOLATED"or"CROSS".opening_timestamp(POSIXct): Position opened time (coerced from milliseconds).current_timestamp(POSIXct): Current server time (coerced from milliseconds).
Method get_positions()
Get All Positions
Retrieves all open positions.
Workflow
Request: Authenticated GET with optional
currencyquery parameter.Parsing: Returns a multi-row
data.tablewith one row per open position.Timestamp Conversion: Coerces
opening_timestampandcurrent_timestampfrom milliseconds to POSIXct.
curl
curl --location --request GET \
'https://api-futures.kucoin.com/api/v1/positions?currency=USDT' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'JSON Response
{
"code": "200000",
"data": [
{
"id": "615ba79f27adbe000854c352",
"symbol": "XBTUSDTM",
"realLeverage": 2.05,
"crossMode": false,
"currentQty": 1,
"currentCost": "40.008",
"isOpen": true,
"markPrice": 40014.93,
"markValue": "40.01493",
"posMargin": "20.02800588",
"unrealisedPnl": 0.00693,
"avgEntryPrice": "40008.0",
"liquidationPrice": "20332.0",
"marginMode": "ISOLATED",
"openingTimestamp": 1729176273859,
"currentTimestamp": 1729176573859
},
{
"id": "615ba7a027adbe000854c358",
"symbol": "ETHUSDTM",
"realLeverage": 5.12,
"crossMode": true,
"currentQty": 10,
"currentCost": "200.50",
"isOpen": true,
"markPrice": 2210.45,
"markValue": "221.045",
"posMargin": "44.209",
"unrealisedPnl": 0.545,
"avgEntryPrice": "2005.0",
"liquidationPrice": "1650.0",
"marginMode": "CROSS",
"openingTimestamp": 1729176273859,
"currentTimestamp": 1729176573859
}
]
}Method get_positions_history()
Get Position History
Retrieves historical position records.
Workflow
Request: Authenticated GET with optional query parameters for filtering and pagination.
Parsing: Extracts
itemsfrom paginated response into adata.table.Timestamp Conversion: Coerces
open_timeandclose_timefrom milliseconds to POSIXct.
curl
curl --location --request GET \
'https://api-futures.kucoin.com/api/v1/history-positions?symbol=XBTUSDTM&limit=20' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'JSON Response
{
"code": "200000",
"data": {
"currentPage": 1,
"pageSize": 20,
"totalNum": 1,
"totalPage": 1,
"items": [
{
"closeId": "615ba79f27adbe000854c360",
"positionId": "615ba79f27adbe000854c352",
"uid": 123456789,
"userId": "5e1234567890abcdef123456",
"symbol": "XBTUSDTM",
"settleCurrency": "USDT",
"leverage": "10",
"type": "Close",
"pnl": "2.345",
"realisedGrossCost": "2.5",
"withdrawPnl": "0",
"tradeFee": "0.155",
"fundingFee": "0.012",
"openTime": 1729176273859,
"closeTime": 1729262673859,
"openPrice": "40008.0",
"closePrice": "40250.0",
"marginMode": "ISOLATED"
}
]
}
}Usage
KucoinFuturesAccount$get_positions_history(query = list())Returns
A data.table with columns:
symbol(character): Contract symbol.settle_currency(character): Settlement currency.realised_gross_pnl(character): Gross realised PNL.realised_pnl(character): Net realised PNL (after fees).leverage(integer): Leverage used.type(character): Close type (e.g.,"Close").open_time(POSIXct): Position opened time (coerced from milliseconds).close_time(POSIXct): Position closed time (coerced from milliseconds).
Method get_margin_mode()
Get Margin Mode
Retrieves the current margin mode for a symbol.
Workflow
Request: Authenticated GET with
symbolquery parameter.Parsing: Returns a single-row
data.tablewith the current margin mode.
curl
curl --location --request GET \
'https://api-futures.kucoin.com/api/v1/marginMode?symbol=XBTUSDTM' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Method set_margin_mode()
Set Margin Mode
Switches the margin mode for a symbol between ISOLATED and CROSS.
Workflow
Build Body: Constructs JSON body with
symbolandmarginMode.Request: Authenticated POST to the margin mode endpoint.
Parsing: Returns a single-row
data.tableconfirming the updated mode.
curl
curl --location --request POST 'https://api-futures.kucoin.com/api/v1/marginMode' \
--header 'Content-Type: application/json' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2' \
--data-raw '{"symbol":"XBTUSDTM","marginMode":"CROSS"}'Method get_cross_margin_leverage()
Get Cross Margin Leverage
Retrieves the current cross margin leverage for a symbol.
Workflow
Request: Authenticated GET with
symbolquery parameter.Parsing: Returns a single-row
data.tablewith the current leverage setting.
curl
curl --location --request GET \
'https://api-futures.kucoin.com/api/v1/crossMarginLeverage?symbol=XBTUSDTM' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Method set_cross_margin_leverage()
Set Cross Margin Leverage
Modifies the cross margin leverage for a symbol.
Workflow
Build Body: Constructs JSON body with
symbolandleverage.Request: Authenticated POST to the cross margin leverage endpoint.
Parsing: Returns a single-row
data.tableconfirming the updated leverage.
curl
curl --location --request POST 'https://api-futures.kucoin.com/api/v1/crossMarginLeverage' \
--header 'Content-Type: application/json' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2' \
--data-raw '{"symbol":"XBTUSDTM","leverage":"10"}'Method get_max_open_size()
Get Maximum Open Size
Retrieves the maximum number of contracts that can be opened.
Workflow
Request: Authenticated GET with
symbol,price, andleveragequery parameters.Parsing: Returns a single-row
data.tablewith maximum buy and sell open sizes.
curl
curl --location --request GET \
'https://api-futures.kucoin.com/api/v1/maxOpenSize?symbol=XBTUSDTM&price=40000&leverage=10' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Method get_max_withdraw_margin()
Get Maximum Withdrawable Margin
Retrieves the maximum margin that can be withdrawn from an isolated position.
Workflow
Request: Authenticated GET with
symbolquery parameter.Parsing: Returns a single-row
data.tablewith the maximum withdrawable margin.
curl
curl --location --request GET \
'https://api-futures.kucoin.com/api/v1/maxWithdrawMargin?symbol=XBTUSDTM' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Method add_isolated_margin()
Add Isolated Margin
Deposits additional margin into an isolated margin position.
Workflow
Build Body: Constructs JSON body with
symbol,margin, andbizNo.Request: Authenticated POST to the margin deposit endpoint.
Parsing: Returns a single-row
data.tableconfirming the deposit.
curl
curl --location --request POST 'https://api-futures.kucoin.com/api/v1/marginDepositIn' \
--header 'Content-Type: application/json' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2' \
--data-raw '{"symbol":"XBTUSDTM","margin":5,"bizNo":"abc123-unique-id"}'Method remove_isolated_margin()
Remove Isolated Margin
Withdraws excess margin from an isolated margin position.
Workflow
Build Body: Constructs JSON body with
symbolandwithdrawAmount.Request: Authenticated POST to the margin withdrawal endpoint.
Parsing: Returns a single-row
data.tableconfirming the withdrawal.
curl
curl --location --request POST 'https://api-futures.kucoin.com/api/v1/marginWithdrawOut' \
--header 'Content-Type: application/json' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2' \
--data-raw '{"symbol":"XBTUSDTM","withdrawAmount":3}'Method get_risk_limit()
Get Risk Limit Level
Retrieves risk limit tiers for a futures contract.
Workflow
Request: Authenticated GET with
symbolembedded in the URL path.Parsing: Returns a multi-row
data.tablewith one row per risk limit tier.
curl
curl --location --request GET \
'https://api-futures.kucoin.com/api/v1/contracts/risk-limit/XBTUSDTM' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'JSON Response
{
"code": "200000",
"data": [
{
"symbol": "XBTUSDTM",
"level": 1,
"maxRiskLimit": 500000,
"minRiskLimit": 0,
"maxLeverage": 125,
"initialMargin": 0.008,
"maintainMargin": 0.004
},
{
"symbol": "XBTUSDTM",
"level": 2,
"maxRiskLimit": 1000000,
"minRiskLimit": 500000,
"maxLeverage": 100,
"initialMargin": 0.01,
"maintainMargin": 0.005
},
{
"symbol": "XBTUSDTM",
"level": 3,
"maxRiskLimit": 2000000,
"minRiskLimit": 1000000,
"maxLeverage": 75,
"initialMargin": 0.0133,
"maintainMargin": 0.007
}
]
}Returns
A data.table with columns:
symbol(character): Contract symbol.level(integer): Risk limit tier level.max_risk_limit(integer): Maximum position value for this tier.min_risk_limit(integer): Minimum position value for this tier.max_leverage(integer): Maximum leverage at this tier.initial_margin(numeric): Initial margin rate.maintain_margin(numeric): Maintenance margin rate.
Method get_funding_history()
Get Private Funding Fee History
Retrieves your personal funding fee settlement records.
Workflow
Request: Authenticated GET with
symbol(required) and optional pagination/filtering query parameters.Parsing: Extracts
dataListfrom response into adata.table.Timestamp Conversion: Coerces
time_pointfrom milliseconds to POSIXct.
curl
curl --location --request GET \
'https://api-futures.kucoin.com/api/v1/funding-history?symbol=XBTUSDTM&maxCount=100' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'JSON Response
{
"code": "200000",
"data": {
"dataList": [
{
"id": 1742547891234,
"symbol": "XBTUSDTM",
"timePoint": 1729176000000,
"fundingRate": 0.0001,
"markPrice": 40125.56,
"positionQty": 10,
"positionCost": "400.12556",
"funding": "-0.04001256",
"settleCurrency": "USDT"
},
{
"id": 1742547891235,
"symbol": "XBTUSDTM",
"timePoint": 1729147200000,
"fundingRate": -0.00005,
"markPrice": 39987.12,
"positionQty": 10,
"positionCost": "399.8712",
"funding": "0.01999356",
"settleCurrency": "USDT"
}
],
"hasMore": false
}
}Usage
KucoinFuturesAccount$get_funding_history(symbol, query = list())Arguments
symbolCharacter; futures symbol.
queryNamed list; additional query parameters. Optional:
startAt,endAt,reverse,offset,forward,maxCount.
Returns
A data.table with columns:
id(integer): Record identifier.symbol(character): Contract symbol.time_point(POSIXct): Funding settlement time (coerced from milliseconds).funding_rate(numeric): Funding rate applied.mark_price(numeric): Mark price at settlement.position_qty(integer): Position size at settlement.position_cost(character): Position cost at settlement.funding(character): Funding fee amount (negative = paid, positive = received).settle_currency(character): Settlement currency.
Examples
if (FALSE) { # \dontrun{
futures_account <- KucoinFuturesAccount$new()
# Get account overview
overview <- futures_account$get_account_overview(currency = "USDT")
# Get open positions
positions <- futures_account$get_positions()
# Get position for a specific symbol
pos <- futures_account$get_position("XBTUSDTM")
} # }