ccxt
Version:
1,066 lines (1,064 loc) • 157 kB
JavaScript
// ----------------------------------------------------------------------------
// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
// EDIT THE CORRESPONDENT .ts FILE INSTEAD
// ---------------------------------------------------------------------------
import Exchange from './abstract/cryptocom.js';
import { Precise } from './base/Precise.js';
import { AuthenticationError, ArgumentsRequired, ExchangeError, InsufficientFunds, DDoSProtection, InvalidNonce, PermissionDenied, BadRequest, BadSymbol, NotSupported, AccountNotEnabled, OnMaintenance, InvalidOrder, RequestTimeout, OrderNotFound, RateLimitExceeded } from './base/errors.js';
import { TICK_SIZE } from './base/functions/number.js';
import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
/**
* @class cryptocom
* @augments Exchange
*/
export default class cryptocom extends Exchange {
describe() {
return this.deepExtend(super.describe(), {
'id': 'cryptocom',
'name': 'Crypto.com',
'countries': ['MT'],
'version': 'v2',
'rateLimit': 10,
'certified': true,
'pro': true,
'has': {
'CORS': false,
'spot': true,
'margin': true,
'swap': true,
'future': true,
'option': true,
'addMargin': false,
'cancelAllOrders': true,
'cancelOrder': true,
'cancelOrders': true,
'cancelOrdersForSymbols': true,
'closeAllPositions': false,
'closePosition': true,
'createMarketBuyOrderWithCost': false,
'createMarketOrderWithCost': false,
'createMarketSellOrderWithCost': false,
'createOrder': true,
'createOrders': true,
'createStopOrder': true,
'createTriggerOrder': true,
'editOrder': true,
'fetchAccounts': true,
'fetchBalance': true,
'fetchBidsAsks': false,
'fetchBorrowInterest': false,
'fetchBorrowRateHistories': false,
'fetchBorrowRateHistory': false,
'fetchClosedOrders': 'emulated',
'fetchCrossBorrowRate': false,
'fetchCrossBorrowRates': false,
'fetchCurrencies': true,
'fetchDepositAddress': true,
'fetchDepositAddresses': false,
'fetchDepositAddressesByNetwork': true,
'fetchDeposits': true,
'fetchDepositsWithdrawals': false,
'fetchDepositWithdrawFee': 'emulated',
'fetchDepositWithdrawFees': true,
'fetchFundingHistory': false,
'fetchFundingRate': false,
'fetchFundingRateHistory': true,
'fetchFundingRates': false,
'fetchGreeks': false,
'fetchIndexOHLCV': false,
'fetchIsolatedBorrowRate': false,
'fetchIsolatedBorrowRates': false,
'fetchLedger': true,
'fetchLeverage': false,
'fetchLeverageTiers': false,
'fetchMarginAdjustmentHistory': false,
'fetchMarginMode': false,
'fetchMarketLeverageTiers': false,
'fetchMarkets': true,
'fetchMarkOHLCV': false,
'fetchMySettlementHistory': false,
'fetchMyTrades': true,
'fetchOHLCV': true,
'fetchOpenOrders': true,
'fetchOrder': true,
'fetchOrderBook': true,
'fetchOrders': true,
'fetchPosition': true,
'fetchPositionHistory': false,
'fetchPositionMode': false,
'fetchPositions': true,
'fetchPositionsHistory': false,
'fetchPremiumIndexOHLCV': false,
'fetchSettlementHistory': true,
'fetchStatus': false,
'fetchTicker': true,
'fetchTickers': true,
'fetchTime': false,
'fetchTrades': true,
'fetchTradingFee': true,
'fetchTradingFees': true,
'fetchTransactionFees': false,
'fetchTransactions': false,
'fetchTransfers': false,
'fetchUnderlyingAssets': false,
'fetchVolatilityHistory': false,
'fetchWithdrawals': true,
'reduceMargin': false,
'repayCrossMargin': false,
'repayIsolatedMargin': false,
'sandbox': true,
'setLeverage': false,
'setMarginMode': false,
'setPositionMode': false,
'transfer': false,
'withdraw': true,
},
'timeframes': {
'1m': '1m',
'5m': '5m',
'15m': '15m',
'30m': '30m',
'1h': '1h',
'4h': '4h',
'6h': '6h',
'12h': '12h',
'1d': '1D',
'1w': '7D',
'2w': '14D',
'1M': '1M',
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/147792121-38ed5e36-c229-48d6-b49a-48d05fc19ed4.jpeg',
'test': {
'v1': 'https://uat-api.3ona.co/exchange/v1',
'v2': 'https://uat-api.3ona.co/v2',
'derivatives': 'https://uat-api.3ona.co/v2',
},
'api': {
'base': 'https://api.crypto.com',
'v1': 'https://api.crypto.com/exchange/v1',
'v2': 'https://api.crypto.com/v2',
'derivatives': 'https://deriv-api.crypto.com/v1',
},
'www': 'https://crypto.com/',
'referral': {
'url': 'https://crypto.com/exch/kdacthrnxt',
'discount': 0.75,
},
'doc': [
'https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html',
'https://exchange-docs.crypto.com/spot/index.html',
'https://exchange-docs.crypto.com/derivatives/index.html',
],
'fees': 'https://crypto.com/exchange/document/fees-limits',
},
'api': {
'base': {
'public': {
'get': {
'v1/public/get-announcements': 1, // no description of rate limit
},
},
},
'v1': {
'public': {
'get': {
'public/auth': 10 / 3,
'public/get-instruments': 10 / 3,
'public/get-book': 1,
'public/get-candlestick': 1,
'public/get-trades': 1,
'public/get-tickers': 1,
'public/get-valuations': 1,
'public/get-expired-settlement-price': 10 / 3,
'public/get-insurance': 1,
'public/get-risk-parameters': 1,
},
'post': {
'public/staking/get-conversion-rate': 2,
},
},
'private': {
'post': {
'private/set-cancel-on-disconnect': 10 / 3,
'private/get-cancel-on-disconnect': 10 / 3,
'private/user-balance': 10 / 3,
'private/user-balance-history': 10 / 3,
'private/get-positions': 10 / 3,
'private/create-order': 2 / 3,
'private/amend-order': 4 / 3,
'private/create-order-list': 10 / 3,
'private/cancel-order': 2 / 3,
'private/cancel-order-list': 10 / 3,
'private/cancel-all-orders': 2 / 3,
'private/close-position': 10 / 3,
'private/get-order-history': 100,
'private/get-open-orders': 10 / 3,
'private/get-order-detail': 1 / 3,
'private/get-trades': 100,
'private/change-account-leverage': 10 / 3,
'private/get-transactions': 10 / 3,
'private/create-subaccount-transfer': 10 / 3,
'private/get-subaccount-balances': 10 / 3,
'private/get-order-list': 10 / 3,
'private/create-withdrawal': 10 / 3,
'private/get-currency-networks': 10 / 3,
'private/get-deposit-address': 10 / 3,
'private/get-accounts': 10 / 3,
'private/get-withdrawal-history': 10 / 3,
'private/get-deposit-history': 10 / 3,
'private/get-fee-rate': 2,
'private/get-instrument-fee-rate': 2,
'private/staking/stake': 2,
'private/staking/unstake': 2,
'private/staking/get-staking-position': 2,
'private/staking/get-staking-instruments': 2,
'private/staking/get-open-stake': 2,
'private/staking/get-stake-history': 2,
'private/staking/get-reward-history': 2,
'private/staking/convert': 2,
'private/staking/get-open-convert': 2,
'private/staking/get-convert-history': 2,
},
},
},
'v2': {
'public': {
'get': {
'public/auth': 1,
'public/get-instruments': 1,
'public/get-book': 1,
'public/get-candlestick': 1,
'public/get-ticker': 1,
'public/get-trades': 1,
'public/margin/get-transfer-currencies': 1,
'public/margin/get-load-currenices': 1,
'public/respond-heartbeat': 1,
},
},
'private': {
'post': {
'private/set-cancel-on-disconnect': 10 / 3,
'private/get-cancel-on-disconnect': 10 / 3,
'private/create-withdrawal': 10 / 3,
'private/get-withdrawal-history': 10 / 3,
'private/get-currency-networks': 10 / 3,
'private/get-deposit-history': 10 / 3,
'private/get-deposit-address': 10 / 3,
'private/export/create-export-request': 10 / 3,
'private/export/get-export-requests': 10 / 3,
'private/export/download-export-output': 10 / 3,
'private/get-account-summary': 10 / 3,
'private/create-order': 2 / 3,
'private/cancel-order': 2 / 3,
'private/cancel-all-orders': 2 / 3,
'private/create-order-list': 10 / 3,
'private/get-order-history': 10 / 3,
'private/get-open-orders': 10 / 3,
'private/get-order-detail': 1 / 3,
'private/get-trades': 100,
'private/get-accounts': 10 / 3,
'private/get-subaccount-balances': 10 / 3,
'private/create-subaccount-transfer': 10 / 3,
'private/otc/get-otc-user': 10 / 3,
'private/otc/get-instruments': 10 / 3,
'private/otc/request-quote': 100,
'private/otc/accept-quote': 100,
'private/otc/get-quote-history': 10 / 3,
'private/otc/get-trade-history': 10 / 3,
'private/otc/create-order': 10 / 3,
},
},
},
'derivatives': {
'public': {
'get': {
'public/auth': 10 / 3,
'public/get-instruments': 10 / 3,
'public/get-book': 1,
'public/get-candlestick': 1,
'public/get-trades': 1,
'public/get-tickers': 1,
'public/get-valuations': 1,
'public/get-expired-settlement-price': 10 / 3,
'public/get-insurance': 1,
},
},
'private': {
'post': {
'private/set-cancel-on-disconnect': 10 / 3,
'private/get-cancel-on-disconnect': 10 / 3,
'private/user-balance': 10 / 3,
'private/user-balance-history': 10 / 3,
'private/get-positions': 10 / 3,
'private/create-order': 2 / 3,
'private/create-order-list': 10 / 3,
'private/cancel-order': 2 / 3,
'private/cancel-order-list': 10 / 3,
'private/cancel-all-orders': 2 / 3,
'private/close-position': 10 / 3,
'private/convert-collateral': 10 / 3,
'private/get-order-history': 100,
'private/get-open-orders': 10 / 3,
'private/get-order-detail': 1 / 3,
'private/get-trades': 100,
'private/change-account-leverage': 10 / 3,
'private/get-transactions': 10 / 3,
'private/create-subaccount-transfer': 10 / 3,
'private/get-subaccount-balances': 10 / 3,
'private/get-order-list': 10 / 3,
},
},
},
},
'fees': {
'trading': {
'maker': this.parseNumber('0.004'),
'taker': this.parseNumber('0.004'),
'tiers': {
'maker': [
[this.parseNumber('0'), this.parseNumber('0.004')],
[this.parseNumber('25000'), this.parseNumber('0.0035')],
[this.parseNumber('50000'), this.parseNumber('0.0015')],
[this.parseNumber('100000'), this.parseNumber('0.001')],
[this.parseNumber('250000'), this.parseNumber('0.0009')],
[this.parseNumber('1000000'), this.parseNumber('0.0008')],
[this.parseNumber('20000000'), this.parseNumber('0.0007')],
[this.parseNumber('100000000'), this.parseNumber('0.0006')],
[this.parseNumber('200000000'), this.parseNumber('0.0004')],
],
'taker': [
[this.parseNumber('0'), this.parseNumber('0.004')],
[this.parseNumber('25000'), this.parseNumber('0.0035')],
[this.parseNumber('50000'), this.parseNumber('0.0025')],
[this.parseNumber('100000'), this.parseNumber('0.0016')],
[this.parseNumber('250000'), this.parseNumber('0.00015')],
[this.parseNumber('1000000'), this.parseNumber('0.00014')],
[this.parseNumber('20000000'), this.parseNumber('0.00013')],
[this.parseNumber('100000000'), this.parseNumber('0.00012')],
[this.parseNumber('200000000'), this.parseNumber('0.0001')],
],
},
},
},
'options': {
'defaultType': 'spot',
'accountsById': {
'funding': 'SPOT',
'spot': 'SPOT',
'margin': 'MARGIN',
'derivatives': 'DERIVATIVES',
'swap': 'DERIVATIVES',
'future': 'DERIVATIVES',
},
'networks': {
'BEP20': 'BSC',
'ERC20': 'ETH',
'TRC20': 'TRON',
},
'broker': 'CCXT',
},
'features': {
'default': {
'sandbox': true,
'createOrder': {
'marginMode': true,
'triggerPrice': true,
// todo: implementation fix
'triggerPriceType': {
'last': true,
'mark': true,
'index': true,
},
'triggerDirection': false,
'stopLossPrice': true,
'takeProfitPrice': true,
'attachedStopLossTakeProfit': undefined,
'timeInForce': {
'IOC': true,
'FOK': true,
'PO': true,
'GTD': false,
},
'hedged': false,
'selfTradePrevention': true,
'trailing': false,
'iceberg': false,
'leverage': false,
'marketBuyByCost': true,
'marketBuyRequiresPrice': true,
},
'createOrders': {
'max': 10,
},
'fetchMyTrades': {
'marginMode': false,
'limit': 100,
'daysBack': undefined,
'untilDays': 1,
'symbolRequired': false,
},
'fetchOrder': {
'marginMode': false,
'trigger': false,
'trailing': false,
'symbolRequired': false,
},
'fetchOpenOrders': {
'marginMode': true,
'limit': 100,
'trigger': false,
'trailing': false,
'symbolRequired': false,
},
'fetchOrders': {
'marginMode': false,
'limit': 100,
'daysBack': undefined,
'untilDays': 1,
'trigger': false,
'trailing': false,
'symbolRequired': false,
},
'fetchClosedOrders': {
'marginMode': false,
'limit': 100,
'daysBack': undefined,
'daysBackCanceled': undefined,
'untilDays': 1,
'trigger': false,
'trailing': false,
'symbolRequired': false,
},
'fetchOHLCV': {
'limit': 300,
},
},
'spot': {
'extends': 'default',
},
'swap': {
'linear': {
'extends': 'default',
},
'inverse': {
'extends': 'default',
},
},
'future': {
'linear': {
'extends': 'default',
},
'inverse': {
'extends': 'default',
},
},
},
// https://exchange-docs.crypto.com/spot/index.html#response-and-reason-codes
'commonCurrencies': {
'USD_STABLE_COIN': 'USDC',
},
'precisionMode': TICK_SIZE,
'exceptions': {
'exact': {
'219': InvalidOrder,
'314': InvalidOrder,
'325': InvalidOrder,
'415': InvalidOrder,
'10001': ExchangeError,
'10002': PermissionDenied,
'10003': PermissionDenied,
'10004': BadRequest,
'10005': PermissionDenied,
'10006': DDoSProtection,
'10007': InvalidNonce,
'10008': BadRequest,
'10009': BadRequest,
'20001': BadRequest,
'20002': InsufficientFunds,
'20005': AccountNotEnabled,
'30003': BadSymbol,
'30004': BadRequest,
'30005': BadRequest,
'30006': InvalidOrder,
'30007': InvalidOrder,
'30008': InvalidOrder,
'30009': InvalidOrder,
'30010': BadRequest,
'30013': InvalidOrder,
'30014': InvalidOrder,
'30016': InvalidOrder,
'30017': InvalidOrder,
'30023': InvalidOrder,
'30024': InvalidOrder,
'30025': InvalidOrder,
'40001': BadRequest,
'40002': BadRequest,
'40003': BadRequest,
'40004': BadRequest,
'40005': BadRequest,
'40006': BadRequest,
'40007': BadRequest,
'40101': AuthenticationError,
'40102': InvalidNonce,
'40103': AuthenticationError,
'40104': AuthenticationError,
'40107': BadRequest,
'40401': OrderNotFound,
'40801': RequestTimeout,
'42901': RateLimitExceeded,
'43005': InvalidOrder,
'43003': InvalidOrder,
'43004': InvalidOrder,
'43012': BadRequest,
'50001': ExchangeError,
'9010001': OnMaintenance, // {"code":9010001,"message":"SYSTEM_MAINTENANCE","details":"Crypto.com Exchange is currently under maintenance. Please refer to https://status.crypto.com for more details."}
},
'broad': {},
},
});
}
/**
* @method
* @name cryptocom#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-currency-networks
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
async fetchCurrencies(params = {}) {
// this endpoint requires authentication
if (!this.checkRequiredCredentials(false)) {
return undefined;
}
let skipFetchCurrencies = false;
[skipFetchCurrencies, params] = this.handleOptionAndParams(params, 'fetchCurrencies', 'skipFetchCurrencies', false);
if (skipFetchCurrencies) {
// sub-accounts can't access this endpoint
return undefined;
}
let response = {};
try {
response = await this.v1PrivatePostPrivateGetCurrencyNetworks(params);
}
catch (e) {
if (e instanceof ExchangeError) {
// sub-accounts can't access this endpoint
// {"code":"10001","msg":"SYS_ERROR"}
return undefined;
}
throw e;
// do nothing
// sub-accounts can't access this endpoint
}
//
// {
// "id": "1747502328559",
// "method": "private/get-currency-networks",
// "code": "0",
// "result": {
// "update_time": "1747502281000",
// "currency_map": {
// "USDT": {
// "full_name": "Tether USD",
// "default_network": "ETH",
// "network_list": [
// {
// "network_id": "ETH",
// "withdrawal_fee": "10.00000000",
// "withdraw_enabled": true,
// "min_withdrawal_amount": "20.0",
// "deposit_enabled": true,
// "confirmation_required": "32"
// },
// {
// "network_id": "CRONOS",
// "withdrawal_fee": "0.18000000",
// "withdraw_enabled": true,
// "min_withdrawal_amount": "0.35",
// "deposit_enabled": true,
// "confirmation_required": "15"
// },
// {
// "network_id": "SOL",
// "withdrawal_fee": "5.31000000",
// "withdraw_enabled": true,
// "min_withdrawal_amount": "10.62",
// "deposit_enabled": true,
// "confirmation_required": "1"
// }
// ]
// }
// }
// }
// }
//
const resultData = this.safeDict(response, 'result', {});
const currencyMap = this.safeDict(resultData, 'currency_map', {});
const keys = Object.keys(currencyMap);
const result = {};
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const currency = currencyMap[key];
const id = key;
const code = this.safeCurrencyCode(id);
const networks = {};
const chains = this.safeList(currency, 'network_list', []);
for (let j = 0; j < chains.length; j++) {
const chain = chains[j];
const networkId = this.safeString(chain, 'network_id');
const network = this.networkIdToCode(networkId);
networks[network] = {
'info': chain,
'id': networkId,
'network': network,
'active': undefined,
'deposit': this.safeBool(chain, 'deposit_enabled', false),
'withdraw': this.safeBool(chain, 'withdraw_enabled', false),
'fee': this.safeNumber(chain, 'withdrawal_fee'),
'precision': undefined,
'limits': {
'withdraw': {
'min': this.safeNumber(chain, 'min_withdrawal_amount'),
'max': undefined,
},
},
};
}
result[code] = this.safeCurrencyStructure({
'info': currency,
'id': id,
'code': code,
'name': this.safeString(currency, 'full_name'),
'active': undefined,
'deposit': undefined,
'withdraw': undefined,
'fee': undefined,
'precision': undefined,
'limits': {
'amount': {
'min': undefined,
'max': undefined,
},
},
'type': 'crypto',
'networks': networks,
});
}
return result;
}
/**
* @method
* @name cryptocom#fetchMarkets
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-instruments
* @description retrieves data on all markets for cryptocom
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
async fetchMarkets(params = {}) {
const response = await this.v1PublicGetPublicGetInstruments(params);
//
// {
// "id": 1,
// "method": "public/get-instruments",
// "code": 0,
// "result": {
// "data": [
// {
// "symbol": "BTC_USDT",
// "inst_type": "CCY_PAIR",
// "display_name": "BTC/USDT",
// "base_ccy": "BTC",
// "quote_ccy": "USDT",
// "quote_decimals": 2,
// "quantity_decimals": 5,
// "price_tick_size": "0.01",
// "qty_tick_size": "0.00001",
// "max_leverage": "50",
// "tradable": true,
// "expiry_timestamp_ms": 0,
// "beta_product": false,
// "margin_buy_enabled": false,
// "margin_sell_enabled": true
// },
// {
// "symbol": "RUNEUSD-PERP",
// "inst_type": "PERPETUAL_SWAP",
// "display_name": "RUNEUSD Perpetual",
// "base_ccy": "RUNE",
// "quote_ccy": "USD",
// "quote_decimals": 3,
// "quantity_decimals": 1,
// "price_tick_size": "0.001",
// "qty_tick_size": "0.1",
// "max_leverage": "50",
// "tradable": true,
// "expiry_timestamp_ms": 0,
// "beta_product": false,
// "underlying_symbol": "RUNEUSD-INDEX",
// "contract_size": "1",
// "margin_buy_enabled": false,
// "margin_sell_enabled": false
// },
// {
// "symbol": "ETHUSD-230825",
// "inst_type": "FUTURE",
// "display_name": "ETHUSD Futures 20230825",
// "base_ccy": "ETH",
// "quote_ccy": "USD",
// "quote_decimals": 2,
// "quantity_decimals": 4,
// "price_tick_size": "0.01",
// "qty_tick_size": "0.0001",
// "max_leverage": "100",
// "tradable": true,
// "expiry_timestamp_ms": 1692950400000,
// "beta_product": false,
// "underlying_symbol": "ETHUSD-INDEX",
// "contract_size": "1",
// "margin_buy_enabled": false,
// "margin_sell_enabled": false
// },
// {
// "symbol": "BTCUSD-230630-CW30000",
// "inst_type": "WARRANT",
// "display_name": "BTCUSD-230630-CW30000",
// "base_ccy": "BTC",
// "quote_ccy": "USD",
// "quote_decimals": 3,
// "quantity_decimals": 0,
// "price_tick_size": "0.001",
// "qty_tick_size": "10",
// "max_leverage": "50",
// "tradable": true,
// "expiry_timestamp_ms": 1688112000000,
// "beta_product": false,
// "underlying_symbol": "BTCUSD-INDEX",
// "put_call": "CALL",
// "strike": "30000",
// "contract_size": "0.0001",
// "margin_buy_enabled": false,
// "margin_sell_enabled": false
// },
// ]
// }
// }
//
const resultResponse = this.safeDict(response, 'result', {});
const data = this.safeList(resultResponse, 'data', []);
const result = [];
for (let i = 0; i < data.length; i++) {
const market = data[i];
const inst_type = this.safeString(market, 'inst_type');
const spot = inst_type === 'CCY_PAIR';
const swap = inst_type === 'PERPETUAL_SWAP';
const future = inst_type === 'FUTURE';
const option = inst_type === 'WARRANT';
const baseId = this.safeString(market, 'base_ccy');
const quoteId = this.safeString(market, 'quote_ccy');
const settleId = spot ? undefined : quoteId;
const base = this.safeCurrencyCode(baseId);
const quote = this.safeCurrencyCode(quoteId);
const settle = spot ? undefined : this.safeCurrencyCode(settleId);
const optionType = this.safeStringLower(market, 'put_call');
const strike = this.safeString(market, 'strike');
const marginBuyEnabled = this.safeBool(market, 'margin_buy_enabled');
const marginSellEnabled = this.safeBool(market, 'margin_sell_enabled');
const expiryString = this.omitZero(this.safeString(market, 'expiry_timestamp_ms'));
const expiry = (expiryString !== undefined) ? parseInt(expiryString) : undefined;
let symbol = base + '/' + quote;
let type = undefined;
let contract = undefined;
if (inst_type === 'CCY_PAIR') {
type = 'spot';
contract = false;
}
else if (inst_type === 'PERPETUAL_SWAP') {
type = 'swap';
symbol = symbol + ':' + quote;
contract = true;
}
else if (inst_type === 'FUTURE') {
type = 'future';
symbol = symbol + ':' + quote + '-' + this.yymmdd(expiry);
contract = true;
}
else if (inst_type === 'WARRANT') {
type = 'option';
const symbolOptionType = (optionType === 'call') ? 'C' : 'P';
symbol = symbol + ':' + quote + '-' + this.yymmdd(expiry) + '-' + strike + '-' + symbolOptionType;
contract = true;
}
result.push({
'id': this.safeString(market, 'symbol'),
'symbol': symbol,
'base': base,
'quote': quote,
'settle': settle,
'baseId': baseId,
'quoteId': quoteId,
'settleId': settleId,
'type': type,
'spot': spot,
'margin': ((marginBuyEnabled) || (marginSellEnabled)),
'swap': swap,
'future': future,
'option': option,
'active': this.safeBool(market, 'tradable'),
'contract': contract,
'linear': (contract) ? true : undefined,
'inverse': (contract) ? false : undefined,
'contractSize': this.safeNumber(market, 'contract_size'),
'expiry': expiry,
'expiryDatetime': this.iso8601(expiry),
'strike': this.parseNumber(strike),
'optionType': optionType,
'precision': {
'price': this.parseNumber(this.safeString(market, 'price_tick_size')),
'amount': this.parseNumber(this.safeString(market, 'qty_tick_size')),
},
'limits': {
'leverage': {
'min': this.parseNumber('1'),
'max': this.safeNumber(market, 'max_leverage'),
},
'amount': {
'min': undefined,
'max': undefined,
},
'price': {
'min': undefined,
'max': undefined,
},
'cost': {
'min': undefined,
'max': undefined,
},
},
'created': undefined,
'info': market,
});
}
return result;
}
/**
* @method
* @name cryptocom#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-tickers
* @see https://exchange-docs.crypto.com/derivatives/index.html#public-get-tickers
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
*/
async fetchTickers(symbols = undefined, params = {}) {
await this.loadMarkets();
let market = undefined;
const request = {};
if (symbols !== undefined) {
let symbol = undefined;
if (Array.isArray(symbols)) {
const symbolsLength = symbols.length;
if (symbolsLength > 1) {
throw new BadRequest(this.id + ' fetchTickers() symbols argument cannot contain more than 1 symbol');
}
symbol = symbols[0];
}
else {
symbol = symbols;
}
market = this.market(symbol);
request['instrument_name'] = market['id'];
}
const response = await this.v1PublicGetPublicGetTickers(this.extend(request, params));
//
// {
// "id": -1,
// "method": "public/get-tickers",
// "code": 0,
// "result": {
// "data": [
// {
// "i": "AVAXUSD-PERP",
// "h": "13.209",
// "l": "12.148",
// "a": "13.209",
// "v": "1109.8",
// "vv": "14017.33",
// "c": "0.0732",
// "b": "13.210",
// "k": "13.230",
// "oi": "10888.9",
// "t": 1687402657575
// },
// ]
// }
// }
//
const result = this.safeDict(response, 'result', {});
const data = this.safeList(result, 'data', []);
return this.parseTickers(data, symbols);
}
/**
* @method
* @name cryptocom#fetchTicker
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-tickers
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
*/
async fetchTicker(symbol, params = {}) {
await this.loadMarkets();
symbol = this.symbol(symbol);
const tickers = await this.fetchTickers([symbol], params);
return this.safeValue(tickers, symbol);
}
/**
* @method
* @name cryptocom#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-order-history
* @param {string} symbol unified market symbol of the market the orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for, max date range is one day
* @param {int} [limit] the maximum number of order structures to retrieve, default 100 max 100
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets();
let paginate = false;
[paginate, params] = this.handleOptionAndParams(params, 'fetchOrders', 'paginate');
if (paginate) {
return await this.fetchPaginatedCallDynamic('fetchOrders', symbol, since, limit, params);
}
let market = undefined;
const request = {};
if (symbol !== undefined) {
market = this.market(symbol);
request['instrument_name'] = market['id'];
}
if (since !== undefined) {
request['start_time'] = since;
}
if (limit !== undefined) {
request['limit'] = limit;
}
const until = this.safeInteger(params, 'until');
params = this.omit(params, ['until']);
if (until !== undefined) {
request['end_time'] = until;
}
const response = await this.v1PrivatePostPrivateGetOrderHistory(this.extend(request, params));
//
// {
// "id": 1686881486183,
// "method": "private/get-order-history",
// "code": 0,
// "result": {
// "data": [
// {
// "account_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
// "order_id": "6142909895014042762",
// "client_oid": "4e918597-1234-4321-8201-a7577e1e1d91",
// "order_type": "MARKET",
// "time_in_force": "GOOD_TILL_CANCEL",
// "side": "SELL",
// "exec_inst": [ ],
// "quantity": "0.00024",
// "order_value": "5.7054672",
// "maker_fee_rate": "0",
// "taker_fee_rate": "0",
// "avg_price": "25023.97",
// "trigger_price": "0",
// "ref_price": "0",
// "ref_price_type": "NULL_VAL",
// "cumulative_quantity": "0.00024",
// "cumulative_value": "6.0057528",
// "cumulative_fee": "0.001501438200",
// "status": "FILLED",
// "update_user_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
// "order_date": "2023-06-15",
// "instrument_name": "BTC_USD",
// "fee_instrument_name": "USD",
// "create_time": 1686805465891,
// "create_time_ns": "1686805465891812578",
// "update_time": 1686805465891
// }
// ]
// }
// }
//
const data = this.safeDict(response, 'result', {});
const orders = this.safeList(data, 'data', []);
return this.parseOrders(orders, market, since, limit);
}
/**
* @method
* @name cryptocom#fetchTrades
* @description get a list of the most recent trades for a particular symbol
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-trades
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch, maximum date range is one day
* @param {int} [limit] the maximum number of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
*/
async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets();
let paginate = false;
[paginate, params] = this.handleOptionAndParams(params, 'fetchTrades', 'paginate');
if (paginate) {
return await this.fetchPaginatedCallDynamic('fetchTrades', symbol, since, limit, params);
}
const market = this.market(symbol);
const request = {
'instrument_name': market['id'],
};
if (since !== undefined) {
request['start_ts'] = since;
}
if (limit !== undefined) {
request['count'] = limit;
}
const until = this.safeInteger(params, 'until');
params = this.omit(params, ['until']);
if (until !== undefined) {
request['end_ts'] = until;
}
const response = await this.v1PublicGetPublicGetTrades(this.extend(request, params));
//
// {
// "id": -1,
// "method": "public/get-trades",
// "code": 0,
// "result": {
// "data": [
// {
// "s": "sell",
// "p": "26386.00",
// "q": "0.00453",
// "t": 1686944282062,
// "tn" : 1704476468851524373,
// "d": "4611686018455979970",
// "i": "BTC_USD"
// },
// ]
// }
// }
//
const result = this.safeDict(response, 'result', {});
const trades = this.safeList(result, 'data', []);
return this.parseTrades(trades, market, since, limit);
}
/**
* @method
* @name cryptocom#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-candlestick
* @par