-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
coinex futures
github-actions[bot] edited this page Jun 11, 2026
·
2 revisions
'use strict';
const ccxt = require ('../../ccxt');
console.log ('CCXT Version:', ccxt.version)
let exchange = new ccxt.coinex({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET_KEY',
})
// Example 1 :: Swap : fetch balance, create a limit swap order with leverage
async function example1 () {
exchange['options']['defaultType'] = 'swap';
exchange.options['defaultMarginMode'] = 'cross' // or isolated
await exchange.loadMarkets ();
const symbol = 'ADA/USDT:USDT';
// fetchBalance
const balance = await exchange.fetchBalance ();
console.log (balance)
// set the desired leverage (has to be made before placing the order and for a specific symbol)
const leverage = 8;
const leverage_response = await exchange.setLeverage(leverage, symbol)
// create limit order
const amount = 50;
const price = 0.3 // adjust this accordingly
const createOrder = await exchange.createOrder (symbol, 'limit', 'buy', amount, price);
console.log ('Created order id:', createOrder['id'])
}
// Example 2 :: Swap :: open a position and close it
async function example2 () {
exchange['options']['defaultType'] = 'swap';
exchange.options['defaultMarginMode'] = 'cross' // or isolated
await exchange.loadMarkets ();
const symbol = 'ADA/USDT:USDT';
// fetchBalance
const balance = await exchange.fetchBalance ();
console.log (balance)
// set the desired leverage (has to be made before placing the order and for a specific symbol)
const leverage = 8;
const leverage_response = await exchange.setLeverage(leverage, symbol)
// create market order and open position
const amount = 50;
const createOrder = await exchange.createOrder (symbol, 'market', 'buy', amount);
console.log ('Created order id:', createOrder['id'])
// check if the order was filled and the position opened
const position = await exchange.fetchPositions (symbol);
console.log (position)
// close position (assuming it was already opened) by issuing an order in the opposite direction
const params = {
'reduce_only': true
}
const closePositionOrder = await exchange.createOrder (symbol, 'market', 'sell', amount, undefined, params);
console.log (closePositionOrder);
}
// -----------------------------------------------------------------------------------------
async function main () {
await example1 ();
await example2 ();
}
main ();(If the page is not being rendered for you, you can refer to the mirror at https://docs.ccxt.com/)
- Install
- Examples
- Manual
- CCXT Pro
- Contributing
- Supported Exchanges
- Exchanges By Country
- API Spec By Method
- FAQ
- Changelog
- Awesome
- API Spec by Exchange
- fetchCurrencies
- alpaca
- apex
- ascendex
- aster
- backpack
- bigone
- binance
- bingx
- bit2c
- bitbank
- bitbns
- bitfinex
- bitflyer
- bitget
- bithumb
- bitmart
- bitmex
- bitopro
- bitrue
- bitso
- bitstamp
- bitteam
- bittrade
- bitvavo
- blockchaincom
- blofin
- btcbox
- btcmarkets
- btcturk
- bullish
- bybit
- bydfi
- cex
- coinbase
- coinbaseexchange
- coinbaseinternational
- coincheck
- coinex
- coinmate
- coinmetro
- coinone
- coinsph
- coinspot
- cryptocom
- cryptomus
- deepcoin
- delta
- deribit
- derive
- digifinex
- dydx
- exmo
- extended
- foxbit
- gate
- gemini
- grvt
- hashkey
- hibachi
- hitbtc
- hollaex
- htx
- hyperliquid
- independentreserve
- indodax
- kraken
- krakenfutures
- kucoin
- fetchBidsAsks
- latoken
- lbank
- lighter
- luno
- mercado
- mexc
- modetrade
- ndax
- novadax
- okx
- onetrading
- p2b
- pacifica
- paradex
- paymium
- phemex
- poloniex
- tokocrypto
- toobit
- upbit
- weex
- whitebit
- woo
- woofipro
- xt
- zaif
- fetchStatus