UNPKG

ccxt

Version:

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges

1,213 lines (1,210 loc) • 99.9 kB
'use strict'; var bigone$1 = require('./abstract/bigone.js'); var errors = require('./base/errors.js'); var number = require('./base/functions/number.js'); var rsa = require('./base/functions/rsa.js'); var sha256 = require('./static_dependencies/noble-hashes/sha256.js'); var Precise = require('./base/Precise.js'); // ---------------------------------------------------------------------------- // --------------------------------------------------------------------------- /** * @class bigone * @augments Exchange */ class bigone extends bigone$1 { describe() { return this.deepExtend(super.describe(), { 'id': 'bigone', 'name': 'BigONE', 'countries': ['CN'], 'version': 'v3', 'rateLimit': 20, 'has': { 'CORS': undefined, 'spot': true, 'margin': false, 'swap': undefined, 'future': undefined, 'option': false, 'cancelAllOrders': true, 'cancelOrder': true, 'createMarketBuyOrderWithCost': true, 'createMarketOrderWithCost': false, 'createMarketSellOrderWithCost': false, 'createOrder': true, 'createPostOnlyOrder': true, 'createStopLimitOrder': true, 'createStopMarketOrder': true, 'createStopOrder': true, 'fetchBalance': true, 'fetchClosedOrders': true, 'fetchCurrencies': true, 'fetchDepositAddress': true, 'fetchDepositAddresses': false, 'fetchDepositAddressesByNetwork': false, 'fetchDeposits': true, 'fetchFundingHistory': false, 'fetchFundingRate': false, 'fetchFundingRateHistory': false, 'fetchFundingRates': false, 'fetchMarkets': true, 'fetchMyTrades': true, 'fetchOHLCV': true, 'fetchOpenOrders': true, 'fetchOrder': true, 'fetchOrderBook': true, 'fetchOrders': true, 'fetchTicker': true, 'fetchTickers': true, 'fetchTime': true, 'fetchTrades': true, 'fetchTradingFee': false, 'fetchTradingFees': false, 'fetchTransactionFees': false, 'fetchWithdrawals': true, 'transfer': true, 'withdraw': true, }, 'timeframes': { '1m': 'min1', '5m': 'min5', '15m': 'min15', '30m': 'min30', '1h': 'hour1', '3h': 'hour3', '4h': 'hour4', '6h': 'hour6', '12h': 'hour12', '1d': 'day1', '1w': 'week1', '1M': 'month1', }, 'hostname': 'big.one', 'urls': { 'logo': 'https://github.com/user-attachments/assets/4e5cfd53-98cc-4b90-92cd-0d7b512653d1', 'api': { 'public': 'https://{hostname}/api/v3', 'private': 'https://{hostname}/api/v3/viewer', 'contractPublic': 'https://{hostname}/api/contract/v2', 'contractPrivate': 'https://{hostname}/api/contract/v2', 'webExchange': 'https://{hostname}/api/', }, 'www': 'https://big.one', 'doc': 'https://open.big.one/docs/api.html', 'fees': 'https://bigone.zendesk.com/hc/en-us/articles/115001933374-BigONE-Fee-Policy', 'referral': 'https://b1.run/users/new?code=D3LLBVFT', }, 'api': { 'public': { 'get': [ 'ping', 'asset_pairs', 'asset_pairs/{asset_pair_name}/depth', 'asset_pairs/{asset_pair_name}/trades', 'asset_pairs/{asset_pair_name}/ticker', 'asset_pairs/{asset_pair_name}/candles', 'asset_pairs/tickers', ], }, 'private': { 'get': [ 'accounts', 'fund/accounts', 'assets/{asset_symbol}/address', 'orders', 'orders/{id}', 'orders/multi', 'trades', 'withdrawals', 'deposits', ], 'post': [ 'orders', 'orders/{id}/cancel', 'orders/cancel', 'withdrawals', 'transfer', ], }, 'contractPublic': { 'get': [ 'symbols', 'instruments', 'depth@{symbol}/snapshot', 'instruments/difference', 'instruments/prices', ], }, 'contractPrivate': { 'get': [ 'accounts', 'orders/{id}', 'orders', 'orders/opening', 'orders/count', 'orders/opening/count', 'trades', 'trades/count', ], 'post': [ 'orders', 'orders/batch', ], 'put': [ 'positions/{symbol}/margin', 'positions/{symbol}/risk-limit', ], 'delete': [ 'orders/{id}', 'orders/batch', ], }, 'webExchange': { 'get': [ 'v3/assets', ], }, }, 'fees': { 'trading': { 'maker': this.parseNumber('0.001'), 'taker': this.parseNumber('0.001'), }, 'funding': { 'withdraw': {}, }, }, 'options': { 'createMarketBuyOrderRequiresPrice': true, 'accountsByType': { 'spot': 'SPOT', 'fund': 'FUND', 'funding': 'FUND', 'future': 'CONTRACT', 'swap': 'CONTRACT', }, 'transfer': { 'fillResponseFromRequest': true, }, 'exchangeMillisecondsCorrection': -100, 'fetchCurrencies': { 'webApiEnable': true, 'webApiRetries': 5, 'webApiMuteFailure': true, }, 'defaultNetwork': 'ERC20', 'defaultNetworks': { 'USDT': 'TRC20', }, 'networks': { 'ABBC': 'ABBC', 'ACA': 'Acala', 'AE': 'Aeternity', 'ALGO': 'Algorand', 'APT': 'Aptos', 'AR': 'Arweave', 'ASTR': 'Astar', 'AVAXC': 'Avax', 'AVAXX': 'AvaxChain', 'BEAM': 'Beam', 'BEP20': 'BinanceSmartChain', 'BITCI': 'BitciChain', 'BTC': 'Bitcoin', 'BCH': 'BitcoinCash', 'BSV': 'BitcoinSV', 'CELO': 'Celo', 'CKKB': 'CKB', 'ATOM': 'Cosmos', 'CRC20': 'CRO', 'DASH': 'Dash', 'DOGE': 'Dogecoin', 'XEC': 'ECash', 'EOS': 'EOS', 'ETH': 'Ethereum', 'ETC': 'EthereumClassic', 'ETHW': 'EthereumPow', 'FTM': 'Fantom', 'FIL': 'Filecoin', 'FSN': 'Fusion', 'GRIN': 'Grin', 'ONE': 'Harmony', 'HRC20': 'Hecochain', 'HBAR': 'Hedera', 'HNT': 'Helium', 'ZEN': 'Horizen', 'IOST': 'IOST', 'IRIS': 'IRIS', 'KLAY': 'Klaytn', 'KSM': 'Kusama', 'LTC': 'Litecoin', 'XMR': 'Monero', 'GLMR': 'Moonbeam', 'NEAR': 'Near', 'NEO': 'Neo', 'NEON3': 'NeoN3', 'OASIS': 'Oasis', 'OKC': 'Okexchain', 'ONT': 'Ontology', 'OPTIMISM': 'Optimism', 'DOT': 'Polkadot', 'MATIC': 'Polygon', 'QTUM': 'Qtum', 'REI': 'REI', 'XRP': 'Ripple', 'SGB': 'SGB', 'SDN': 'Shiden', 'SOL': 'Solana', 'XLM': 'Stellar', 'TERA': 'Tera', 'XTZ': 'Tezos', 'TRC20': 'Tron', 'VET': 'Vechain', 'VSYS': 'VSystems', 'WAX': 'WAX', 'ZEC': 'Zcash', // todo: uncomment after consensus // 'BITSHARES_OLD': 'Bitshares', // 'BITSHARES_NEW': 'NewBitshares', // 'MOBILECOIN': 'Mobilecoin', // 'LBRY': 'Lbry', // 'ZEEPIN': 'Zeepin', // 'WAYFCOIN': 'Wayfcoin', // 'UCACOIN': 'Ucacoin', // 'VANILLACASH': 'Vcash', // 'LAMDEN': 'Lamden', // 'GXSHARES': 'Gxshares', // 'ICP': 'Dfinity', // 'CLOVER': 'Clover', // 'CLASSZZ': 'Classzz', // 'CLASSZZ_V2': 'ClasszzV2', // 'CHAINX_V2': 'ChainxV2', // 'BITCOINDIAMON': 'BitcoinDiamond', // 'BITCOINGOLD': 'BitcoinGold', // 'BUTTRUSTSYSTEM': 'BitTrustSystem', // 'BYTOM_V2': 'BytomV2', // 'LIBONOMY': 'Libonomy', // 'TERRACLASSIC': 'Terra', // 'TERRA': 'Terra2', // 'SUPERBITCOIN': 'SuperBitcoin', // 'SIACLASSIC': 'Sia', // 'SIACOIN': 'SiaCore', // 'PARALLELFINANCE': 'Parallel', // 'PLCULTIMA': 'Plcu', // 'PLCULTIMA2': 'Plcu2', // undetermined: XinFin, YAS, Ycash }, }, 'features': { 'default': { 'sandbox': false, 'createOrder': { 'marginMode': false, 'triggerPrice': true, 'triggerPriceType': undefined, 'triggerDirection': true, 'stopLossPrice': false, 'takeProfitPrice': false, 'attachedStopLossTakeProfit': undefined, 'timeInForce': { 'IOC': true, 'FOK': false, 'PO': true, 'GTD': false, }, 'hedged': false, 'trailing': false, 'leverage': false, 'marketBuyRequiresPrice': true, 'marketBuyByCost': true, 'selfTradePrevention': false, 'iceberg': false, }, 'createOrders': undefined, 'fetchMyTrades': { 'marginMode': false, 'limit': 200, 'daysBack': undefined, 'untilDays': undefined, 'symbolRequired': true, }, 'fetchOrder': { 'marginMode': false, 'trigger': false, 'trailing': false, 'symbolRequired': false, }, 'fetchOpenOrders': { 'marginMode': false, 'limit': 200, 'trigger': false, 'trailing': false, 'symbolRequired': true, }, 'fetchOrders': { 'marginMode': false, 'limit': 200, 'daysBack': undefined, 'untilDays': undefined, 'trigger': false, 'trailing': false, 'symbolRequired': true, }, 'fetchClosedOrders': { 'marginMode': false, 'limit': 200, 'daysBack': undefined, 'daysBackCanceled': undefined, 'untilDays': undefined, 'trigger': false, 'trailing': false, 'symbolRequired': true, }, 'fetchOHLCV': { 'limit': 500, }, }, 'spot': { 'extends': 'default', }, 'forDerivatives': { 'extends': 'default', 'createOrder': { // todo: implement 'triggerPriceType': { 'mark': true, 'index': true, 'last': true, }, }, 'fetchOrders': { 'daysBack': 100000, 'untilDays': 100000, }, 'fetchClosedOrders': { 'daysBack': 100000, 'untilDays': 100000, }, }, 'swap': { 'linear': { 'extends': 'forDerivatives', }, 'inverse': { 'extends': 'forDerivatives', }, }, 'future': { 'linear': undefined, 'inverse': undefined, }, }, 'precisionMode': number.TICK_SIZE, 'exceptions': { 'exact': { '10001': errors.BadRequest, '10005': errors.ExchangeError, "Amount's scale must greater than AssetPair's base scale": errors.InvalidOrder, "Price mulit with amount should larger than AssetPair's min_quote_value": errors.InvalidOrder, '10007': errors.BadRequest, '10011': errors.ExchangeError, '10013': errors.BadSymbol, '10014': errors.InsufficientFunds, '10403': errors.PermissionDenied, '10429': errors.RateLimitExceeded, '40004': errors.AuthenticationError, '40103': errors.AuthenticationError, '40104': errors.AuthenticationError, '40301': errors.PermissionDenied, '40302': errors.ExchangeError, '40601': errors.ExchangeError, '40602': errors.ExchangeError, '40603': errors.InsufficientFunds, '40604': errors.InvalidOrder, '40605': errors.InvalidOrder, '40120': errors.InvalidOrder, '40121': errors.InvalidOrder, '60100': errors.BadSymbol, // {"code":60100,"message":"Asset pair is suspended"} }, 'broad': {}, }, 'commonCurrencies': { 'CRE': 'Cybereits', 'FXT': 'FXTTOKEN', 'FREE': 'FreeRossDAO', 'MBN': 'Mobilian Coin', 'ONE': 'BigONE Token', }, }); } /** * @method * @name bigone#fetchCurrencies * @description fetches all available currencies on an exchange * @param {dict} [params] extra parameters specific to the exchange API endpoint * @returns {dict} an associative dictionary of currencies */ async fetchCurrencies(params = {}) { // we use undocumented link (possible, less informative alternative is : https://big.one/api/uc/v3/assets/accounts) const data = await this.fetchWebEndpoint('fetchCurrencies', 'webExchangeGetV3Assets', true); if (data === undefined) { return undefined; } // // { // "code": "0", // "message": "", // "data": [ // { // "uuid": "17082d1c-0195-4fb6-8779-2cdbcb9eeb3c", // "symbol": "USDT", // "name": "TetherUS", // "scale": 12, // "is_fiat": false, // "is_transfer_enabled": true, // "transfer_scale": 12, // "binding_gateways": [ // { // "guid": "07efc37f-d1ec-4bc9-8339-a745256ea2ba", // "is_deposit_enabled": true, // "gateway_name": "Ethereum", // "min_withdrawal_amount": "0.000001", // "withdrawal_fee": "5.71", // "is_withdrawal_enabled": true, // "min_deposit_amount": "0.000001", // "is_memo_required": false, // "withdrawal_scale": 6, // "scale": 12 // }, // { // "guid": "4e387a9a-a480-40a3-b4ae-ed1773c2db5a", // "is_deposit_enabled": true, // "gateway_name": "BinanceSmartChain", // "min_withdrawal_amount": "10", // "withdrawal_fee": "5", // "is_withdrawal_enabled": false, // "min_deposit_amount": "1", // "is_memo_required": false, // "withdrawal_scale": 8, // "scale": 12 // } // ] // }, // ... // ], // } // const currenciesData = this.safeList(data, 'data', []); const result = {}; for (let i = 0; i < currenciesData.length; i++) { const currency = currenciesData[i]; const id = this.safeString(currency, 'symbol'); const code = this.safeCurrencyCode(id); const name = this.safeString(currency, 'name'); const type = this.safeBool(currency, 'is_fiat') ? 'fiat' : 'crypto'; const networks = {}; const chains = this.safeList(currency, 'binding_gateways', []); let currencyMaxPrecision = this.parsePrecision(this.safeString2(currency, 'withdrawal_scale', 'scale')); let currencyDepositEnabled = undefined; let currencyWithdrawEnabled = undefined; for (let j = 0; j < chains.length; j++) { const chain = chains[j]; const networkId = this.safeString(chain, 'gateway_name'); const networkCode = this.networkIdToCode(networkId); const deposit = this.safeBool(chain, 'is_deposit_enabled'); const withdraw = this.safeBool(chain, 'is_withdrawal_enabled'); const isActive = (deposit && withdraw); const minDepositAmount = this.safeString(chain, 'min_deposit_amount'); const minWithdrawalAmount = this.safeString(chain, 'min_withdrawal_amount'); const withdrawalFee = this.safeString(chain, 'withdrawal_fee'); const precision = this.parsePrecision(this.safeString2(chain, 'withdrawal_scale', 'scale')); networks[networkCode] = { 'id': networkId, 'network': networkCode, 'margin': undefined, 'deposit': deposit, 'withdraw': withdraw, 'active': isActive, 'fee': this.parseNumber(withdrawalFee), 'precision': this.parseNumber(precision), 'limits': { 'deposit': { 'min': minDepositAmount, 'max': undefined, }, 'withdraw': { 'min': minWithdrawalAmount, 'max': undefined, }, }, 'info': chain, }; // fill global values currencyDepositEnabled = (currencyDepositEnabled === undefined) || deposit ? deposit : currencyDepositEnabled; currencyWithdrawEnabled = (currencyWithdrawEnabled === undefined) || withdraw ? withdraw : currencyWithdrawEnabled; currencyMaxPrecision = (currencyMaxPrecision === undefined) || Precise["default"].stringGt(currencyMaxPrecision, precision) ? precision : currencyMaxPrecision; } result[code] = { 'id': id, 'code': code, 'info': currency, 'name': name, 'type': type, 'active': undefined, 'deposit': currencyDepositEnabled, 'withdraw': currencyWithdrawEnabled, 'fee': undefined, 'precision': this.parseNumber(currencyMaxPrecision), 'limits': { 'amount': { 'min': undefined, 'max': undefined, }, 'withdraw': { 'min': undefined, 'max': undefined, }, }, 'networks': networks, }; } return result; } /** * @method * @name bigone#fetchMarkets * @description retrieves data on all markets for bigone * @see https://open.big.one/docs/spot_asset_pair.html * @param {object} [params] extra parameters specific to the exchange API endpoint * @returns {object[]} an array of objects representing market data */ async fetchMarkets(params = {}) { const promises = [this.publicGetAssetPairs(params), this.contractPublicGetSymbols(params)]; const promisesResult = await Promise.all(promises); const response = promisesResult[0]; const contractResponse = promisesResult[1]; // // { // "code":0, // "data":[ // { // "id":"01e48809-b42f-4a38-96b1-c4c547365db1", // "name":"PCX-BTC", // "quote_scale":7, // "quote_asset":{ // "id":"0df9c3c3-255a-46d7-ab82-dedae169fba9", // "symbol":"BTC", // "name":"Bitcoin", // }, // "base_asset":{ // "id":"405484f7-4b03-4378-a9c1-2bd718ecab51", // "symbol":"PCX", // "name":"ChainX", // }, // "base_scale":3, // "min_quote_value":"0.0001", // "max_quote_value":"35" // }, // ] // } // // // [ // { // "baseCurrency": "BTC", // "multiplier": 1, // "enable": true, // "priceStep": 0.5, // "maxRiskLimit": 1000, // "pricePrecision": 1, // "maintenanceMargin": 0.00500, // "symbol": "BTCUSD", // "valuePrecision": 4, // "minRiskLimit": 100, // "riskLimit": 100, // "isInverse": true, // "riskStep": 1, // "settleCurrency": "BTC", // "baseName": "Bitcoin", // "feePrecision": 8, // "priceMin": 0.5, // "priceMax": 1E+6, // "initialMargin": 0.01000, // "quoteCurrency": "USD" // }, // ... // ] // const markets = this.safeList(response, 'data', []); const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; const baseAsset = this.safeDict(market, 'base_asset', {}); const quoteAsset = this.safeDict(market, 'quote_asset', {}); const baseId = this.safeString(baseAsset, 'symbol'); const quoteId = this.safeString(quoteAsset, 'symbol'); const base = this.safeCurrencyCode(baseId); const quote = this.safeCurrencyCode(quoteId); result.push(this.safeMarketStructure({ 'id': this.safeString(market, 'name'), 'uuid': this.safeString(market, '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': true, 'contract': false, 'linear': undefined, 'inverse': undefined, 'contractSize': undefined, 'expiry': undefined, 'expiryDatetime': undefined, 'strike': undefined, 'optionType': undefined, 'precision': { 'amount': this.parseNumber(this.parsePrecision(this.safeString(market, 'base_scale'))), 'price': this.parseNumber(this.parsePrecision(this.safeString(market, 'quote_scale'))), }, 'limits': { 'leverage': { 'min': undefined, 'max': undefined, }, 'amount': { 'min': undefined, 'max': undefined, }, 'price': { 'min': undefined, 'max': undefined, }, 'cost': { 'min': this.safeNumber(market, 'min_quote_value'), 'max': this.safeNumber(market, 'max_quote_value'), }, }, 'created': undefined, 'info': market, })); } for (let i = 0; i < contractResponse.length; i++) { const market = contractResponse[i]; const baseId = this.safeString(market, 'baseCurrency'); const quoteId = this.safeString(market, 'quoteCurrency'); const settleId = this.safeString(market, 'settleCurrency'); const marketId = this.safeString(market, 'symbol'); const base = this.safeCurrencyCode(baseId); const quote = this.safeCurrencyCode(quoteId); const settle = this.safeCurrencyCode(settleId); const inverse = this.safeBool(market, 'isInverse'); result.push(this.safeMarketStructure({ 'id': marketId, 'symbol': base + '/' + quote + ':' + settle, 'base': base, 'quote': quote, 'settle': settle, 'baseId': baseId, 'quoteId': quoteId, 'settleId': settleId, 'type': 'swap', 'spot': false, 'margin': false, 'swap': true, 'future': false, 'option': false, 'active': this.safeBool(market, 'enable'), 'contract': true, 'linear': !inverse, 'inverse': inverse, 'contractSize': this.safeNumber(market, 'multiplier'), 'expiry': undefined, 'expiryDatetime': undefined, 'strike': undefined, 'optionType': undefined, 'precision': { 'amount': this.parseNumber(this.parsePrecision(this.safeString(market, 'valuePrecision'))), 'price': this.parseNumber(this.parsePrecision(this.safeString(market, 'pricePrecision'))), }, 'limits': { 'leverage': { 'min': undefined, 'max': undefined, }, 'amount': { 'min': undefined, 'max': undefined, }, 'price': { 'min': this.safeNumber(market, 'priceMin'), 'max': this.safeNumber(market, 'priceMax'), }, 'cost': { 'min': this.safeNumber(market, 'initialMargin'), 'max': undefined, }, }, 'info': market, })); } return result; } parseTicker(ticker, market = undefined) { // // spot // // { // "asset_pair_name": "ETH-BTC", // "bid": { // "price": "0.021593", // "order_count": 1, // "quantity": "0.20936" // }, // "ask": { // "price": "0.021613", // "order_count": 1, // "quantity": "2.87064" // }, // "open": "0.021795", // "high": "0.021795", // "low": "0.021471", // "close": "0.021613", // "volume": "117078.90431", // "daily_change": "-0.000182" // } // // contract // // { // "usdtPrice": 1.00031998, // "symbol": "BTCUSD", // "btcPrice": 34700.4, // "ethPrice": 1787.83, // "nextFundingRate": 0.00010, // "fundingRate": 0.00010, // "latestPrice": 34708.5, // "last24hPriceChange": 0.0321, // "indexPrice": 34700.4, // "volume24h": 261319063, // "turnover24h": 8204.129380685496, // "nextFundingTime": 1698285600000, // "markPrice": 34702.4646738, // "last24hMaxPrice": 35127.5, // "volume24hInUsd": 0.0, // "openValue": 32.88054722085945, // "last24hMinPrice": 33552.0, // "openInterest": 1141372.0 // } // const marketType = ('asset_pair_name' in ticker) ? 'spot' : 'swap'; const marketId = this.safeString2(ticker, 'asset_pair_name', 'symbol'); const symbol = this.safeSymbol(marketId, market, '-', marketType); const close = this.safeString2(ticker, 'close', 'latestPrice'); const bid = this.safeDict(ticker, 'bid', {}); const ask = this.safeDict(ticker, 'ask', {}); return this.safeTicker({ 'symbol': symbol, 'timestamp': undefined, 'datetime': undefined, 'high': this.safeString2(ticker, 'high', 'last24hMaxPrice'), 'low': this.safeString2(ticker, 'low', 'last24hMinPrice'), 'bid': this.safeString(bid, 'price'), 'bidVolume': this.safeString(bid, 'quantity'), 'ask': this.safeString(ask, 'price'), 'askVolume': this.safeString(ask, 'quantity'), 'vwap': undefined, 'open': this.safeString(ticker, 'open'), 'close': close, 'last': close, 'previousClose': undefined, 'change': this.safeString2(ticker, 'daily_change', 'last24hPriceChange'), 'percentage': undefined, 'average': undefined, 'baseVolume': this.safeString2(ticker, 'volume', 'volume24h'), 'quoteVolume': this.safeString(ticker, 'volume24hInUsd'), 'markPrice': this.safeString(ticker, 'markPrice'), 'indexPrice': this.safeString(ticker, 'indexPrice'), 'info': ticker, }, market); } /** * @method * @name bigone#fetchTicker * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market * @see https://open.big.one/docs/spot_tickers.html * @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); let type = undefined; [type, params] = this.handleMarketTypeAndParams('fetchTicker', market, params); if (type === 'spot') { const request = { 'asset_pair_name': market['id'], }; const response = await this.publicGetAssetPairsAssetPairNameTicker(this.extend(request, params)); // // { // "code":0, // "data":{ // "asset_pair_name":"ETH-BTC", // "bid":{"price":"0.021593","order_count":1,"quantity":"0.20936"}, // "ask":{"price":"0.021613","order_count":1,"quantity":"2.87064"}, // "open":"0.021795", // "high":"0.021795", // "low":"0.021471", // "close":"0.021613", // "volume":"117078.90431", // "daily_change":"-0.000182" // } // } // const ticker = this.safeDict(response, 'data', {}); return this.parseTicker(ticker, market); } else { const tickers = await this.fetchTickers([symbol], params); return this.safeValue(tickers, symbol); } } /** * @method * @name bigone#fetchTickers * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market * @see https://open.big.one/docs/spot_tickers.html * @param {string[]} [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 symbol = this.safeString(symbols, 0); if (symbol !== undefined) { market = this.market(symbol); } let type = undefined; [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params); const isSpot = type === 'spot'; const request = {}; symbols = this.marketSymbols(symbols); let data = undefined; if (isSpot) { if (symbols !== undefined) { const ids = this.marketIds(symbols); request['pair_names'] = ids.join(','); } const response = await this.publicGetAssetPairsTickers(this.extend(request, params)); // // { // "code": 0, // "data": [ // { // "asset_pair_name": "PCX-BTC", // "bid": { // "price": "0.000234", // "order_count": 1, // "quantity": "0.518" // }, // "ask": { // "price": "0.0002348", // "order_count": 1, // "quantity": "2.348" // }, // "open": "0.0002343", // "high": "0.0002348", // "low": "0.0002162", // "close": "0.0002348", // "volume": "12887.016", // "daily_change": "0.0000005" // }, // ... // ] // } // data = this.safeList(response, 'data', []); } else { data = await this.contractPublicGetInstruments(params); // // [ // { // "usdtPrice": 1.00031998, // "symbol": "BTCUSD", // "btcPrice": 34700.4, // "ethPrice": 1787.83, // "nextFundingRate": 0.00010, // "fundingRate": 0.00010, // "latestPrice": 34708.5, // "last24hPriceChange": 0.0321, // "indexPrice": 34700.4, // "volume24h": 261319063, // "turnover24h": 8204.129380685496, // "nextFundingTime": 1698285600000, // "markPrice": 34702.4646738, // "last24hMaxPrice": 35127.5, // "volume24hInUsd": 0.0, // "openValue": 32.88054722085945, // "last24hMinPrice": 33552.0, // "openInterest": 1141372.0 // } // ... // ] // } const tickers = this.parseTickers(data, symbols); return this.filterByArrayTickers(tickers, 'symbol', symbols); } /** * @method * @name bigone#fetchTime * @description fetches the current integer timestamp in milliseconds from the exchange server * @see https://open.big.one/docs/spot_ping.html * @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.publicGetPing(params); // // { // "data": { // "timestamp": 1527665262168391000 // } // } // const data = this.safeDict(response, 'data', {}); const timestamp = this.safeInteger(data, 'Timestamp'); return this.parseToInt(timestamp / 1000000); } /** * @method * @name bigone#fetchOrderBook * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data * @see https://open.big.one/docs/contract_misc.html#get-orderbook-snapshot * @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 * @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); let response = undefined; if (market['contract']) { const request = { 'symbol': market['id'], }; response = await this.contractPublicGetDepthSymbolSnapshot(this.extend(request, params)); // // { // bids: { // '20000': '20', // ... // '34552': '64851', // '34526.5': '59594', // ... // '34551.5': '29711' // }, // asks: { // '34557': '34395', // ... // '40000': '20', // '34611.5': '56024', // ... // '34578.5': '66367' // }, // to: '59737174', // lastPrice: '34554.5', // bestPrices: { // ask: '34557.0', // bid: '34552.0' // }, // from: '0' // } // return this.parseContractOrderBook(response, market['symbol'], limit); } else { const request = { 'asset_pair_name': market['id'], }; if (limit !== undefined) { request['limit'] = limit; // default 50, max 200 } response = await this.publicGetAssetPairsAssetPairNameDepth(this.extend(request, params)); // // { // "code":0, // "data": { // "asset_pair_name": "EOS-BTC", // "bids": [ // { "price": "42", "order_count": 4, "quantity": "23.33363711" } // ], // "asks": [ // { "price": "45", "order_count": 2, "quantity": "4193.3283464" } // ] // } // } // const orderbook = this.safeDict(response, 'data', {}); return this.parseOrderBook(orderbook, market['symbol'], undefined, 'bids', 'asks', 'price', 'quantity'); } } parseContractBidsAsks(bidsAsks) { const bidsAsksKeys = Object.keys(bidsAsks); const result = []; for (let i = 0; i < bidsAsksKeys.length; i++) { const price = bidsAsksKeys[i]; const amount = bidsAsks[price]; result.push([this.parseNumber(price), this.parseNumber(amount)]); } return result; } parseContractOrderBook(orderbook, symbol, limit = undefined) { const responseBids = this.safeValue(orderbook, 'bids'); const responseAsks = this.safeValue(orderbook, 'asks'); const bids = this.parseContractBidsAsks(responseBids); const asks = this.parseContractBidsAsks(responseAsks); return { 'symbol': symbol, 'bids': this.filterByLimit(this.sortBy(bids, 0, true), limit), 'asks': this.filterByLimit(this.sortBy(asks, 0), limit), 'timestamp': undefined, 'datetime': undefined, 'nonce': undefined, }; } parseTrade(trade, market = undefined) { // // fetchTrades (public) // // { // "id": 38199941, // "price": "3378.67", // "amount": "0.019812", // "taker_side": "ASK", // "created_at": "2019-01-29T06:05:56Z" // } // // fetchMyTrades (private) // // { // "id": 10854280, // "asset_pair_name": "XIN-USDT", // "price": "70", // "amount": "1", // "taker_side": "ASK", // "maker_order_id": 58284908, // "taker_order_id": 58284909, // "maker_fee": "0.0008", // "taker_fee": "0.07", // "side": "SELF_TRADING", // "inserted_at": "2019-04-16T12:00:01Z" // }, // // { // "id": 10854263, // "asset_pair_name": "XIN-USDT", // "price": "75.7", // "amount": "12.743149", // "taker_side": "BID", // "maker_order_id": null, // "taker_order_id": 58284888, // "maker_fee": null, // "taker_fee": "0.0025486298", // "side": "BID", // "inserted_at": "2019-04-15T06:20:57Z" // } // const timestamp = this.parse8601(this.safeString2(trade, 'created_at', 'inserted_at')); const priceString = this.safeString(trade, 'price'); const amountString = this.safeString(trade, 'amount'); const marketId = this.safeString(trade, 'asset_pair_name'); market = this.safeMarket(marketId, market, '-'); let side = this.safeString(trade, 'side'); const takerSide = this.safeString(trade, 'taker_side'); let takerOrMaker = undefined; if ((takerSide !== undefined) && (side !== undefined) && (side !== 'SELF_TRADING')) { takerOrMaker = (takerSide === side) ? 'taker' : 'maker'; } if (side === undefined) { // taker side is not related to buy/sell side // the following code is probably a mistake side = (takerSide === 'ASK') ? 'sell' : 'buy'; } else { if (side === 'BID') { side = 'buy'; } else if (side === 'ASK') { side = 'sell'; } } const makerOrderId = this.safeString(trade, 'maker_order_id'); const takerOrderId = this.safeString(trade, 'taker_order_id'); let orderId = undefined; if (makerOrderId !== undefined) { orderId = makerOrderId; } else if (takerOrderId !== undefined) { orderId = takerOrderId; } const id = this.safeString(trade, 'id'); const result = { 'id': id, 'timestamp': timestamp, 'datetime': this.iso8601(timestamp), 'symbol': market['symbol'], 'order': orderId, 'type': 'limit', 'side': side, 'takerOrMaker': takerOrMaker, 'price': priceString, 'amount': amountString, 'cost': undefined, 'info': trade, }; let makerCurrencyCode; let takerCurrencyCode; if (takerOrMaker !== undefined) { if (side === 'buy') { if (takerOrMaker === 'maker') { makerCurrencyCode = market['base']; takerCurrencyCode = market['quote']; } else { makerCurrencyCode = market['quote']; takerCurrencyCode = market['base']; } } else { if (takerOrMaker === 'maker') { makerCurrencyCode = market['quote']; takerCurrencyCode = market['base']; } else { makerCurrencyCode = market['base']; takerCurrencyCode = market['quote']; } } } else if (side === 'SELF_TRADING') { if (takerSide === 'BID') { makerCurrencyCode = market['quote']; takerCurrencyCode = market['base']; } else if (takerSide === 'ASK') { makerCurrencyCode = market['base']; takerCurrencyCode = market['quote']; } }