ccxt
Version:
1,061 lines (1,059 loc) • 92.3 kB
JavaScript
'use strict';
var coinsph$1 = require('./abstract/coinsph.js');
var errors = require('./base/errors.js');
var number = require('./base/functions/number.js');
var Precise = require('./base/Precise.js');
var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
// ----------------------------------------------------------------------------
/**
* @class coinsph
* @augments Exchange
*/
class coinsph extends coinsph$1 {
describe() {
return this.deepExtend(super.describe(), {
'id': 'coinsph',
'name': 'Coins.ph',
'countries': ['PH'],
'version': 'v1',
'rateLimit': 50,
'certified': false,
'pro': false,
'has': {
'CORS': undefined,
'spot': true,
'margin': false,
'swap': false,
'future': false,
'option': false,
'addMargin': false,
'cancelAllOrders': true,
'cancelOrder': true,
'cancelOrders': false,
'closeAllPositions': false,
'closePosition': false,
'createDepositAddress': false,
'createMarketBuyOrderWithCost': true,
'createMarketOrderWithCost': false,
'createMarketSellOrderWithCost': false,
'createOrder': true,
'createPostOnlyOrder': false,
'createReduceOnlyOrder': false,
'createStopLimitOrder': true,
'createStopMarketOrder': true,
'createStopOrder': true,
'deposit': true,
'editOrder': false,
'fetchAccounts': false,
'fetchBalance': true,
'fetchBidsAsks': false,
'fetchBorrowInterest': false,
'fetchBorrowRateHistories': false,
'fetchBorrowRateHistory': false,
'fetchCanceledOrders': false,
'fetchClosedOrder': false,
'fetchClosedOrders': true,
'fetchCrossBorrowRate': false,
'fetchCrossBorrowRates': false,
'fetchCurrencies': false,
'fetchDeposit': undefined,
'fetchDepositAddress': true,
'fetchDepositAddresses': false,
'fetchDepositAddressesByNetwork': false,
'fetchDeposits': true,
'fetchDepositWithdrawFee': false,
'fetchDepositWithdrawFees': false,
'fetchFundingHistory': false,
'fetchFundingRate': false,
'fetchFundingRateHistory': false,
'fetchFundingRates': false,
'fetchIndexOHLCV': false,
'fetchIsolatedBorrowRate': false,
'fetchIsolatedBorrowRates': false,
'fetchL3OrderBook': false,
'fetchLedger': false,
'fetchLeverage': false,
'fetchLeverageTiers': false,
'fetchMarketLeverageTiers': false,
'fetchMarkets': true,
'fetchMarkOHLCV': false,
'fetchMyTrades': true,
'fetchOHLCV': true,
'fetchOpenInterestHistory': false,
'fetchOpenOrder': undefined,
'fetchOpenOrders': true,
'fetchOrder': true,
'fetchOrderBook': true,
'fetchOrderBooks': false,
'fetchOrders': false,
'fetchOrderTrades': true,
'fetchPosition': false,
'fetchPositionHistory': false,
'fetchPositionMode': false,
'fetchPositions': false,
'fetchPositionsForSymbol': false,
'fetchPositionsHistory': false,
'fetchPositionsRisk': false,
'fetchPremiumIndexOHLCV': false,
'fetchStatus': true,
'fetchTicker': true,
'fetchTickers': true,
'fetchTime': true,
'fetchTrades': true,
'fetchTradingFee': true,
'fetchTradingFees': true,
'fetchTradingLimits': false,
'fetchTransactionFee': false,
'fetchTransactionFees': false,
'fetchTransactions': false,
'fetchTransfers': false,
'fetchWithdrawal': undefined,
'fetchWithdrawals': true,
'fetchWithdrawalWhitelist': false,
'reduceMargin': false,
'repayCrossMargin': false,
'repayIsolatedMargin': false,
'setLeverage': false,
'setMargin': false,
'setMarginMode': false,
'setPositionMode': false,
'signIn': false,
'transfer': false,
'withdraw': true,
'ws': false,
},
'timeframes': {
'1m': '1m',
'3m': '3m',
'5m': '5m',
'15m': '15m',
'30m': '30m',
'1h': '1h',
'2h': '2h',
'4h': '4h',
'6h': '6h',
'8h': '8h',
'12h': '12h',
'1d': '1d',
'3d': '3d',
'1w': '1w',
'1M': '1M',
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/225719995-48ab2026-4ddb-496c-9da7-0d7566617c9b.jpg',
'api': {
'public': 'https://api.pro.coins.ph',
'private': 'https://api.pro.coins.ph',
},
'www': 'https://coins.ph/',
'doc': [
'https://coins-docs.github.io/rest-api',
],
'fees': 'https://support.coins.ph/hc/en-us/sections/4407198694681-Limits-Fees',
},
'api': {
'public': {
'get': {
'openapi/v1/ping': 1,
'openapi/v1/time': 1,
// cost 1 if 'symbol' param defined (one market symbol) or if 'symbols' param is a list of 1-20 market symbols
// cost 20 if 'symbols' param is a list of 21-100 market symbols
// cost 40 if 'symbols' param is a list of 101 or more market symbols or if both 'symbol' and 'symbols' params are omited
'openapi/quote/v1/ticker/24hr': { 'cost': 1, 'noSymbolAndNoSymbols': 40, 'byNumberOfSymbols': [[101, 40], [21, 20], [0, 1]] },
// cost 1 if 'symbol' param defined (one market symbol)
// cost 2 if 'symbols' param is a list of 1 or more market symbols or if both 'symbol' and 'symbols' params are omited
'openapi/quote/v1/ticker/price': { 'cost': 1, 'noSymbol': 2 },
// cost 1 if 'symbol' param defined (one market symbol)
// cost 2 if 'symbols' param is a list of 1 or more market symbols or if both 'symbol' and 'symbols' params are omited
'openapi/quote/v1/ticker/bookTicker': { 'cost': 1, 'noSymbol': 2 },
'openapi/v1/exchangeInfo': 10,
// cost 1 if limit <= 100; 5 if limit > 100.
'openapi/quote/v1/depth': { 'cost': 1, 'byLimit': [[101, 5], [0, 1]] },
'openapi/quote/v1/klines': 1,
'openapi/quote/v1/trades': 1,
'openapi/v1/pairs': 1,
'openapi/quote/v1/avgPrice': 1,
},
},
'private': {
'get': {
'openapi/wallet/v1/config/getall': 10,
'openapi/wallet/v1/deposit/address': 10,
'openapi/wallet/v1/deposit/history': 1,
'openapi/wallet/v1/withdraw/history': 1,
'openapi/v1/account': 10,
// cost 3 for a single symbol; 40 when the symbol parameter is omitted
'openapi/v1/openOrders': { 'cost': 3, 'noSymbol': 40 },
'openapi/v1/asset/tradeFee': 1,
'openapi/v1/order': 2,
// cost 10 with symbol, 40 when the symbol parameter is omitted;
'openapi/v1/historyOrders': { 'cost': 10, 'noSymbol': 40 },
'openapi/v1/myTrades': 10,
'openapi/v1/capital/deposit/history': 1,
'openapi/v1/capital/withdraw/history': 1,
'openapi/v3/payment-request/get-payment-request': 1,
'merchant-api/v1/get-invoices': 1,
'openapi/account/v3/crypto-accounts': 1,
'openapi/transfer/v3/transfers/{id}': 1,
},
'post': {
'openapi/wallet/v1/withdraw/apply': 600,
'openapi/v1/order/test': 1,
'openapi/v1/order': 1,
'openapi/v1/capital/withdraw/apply': 1,
'openapi/v1/capital/deposit/apply': 1,
'openapi/v3/payment-request/payment-requests': 1,
'openapi/v3/payment-request/delete-payment-request': 1,
'openapi/v3/payment-request/payment-request-reminder': 1,
'openapi/v1/userDataStream': 1,
'merchant-api/v1/invoices': 1,
'merchant-api/v1/invoices-cancel': 1,
'openapi/convert/v1/get-supported-trading-pairs': 1,
'openapi/convert/v1/get-quote': 1,
'openapi/convert/v1/accpet-quote': 1,
'openapi/fiat/v1/support-channel': 1,
'openapi/fiat/v1/cash-out': 1,
'openapi/fiat/v1/history': 1,
'openapi/migration/v4/sellorder': 1,
'openapi/migration/v4/validate-field': 1,
'openapi/transfer/v3/transfers': 1,
},
'delete': {
'openapi/v1/order': 1,
'openapi/v1/openOrders': 1,
'openapi/v1/userDataStream': 1,
},
},
},
'fees': {
// todo: zero fees for USDT, ETH and BTC markets till 2023-04-02
'trading': {
'feeSide': 'get',
'tierBased': true,
'percentage': true,
'maker': this.parseNumber('0.0025'),
'taker': this.parseNumber('0.003'),
'tiers': {
'taker': [
[this.parseNumber('0'), this.parseNumber('0.003')],
[this.parseNumber('500000'), this.parseNumber('0.0027')],
[this.parseNumber('1000000'), this.parseNumber('0.0024')],
[this.parseNumber('2500000'), this.parseNumber('0.002')],
[this.parseNumber('5000000'), this.parseNumber('0.0018')],
[this.parseNumber('10000000'), this.parseNumber('0.0015')],
[this.parseNumber('100000000'), this.parseNumber('0.0012')],
[this.parseNumber('500000000'), this.parseNumber('0.0009')],
[this.parseNumber('1000000000'), this.parseNumber('0.0007')],
[this.parseNumber('2500000000'), this.parseNumber('0.0005')],
],
'maker': [
[this.parseNumber('0'), this.parseNumber('0.0025')],
[this.parseNumber('500000'), this.parseNumber('0.0022')],
[this.parseNumber('1000000'), this.parseNumber('0.0018')],
[this.parseNumber('2500000'), this.parseNumber('0.0015')],
[this.parseNumber('5000000'), this.parseNumber('0.0012')],
[this.parseNumber('10000000'), this.parseNumber('0.001')],
[this.parseNumber('100000000'), this.parseNumber('0.0008')],
[this.parseNumber('500000000'), this.parseNumber('0.0007')],
[this.parseNumber('1000000000'), this.parseNumber('0.0006')],
[this.parseNumber('2500000000'), this.parseNumber('0.0005')],
],
},
},
},
'precisionMode': number.TICK_SIZE,
// exchange-specific options
'options': {
'createMarketBuyOrderRequiresPrice': true,
'withdraw': {
'warning': false,
},
'deposit': {
'warning': false,
},
'createOrder': {
'timeInForce': 'GTC',
'newOrderRespType': {
'market': 'FULL',
'limit': 'FULL', // we change it from 'ACK' by default to 'FULL'
},
},
'fetchTicker': {
'method': 'publicGetOpenapiQuoteV1Ticker24hr', // publicGetOpenapiQuoteV1TickerPrice, publicGetOpenapiQuoteV1TickerBookTicker
},
'fetchTickers': {
'method': 'publicGetOpenapiQuoteV1Ticker24hr', // publicGetOpenapiQuoteV1TickerPrice, publicGetOpenapiQuoteV1TickerBookTicker
},
'networks': {
// all networks: 'ETH', 'TRX', 'BSC', 'ARBITRUM', 'RON', 'BTC', 'XRP'
// you can call api privateGetOpenapiWalletV1ConfigGetall to check which network is supported for the currency
'TRC20': 'TRX',
'ERC20': 'ETH',
'BEP20': 'BSC',
'ARB': 'ARBITRUM',
},
},
'features': {
'spot': {
'sandbox': false,
'createOrder': {
'marginMode': false,
'triggerPrice': true,
'triggerPriceType': undefined,
'triggerDirection': false,
'stopLossPrice': false,
'takeProfitPrice': false,
'attachedStopLossTakeProfit': undefined,
'timeInForce': {
'IOC': true,
'FOK': true,
'PO': false,
'GTD': false,
},
'hedged': false,
'trailing': false,
'leverage': false,
'marketBuyByCost': true,
'marketBuyRequiresPrice': false,
'selfTradePrevention': true,
'iceberg': false,
},
'createOrders': undefined,
'fetchMyTrades': {
'marginMode': false,
'limit': 1000,
'daysBack': 100000,
'untilDays': 100000,
'symbolRequired': true,
},
'fetchOrder': {
'marginMode': false,
'trigger': false,
'trailing': false,
'symbolRequired': false,
},
'fetchOpenOrders': {
'marginMode': false,
'limit': undefined,
'trigger': false,
'trailing': false,
'symbolRequired': false,
},
'fetchOrders': undefined,
'fetchClosedOrders': {
'marginMode': false,
'limit': 1000,
'daysBack': 100000,
'daysBackCanceled': 1,
'untilDays': 100000,
'trigger': false,
'trailing': false,
'symbolRequired': true,
},
'fetchOHLCV': {
'limit': 1000,
},
},
'swap': {
'linear': undefined,
'inverse': undefined,
},
'future': {
'linear': undefined,
'inverse': undefined,
},
},
// https://coins-docs.github.io/errors/
'exceptions': {
'exact': {
'-1000': errors.BadRequest,
'-1001': errors.BadRequest,
'-1002': errors.AuthenticationError,
'-1003': errors.RateLimitExceeded,
'-1004': errors.InvalidOrder,
'-1006': errors.BadResponse,
'-1007': errors.BadResponse,
'-1014': errors.InvalidOrder,
'-1015': errors.RateLimitExceeded,
'-1016': errors.NotSupported,
'-1020': errors.NotSupported,
'-1021': errors.BadRequest,
'-1022': errors.BadRequest,
'-1023': errors.AuthenticationError,
'-1024': errors.BadRequest,
'-1025': errors.BadRequest,
'-1030': errors.ExchangeError,
'-1100': errors.BadRequest,
'-1101': errors.BadRequest,
'-1102': errors.BadRequest,
'-1103': errors.BadRequest,
'-1104': errors.BadRequest,
'-1105': errors.BadRequest,
'-1106': errors.BadRequest,
'-1111': errors.BadRequest,
'-1112': errors.BadResponse,
'-1114': errors.BadRequest,
'-1115': errors.InvalidOrder,
'-1116': errors.InvalidOrder,
'-1117': errors.InvalidOrder,
'-1118': errors.InvalidOrder,
'-1119': errors.InvalidOrder,
'-1120': errors.BadRequest,
'-1121': errors.BadSymbol,
'-1122': errors.InvalidOrder,
'-1125': errors.BadRequest,
'-1127': errors.BadRequest,
'-1128': errors.BadRequest,
'-1130': errors.BadRequest,
'-1131': errors.InsufficientFunds,
'-1132': errors.InvalidOrder,
'-1133': errors.InvalidOrder,
'-1134': errors.InvalidOrder,
'-1135': errors.InvalidOrder,
'-1136': errors.InvalidOrder,
'-1137': errors.InvalidOrder,
'-1138': errors.InvalidOrder,
'-1139': errors.InvalidOrder,
'-1140': errors.InvalidOrder,
'-1141': errors.DuplicateOrderId,
'-1142': errors.InvalidOrder,
'-1143': errors.OrderNotFound,
'-1144': errors.InvalidOrder,
'-1145': errors.InvalidOrder,
'-1146': errors.InvalidOrder,
'-1147': errors.InvalidOrder,
'-1148': errors.InvalidOrder,
'-1149': errors.InvalidOrder,
'-1150': errors.InvalidOrder,
'-1151': errors.BadSymbol,
'-1152': errors.NotSupported,
'-1153': errors.AuthenticationError,
'-1154': errors.BadRequest,
'-1155': errors.BadRequest,
'-1156': errors.InvalidOrder,
'-1157': errors.BadSymbol,
'-1158': errors.InvalidOrder,
'-1159': errors.InvalidOrder,
'-1160': errors.BadRequest,
'-1161': errors.BadRequest,
'-2010': errors.InvalidOrder,
'-2013': errors.OrderNotFound,
'-2011': errors.BadRequest,
'-2014': errors.BadRequest,
'-2015': errors.AuthenticationError,
'-2016': errors.BadResponse,
'-3126': errors.InvalidOrder,
'-3127': errors.InvalidOrder,
'-4001': errors.BadRequest,
'-100011': errors.BadSymbol,
'-100012': errors.BadSymbol,
'-30008': errors.InsufficientFunds,
'-30036': errors.InsufficientFunds,
'403': errors.ExchangeNotAvailable,
},
'broad': {
'Unknown order sent': errors.OrderNotFound,
'Duplicate order sent': errors.DuplicateOrderId,
'Market is closed': errors.BadSymbol,
'Account has insufficient balance for requested action': errors.InsufficientFunds,
'Market orders are not supported for this symbol': errors.BadSymbol,
'Iceberg orders are not supported for this symbol': errors.BadSymbol,
'Stop loss orders are not supported for this symbol': errors.BadSymbol,
'Stop loss limit orders are not supported for this symbol': errors.BadSymbol,
'Take profit orders are not supported for this symbol': errors.BadSymbol,
'Take profit limit orders are not supported for this symbol': errors.BadSymbol,
'Price* QTY is zero or less': errors.BadRequest,
'IcebergQty exceeds QTY': errors.BadRequest,
'This action disabled is on this account': errors.PermissionDenied,
'Unsupported order combination': errors.InvalidOrder,
'Order would trigger immediately': errors.InvalidOrder,
'Cancel order is invalid. Check origClOrdId and orderId': errors.InvalidOrder,
'Order would immediately match and take': errors.OrderImmediatelyFillable,
'PRICE_FILTER': errors.InvalidOrder,
'LOT_SIZE': errors.InvalidOrder,
'MIN_NOTIONAL': errors.InvalidOrder,
'MAX_NUM_ORDERS': errors.InvalidOrder,
'MAX_ALGO_ORDERS': errors.InvalidOrder,
'BROKER_MAX_NUM_ORDERS': errors.InvalidOrder,
'BROKER_MAX_ALGO_ORDERS': errors.InvalidOrder,
'ICEBERG_PARTS': errors.BadRequest, // Iceberg order would break into too many parts; icebergQty is too small.
},
},
});
}
calculateRateLimiterCost(api, method, path, params, config = {}) {
if (('noSymbol' in config) && !('symbol' in params)) {
return config['noSymbol'];
}
else if (('noSymbolAndNoSymbols' in config) && !('symbol' in params) && !('symbols' in params)) {
return config['noSymbolAndNoSymbols'];
}
else if (('byNumberOfSymbols' in config) && ('symbols' in params)) {
const symbols = params['symbols'];
const symbolsAmount = symbols.length;
const byNumberOfSymbols = config['byNumberOfSymbols'];
for (let i = 0; i < byNumberOfSymbols.length; i++) {
const entry = byNumberOfSymbols[i];
if (symbolsAmount >= entry[0]) {
return entry[1];
}
}
}
else if (('byLimit' in config) && ('limit' in params)) {
const limit = params['limit'];
const byLimit = config['byLimit'];
for (let i = 0; i < byLimit.length; i++) {
const entry = byLimit[i];
if (limit >= entry[0]) {
return entry[1];
}
}
}
return this.safeValue(config, 'cost', 1);
}
/**
* @method
* @name coinsph#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://coins-docs.github.io/rest-api/#test-connectivity
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure]{@link https://docs.ccxt.com/#/?id=exchange-status-structure}
*/
async fetchStatus(params = {}) {
const response = await this.publicGetOpenapiV1Ping(params);
return {
'status': 'ok',
'updated': undefined,
'eta': undefined,
'url': undefined,
'info': response,
};
}
/**
* @method
* @name coinsph#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://coins-docs.github.io/rest-api/#check-server-time
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the exchange server
*/
async fetchTime(params = {}) {
const response = await this.publicGetOpenapiV1Time(params);
//
// {"serverTime":1677705408268}
//
return this.safeInteger(response, 'serverTime');
}
/**
* @method
* @name coinsph#fetchMarkets
* @description retrieves data on all markets for coinsph
* @see https://coins-docs.github.io/rest-api/#exchange-information
* @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.publicGetOpenapiV1ExchangeInfo(params);
//
// {
// "timezone": "UTC",
// "serverTime": "1677449496897",
// "exchangeFilters": [],
// "symbols": [
// {
// "symbol": "XRPPHP",
// "status": "TRADING",
// "baseAsset": "XRP",
// "baseAssetPrecision": "2",
// "quoteAsset": "PHP",
// "quoteAssetPrecision": "4",
// "orderTypes": [
// "LIMIT",
// "MARKET",
// "LIMIT_MAKER",
// "STOP_LOSS_LIMIT",
// "STOP_LOSS",
// "TAKE_PROFIT_LIMIT",
// "TAKE_PROFIT"
// ],
// "filters": [
// {
// "minPrice": "0.01",
// "maxPrice": "99999999.00000000",
// "tickSize": "0.01",
// "filterType": "PRICE_FILTER"
// },
// {
// "minQty": "0.01",
// "maxQty": "99999999999.00000000",
// "stepSize": "0.01",
// "filterType": "LOT_SIZE"
// },
// { minNotional: "50", filterType: "NOTIONAL" },
// { minNotional: "50", filterType: "MIN_NOTIONAL" },
// {
// "priceUp": "99999999",
// "priceDown": "0.01",
// "filterType": "STATIC_PRICE_RANGE"
// },
// {
// "multiplierUp": "1.1",
// "multiplierDown": "0.9",
// "filterType": "PERCENT_PRICE_INDEX"
// },
// {
// "multiplierUp": "1.1",
// "multiplierDown": "0.9",
// "filterType": "PERCENT_PRICE_ORDER_SIZE"
// },
// { maxNumOrders: "200", filterType: "MAX_NUM_ORDERS" },
// { maxNumAlgoOrders: "5", filterType: "MAX_NUM_ALGO_ORDERS" }
// ]
// },
// ]
// }
//
const markets = this.safeList(response, 'symbols', []);
const result = [];
for (let i = 0; i < markets.length; i++) {
const market = markets[i];
const id = this.safeString(market, 'symbol');
const baseId = this.safeString(market, 'baseAsset');
const quoteId = this.safeString(market, 'quoteAsset');
const base = this.safeCurrencyCode(baseId);
const quote = this.safeCurrencyCode(quoteId);
const limits = this.indexBy(this.safeList(market, 'filters', []), 'filterType');
const amountLimits = this.safeValue(limits, 'LOT_SIZE', {});
const priceLimits = this.safeValue(limits, 'PRICE_FILTER', {});
const costLimits = this.safeValue(limits, 'NOTIONAL', {});
result.push({
'id': id,
'symbol': base + '/' + quote,
'base': base,
'quote': quote,
'settle': undefined,
'baseId': baseId,
'quoteId': quoteId,
'settleId': undefined,
'type': 'spot',
'spot': true,
'margin': false,
'swap': false,
'future': false,
'option': false,
'active': this.safeStringLower(market, 'status') === 'trading',
'contract': false,
'linear': undefined,
'inverse': undefined,
'taker': undefined,
'maker': undefined,
'contractSize': undefined,
'expiry': undefined,
'expiryDatetime': undefined,
'strike': undefined,
'optionType': undefined,
'precision': {
'amount': this.parseNumber(this.safeString(amountLimits, 'stepSize')),
'price': this.parseNumber(this.safeString(priceLimits, 'tickSize')),
},
'limits': {
'leverage': {
'min': undefined,
'max': undefined,
},
'amount': {
'min': this.parseNumber(this.safeString(amountLimits, 'minQty')),
'max': this.parseNumber(this.safeString(amountLimits, 'maxQty')),
},
'price': {
'min': this.parseNumber(this.safeString(priceLimits, 'minPrice')),
'max': this.parseNumber(this.safeString(priceLimits, 'maxPrice')),
},
'cost': {
'min': this.parseNumber(this.safeString(costLimits, 'minNotional')),
'max': undefined,
},
},
'created': undefined,
'info': market,
});
}
this.setMarkets(result);
return result;
}
/**
* @method
* @name coinsph#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://coins-docs.github.io/rest-api/#24hr-ticker-price-change-statistics
* @see https://coins-docs.github.io/rest-api/#symbol-price-ticker
* @see https://coins-docs.github.io/rest-api/#symbol-order-book-ticker
* @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();
const request = {};
if (symbols !== undefined) {
const ids = [];
for (let i = 0; i < symbols.length; i++) {
const market = this.market(symbols[i]);
const id = market['id'];
ids.push(id);
}
request['symbols'] = ids;
}
const defaultMethod = 'publicGetOpenapiQuoteV1Ticker24hr';
const options = this.safeDict(this.options, 'fetchTickers', {});
const method = this.safeString(options, 'method', defaultMethod);
let tickers = undefined;
if (method === 'publicGetOpenapiQuoteV1TickerPrice') {
tickers = await this.publicGetOpenapiQuoteV1TickerPrice(this.extend(request, params));
}
else if (method === 'publicGetOpenapiQuoteV1TickerBookTicker') {
tickers = await this.publicGetOpenapiQuoteV1TickerBookTicker(this.extend(request, params));
}
else {
tickers = await this.publicGetOpenapiQuoteV1Ticker24hr(this.extend(request, params));
}
return this.parseTickers(tickers, symbols, params);
}
/**
* @method
* @name coinsph#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://coins-docs.github.io/rest-api/#24hr-ticker-price-change-statistics
* @see https://coins-docs.github.io/rest-api/#symbol-price-ticker
* @see https://coins-docs.github.io/rest-api/#symbol-order-book-ticker
* @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();
const market = this.market(symbol);
const request = {
'symbol': market['id'],
};
const defaultMethod = 'publicGetOpenapiQuoteV1Ticker24hr';
const options = this.safeDict(this.options, 'fetchTicker', {});
const method = this.safeString(options, 'method', defaultMethod);
let ticker = undefined;
if (method === 'publicGetOpenapiQuoteV1TickerPrice') {
ticker = await this.publicGetOpenapiQuoteV1TickerPrice(this.extend(request, params));
}
else if (method === 'publicGetOpenapiQuoteV1TickerBookTicker') {
ticker = await this.publicGetOpenapiQuoteV1TickerBookTicker(this.extend(request, params));
}
else {
ticker = await this.publicGetOpenapiQuoteV1Ticker24hr(this.extend(request, params));
}
return this.parseTicker(ticker, market);
}
parseTicker(ticker, market = undefined) {
//
// publicGetOpenapiQuoteV1Ticker24hr
// {
// "symbol": "ETHUSDT",
// "priceChange": "41.440000000000000000",
// "priceChangePercent": "0.0259",
// "weightedAvgPrice": "1631.169825783972125436",
// "prevClosePrice": "1601.520000000000000000",
// "lastPrice": "1642.96",
// "lastQty": "0.000001000000000000",
// "bidPrice": "1638.790000000000000000",
// "bidQty": "0.280075000000000000",
// "askPrice": "1647.340000000000000000",
// "askQty": "0.165183000000000000",
// "openPrice": "1601.52",
// "highPrice": "1648.28",
// "lowPrice": "1601.52",
// "volume": "0.000287",
// "quoteVolume": "0.46814574",
// "openTime": "1677417000000",
// "closeTime": "1677503415200",
// "firstId": "1364680572697591809",
// "lastId": "1365389809203560449",
// "count": "100"
// }
//
// publicGetOpenapiQuoteV1TickerPrice
// { "symbol": "ETHUSDT", "price": "1599.68" }
//
// publicGetOpenapiQuoteV1TickerBookTicker
// {
// "symbol": "ETHUSDT",
// "bidPrice": "1596.57",
// "bidQty": "0.246405",
// "askPrice": "1605.12",
// "askQty": "0.242681"
// }
//
const marketId = this.safeString(ticker, 'symbol');
market = this.safeMarket(marketId, market);
const timestamp = this.safeInteger(ticker, 'closeTime');
const bid = this.safeString(ticker, 'bidPrice');
const ask = this.safeString(ticker, 'askPrice');
const bidVolume = this.safeString(ticker, 'bidQty');
const askVolume = this.safeString(ticker, 'askQty');
const baseVolume = this.safeString(ticker, 'volume');
const quoteVolume = this.safeString(ticker, 'quoteVolume');
const open = this.safeString(ticker, 'openPrice');
const high = this.safeString(ticker, 'highPrice');
const low = this.safeString(ticker, 'lowPrice');
const prevClose = this.safeString(ticker, 'prevClosePrice');
const vwap = this.safeString(ticker, 'weightedAvgPrice');
const changeValue = this.safeString(ticker, 'priceChange');
let changePcnt = this.safeString(ticker, 'priceChangePercent');
changePcnt = Precise["default"].stringMul(changePcnt, '100');
return this.safeTicker({
'symbol': market['symbol'],
'timestamp': timestamp,
'datetime': this.iso8601(timestamp),
'open': open,
'high': high,
'low': low,
'close': this.safeString2(ticker, 'lastPrice', 'price'),
'bid': bid,
'bidVolume': bidVolume,
'ask': ask,
'askVolume': askVolume,
'vwap': vwap,
'previousClose': prevClose,
'change': changeValue,
'percentage': changePcnt,
'average': undefined,
'baseVolume': baseVolume,
'quoteVolume': quoteVolume,
'info': ticker,
}, market);
}
/**
* @method
* @name coinsph#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://coins-docs.github.io/rest-api/#order-book
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return (default 100, max 200)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
*/
async fetchOrderBook(symbol, limit = undefined, params = {}) {
await this.loadMarkets();
const market = this.market(symbol);
const request = {
'symbol': market['id'],
};
if (limit !== undefined) {
request['limit'] = limit;
}
const response = await this.publicGetOpenapiQuoteV1Depth(this.extend(request, params));
//
// {
// "lastUpdateId": "1667022157000699400",
// "bids": [
// [ '1651.810000000000000000', '0.214556000000000000' ],
// [ '1651.730000000000000000', '0.257343000000000000' ],
// ],
// "asks": [
// [ '1660.510000000000000000', '0.299092000000000000' ],
// [ '1660.600000000000000000', '0.253667000000000000' ],
// ]
// }
//
const orderbook = this.parseOrderBook(response, symbol);
orderbook['nonce'] = this.safeInteger(response, 'lastUpdateId');
return orderbook;
}
/**
* @method
* @name coinsph#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://coins-docs.github.io/rest-api/#klinecandlestick-data
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch (default 500, max 1000)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
await this.loadMarkets();
const market = this.market(symbol);
const interval = this.safeString(this.timeframes, timeframe);
const until = this.safeInteger(params, 'until');
const request = {
'symbol': market['id'],
'interval': interval,
};
if (limit === undefined) {
limit = 1000;
}
if (since !== undefined) {
request['startTime'] = since;
// since work properly only when it is "younger" than last "limit" candle
if (until !== undefined) {
request['endTime'] = until;
}
else {
const duration = this.parseTimeframe(timeframe) * 1000;
const endTimeByLimit = this.sum(since, duration * (limit - 1));
const now = this.milliseconds();
request['endTime'] = Math.min(endTimeByLimit, now);
}
}
else if (until !== undefined) {
request['endTime'] = until;
// since work properly only when it is "younger" than last "limit" candle
const duration = this.parseTimeframe(timeframe) * 1000;
request['startTime'] = until - (duration * (limit - 1));
}
request['limit'] = limit;
params = this.omit(params, 'until');
const response = await this.publicGetOpenapiQuoteV1Klines(this.extend(request, params));
//
// [
// [
// 1499040000000, // Open time
// "0.01634790", // Open
// "0.80000000", // High
// "0.01575800", // Low
// "0.01577100", // Close
// "148976.11427815", // Volume
// 1499644799999, // Close time
// "2434.19055334", // Quote asset volume
// 308, // Number of trades
// "1756.87402397", // Taker buy base asset volume
// "28.46694368" // Taker buy quote asset volume
// ]
// ]
//
return this.parseOHLCVs(response, market, timeframe, since, limit);
}
parseOHLCV(ohlcv, market = undefined) {
return [
this.safeInteger(ohlcv, 0),
this.safeNumber(ohlcv, 1),
this.safeNumber(ohlcv, 2),
this.safeNumber(ohlcv, 3),
this.safeNumber(ohlcv, 4),
this.safeNumber(ohlcv, 5),
];
}
/**
* @method
* @name coinsph#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://coins-docs.github.io/rest-api/#recent-trades-list
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch (default 500, max 1000)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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();
const market = this.market(symbol);
const request = {
'symbol': market['id'],
};
if (since !== undefined) {
// since work properly only when it is "younger" than last 'limit' trade
request['limit'] = 1000;
}
else {
if (limit !== undefined) {
request['limit'] = limit;
}
}
const response = await this.publicGetOpenapiQuoteV1Trades(this.extend(request, params));
//
// [
// {
// "price": "89685.8",
// "id": "1365561108437680129",
// "qty": "0.000004",
// "quoteQty": "0.000004000000000000",
// "time": "1677523569575",
// "isBuyerMaker": false,
// "isBestMatch": true
// },
// ]
//
return this.parseTrades(response, market, since, limit);
}
/**
* @method
* @name coinsph#fetchMyTrades
* @description fetch all trades made by the user
* @see https://coins-docs.github.io/rest-api/#account-trade-list-user_data
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve (default 500, max 1000)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
*/
async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
if (symbol === undefined) {
throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
}
await this.loadMarkets();
const market = this.market(symbol);
const request = {
'symbol': market['id'],
};
if (since !== undefined) {
request['startTime'] = since;
// since work properly only when it is "younger" than last 'limit' trade
request['limit'] = 1000;
}
else if (limit !== undefined) {
request['limit'] = limit;
}
const response = await this.privateGetOpenapiV1MyTrades(this.extend(request, params));
return this.parseTrades(response, market, since, limit);
}
/**
* @method
* @name coinsph#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://coins-docs.github.io/rest-api/#account-trade-list-user_data
* @param {string} id order id
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
*/
async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
if (symbol === undefined) {
throw new errors.ArgumentsRequired(this.id + ' fetchOrderTrades() requires a symbol argument');
}
const request = {
'orderId': id,
};
return await this.fetchMyTrades(symbol, since, limit, this.extend(request, params));
}
parseTrade(trade, market = undefined) {
//
// fetchTrades
// {
// "price": "89685.8",
// "id": "1365561108437680129",
// "qty": "0.000004",
// "quoteQty": "0.000004000000000000", // warning: report to exchange - this is not quote quantity, this is base quantity
// "time": "1677523569575",
// "isBuyerMaker": false,
// "isBestMatch": true
// },
//
// fetchMyTrades
// {
// "symbol": "ETHUSDT",
// "id": 1375426310524125185,
// "orderId": 1375426310415879614,
// "price": "1580.91",
// "qty": "0.01",
// "quoteQty