<commit_before>'use strict';

// ---------------------------------------------------------------------------

const Exchange = require ('./base/Exchange');
const { ExchangeError, ArgumentsRequired, AuthenticationError, InsufficientFunds, InvalidOrder } = require ('./base/errors');

// ---------------------------------------------------------------------------

module.exports = class idex extends Exchange {
    describe () {
        return this.deepExtend (super.describe (), {
            'id': 'idex',
            'name': 'IDEX',
            'countries': [ 'US' ],
            'rateLimit': 1500,
            'version': '0',
            'requiresWeb3': true,
            'has': {
                'fetchOrderBook': true,
                'fetchTicker': true,
                'fetchTickers': true,
                'fetchMarkets': true,
                'fetchBalance': true,
                'createOrder': true,
                'cancelOrder': true,
                'fetchTransactions': true,
                'fetchTrades': false,
                'fetchMyTrades': true,
                'withdraw': true,
                'fetchOHLCV': false,
            },
            'timeframes': {
                '1m': 'M1',
                '3m': 'M3',
                '5m': 'M5',
                '15m': 'M15',
                '30m': 'M30', // default
                '1h': 'H1',
                '4h': 'H4',
                '1d': 'D1',
                '1w': 'D7',
                '1M': '1M',
            },
            'urls': {
                'test': 'https://api.idex.market/',
                'logo': 'https://oracconstimes.com/wp-content/uploads/2018/05/IDEX.market.png',
                'api': 'https://api.idex.market/',
                'www': 'https://idex.market/',
                'doc': [
                    'https://github.com/AuroraDAO/idex-api-docs',
                ],
            },
            'api': {
                'public': {
                    'post': [
                        'returnTicker',
                        'returnCurrenciesWithPairs', // undocumented
                        'returnCurrencies',
                        'return24Volume',
                        'returnBalances',
                        'returnCompleteBalances', // shows amount in orders as well as total
                        'returnDepositsWithdrawals',
                        'returnOpenOrders',
                        'returnOrderBook',
                        'returnOrderStatus',
                        'returnOrderTrades',
                        'returnTradeHistory',
                        'returnTradeHistoryMeta', // not documented
                        'returnContractAddress',
                        'returnNextNonce',
                    ],
                },
                'private': {
                    'post': [
                        'order',
                        'cancel',
                        'trade',
                        'withdraw',
                    ],
                },
            },
            'options': {
                'contractAddress': undefined,  // 0x2a0c0DBEcC7E4D658f48E01e3fA353F44050c208
                'orderNonce': undefined,
            },
            'exceptions': {
                'Invalid order signature. Please try again.': AuthenticationError,
                'You have insufficient funds to match this order. If you believe this is a mistake please refresh and try again.': InsufficientFunds,
                'Order no longer available.': InvalidOrder,
            },
            'requiredCredentials': {
                'walletAddress': true,
                'privateKey': true,
                'apiKey': false,
                'secret': false,
            },
        });
    }

    async fetchMarkets (params = {}) {
        // idex does not have an endpoint for markets
        // instead we generate the markets from the endpoint for currencies
        const request = {
            'includeDelisted': true,
        };
        const markets = await this.publicPostReturnCurrenciesWithPairs (this.extend (request, params));
        const currenciesById = {};
        const currencies = markets['tokens'];
        for (let i = 0; i < currencies.length; i++) {
            const currency = currencies[i];
            currenciesById[currency['symbol']] = currency;
        }
        const result = [];
        const limits = {
            'amount': {
                'min': undefined,
                'max': undefined,
            },
            'price': {
                'min': undefined,
                'max': undefined,
            },
            'cost': {
                'min': undefined,
                'max': undefined,
            },
        };
        const quotes = markets['pairs'];
        const keys = Object.keys (quotes);
        for (let i = 0; i < keys.length; i++) {
            const quoteId = keys[i];
            const bases = quotes[quoteId];
            const quote = this.safeCurrencyCode (quoteId);
            const quoteCurrency = currenciesById[quoteId];
            for (let j = 0; j < bases.length; j++) {
                const baseId = bases[j];
                const id = quoteId + '_' + baseId;
                const base = this.safeCurrencyCode (baseId);
                const symbol = base + '/' + quote;
                const baseCurrency = currenciesById[baseId];
                const baseAddress = baseCurrency['address'];
                const quoteAddress = quoteCurrency['address'];
                const precision = {
                    'price': this.safeInteger (quoteCurrency, 'decimals'),
                    'amount': this.safeInteger (baseCurrency, 'decimals'),
                };
                result.push ({
                    'symbol': symbol,
                    'precision': precision,
                    'base': base,
                    'quote': quote,
                    'baseId': baseAddress,
                    'quoteId': quoteAddress,
                    'limits': limits,
                    'id': id,
                    'info': baseCurrency,
                    'tierBased': false,
                });
            }
        }
        return result;
    }

    parseTicker (ticker, market = undefined) {
        // { last: '0.0016550916',
        //   high: 'N/A',
        //   low: 'N/A',
        //   lowestAsk: '0.0016743368',
        //   highestBid: '0.001163726270773897',
        //   percentChange: '0',
        //   baseVolume: '0',
        //   quoteVolume: '0' }
        let symbol = undefined;
        if (market) {
            symbol = market['symbol'];
        }
        const baseVolume = this.safeFloat (ticker, 'baseVolume');
        const quoteVolume = this.safeFloat (ticker, 'quoteVolume');<commit_msg>idex minor edits / syntax checks<commit_after>'use strict';

// ---------------------------------------------------------------------------

const Exchange = require ('./base/Exchange');
const { ExchangeError, ArgumentsRequired, AuthenticationError, InsufficientFunds, InvalidOrder } = require ('./base/errors');

// ---------------------------------------------------------------------------

module.exports = class idex extends Exchange {
    describe () {
        return this.deepExtend (super.describe (), {
            'id': 'idex',
            'name': 'IDEX',
            'countries': [ 'US' ],
            'rateLimit': 1500,
            'version': '0',
            'requiresWeb3': true,
            'has': {
                'fetchOrderBook': true,
                'fetchTicker': true,
                'fetchTickers': true,
                'fetchMarkets': true,
                'fetchBalance': true,
                'createOrder': true,
                'cancelOrder': true,
                'fetchTransactions': true,
                'fetchTrades': false,
                'fetchMyTrades': true,
                'withdraw': true,
                'fetchOHLCV': false,
            },
            'timeframes': {
                '1m': 'M1',
                '3m': 'M3',
                '5m': 'M5',
                '15m': 'M15',
                '30m': 'M30', // default
                '1h': 'H1',
                '4h': 'H4',
                '1d': 'D1',
                '1w': 'D7',
                '1M': '1M',
            },
            'urls': {
                'test': 'https://api.idex.market/',
                'logo': 'https://oracconstimes.com/wp-content/uploads/2018/05/IDEX.market.png',
                'api': 'https://api.idex.market/',
                'www': 'https://idex.market/',
                'doc': [
                    'https://github.com/AuroraDAO/idex-api-docs',
                ],
            },
            'api': {
                'public': {
                    'post': [
                        'returnTicker',
                        'returnCurrenciesWithPairs', // undocumented
                        'returnCurrencies',
                        'return24Volume',
                        'returnBalances',
                        'returnCompleteBalances', // shows amount in orders as well as total
                        'returnDepositsWithdrawals',
                        'returnOpenOrders',
                        'returnOrderBook',
                        'returnOrderStatus',
                        'returnOrderTrades',
                        'returnTradeHistory',
                        'returnTradeHistoryMeta', // not documented
                        'returnContractAddress',
                        'returnNextNonce',
                    ],
                },
                'private': {
                    'post': [
                        'order',
                        'cancel',
                        'trade',
                        'withdraw',
                    ],
                },
            },
            'options': {
                'contractAddress': undefined,  // 0x2a0c0DBEcC7E4D658f48E01e3fA353F44050c208
                'orderNonce': undefined,
            },
            'exceptions': {
                'Invalid order signature. Please try again.': AuthenticationError,
                'You have insufficient funds to match this order. If you believe this is a mistake please refresh and try again.': InsufficientFunds,
                'Order no longer available.': InvalidOrder,
            },
            'requiredCredentials': {
                'walletAddress': true,
                'privateKey': true,
                'apiKey': false,
                'secret': false,
            },
        });
    }

    async fetchMarkets (params = {}) {
        // idex does not have an endpoint for markets
        // instead we generate the markets from the endpoint for currencies
        const request = {
            'includeDelisted': true,
        };
        const markets = await this.publicPostReturnCurrenciesWithPairs (this.extend (request, params));
        const currenciesById = {};
        const currencies = markets['tokens'];
        for (let i = 0; i < currencies.length; i++) {
            const currency = currencies[i];
            currenciesById[currency['symbol']] = currency;
        }
        const result = [];
        const limits = {
            'amount': {
                'min': undefined,
                'max': undefined,
            },
            'price': {
                'min': undefined,
                'max': undefined,
            },
            'cost': {
                'min': undefined,
                'max': undefined,
            },
        };
        const quotes = markets['pairs'];
        const keys = Object.keys (quotes);
        for (let i = 0; i < keys.length; i++) {
            const quoteId = keys[i];
            const bases = quotes[quoteId];
            const quote = this.safeCurrencyCode (quoteId);
            const quoteCurrency = currenciesById[quoteId];
            for (let j = 0; j < bases.length; j++) {
                const baseId = bases[j];
                const id = quoteId + '_' + baseId;
                const base = this.safeCurrencyCode (baseId);
                const symbol = base + '/' + quote;
                const baseCurrency = currenciesById[baseId];
                const baseAddress = baseCurrency['address'];
                const quoteAddress = quoteCurrency['address'];
                const precision = {
                    'price': this.safeInteger (quoteCurrency, 'decimals'),
                    'amount': this.safeInteger (baseCurrency, 'decimals'),
                };
                result.push ({
                    'symbol': symbol,
                    'precision': precision,
                    'base': base,
                    'quote': quote,
                    'baseId': baseAddress,
                    'quoteId': quoteAddress,
                    'limits': limits,
                    'id': id,
                    'info': baseCurrency,
                    'tierBased': false,
                });
            }
        }
        return result;
    }

    parseTicker (ticker, market = undefined) {
        //
        //     {
        //         last: '0.0016550916',
        //         high: 'N/A',
        //         low: 'N/A',
        //         lowestAsk: '0.0016743368',
        //         highestBid: '0.001163726270773897',
        //         percentChange: '0',
        //         baseVolume: '0',
        //         quoteVolume: '0'
        //     }
        //
        let symbol = undefined;
        if (market) {
            symbol = market['symbol'];
        }
        const baseVolume = this.safeFloat (ticker, 'baseVolume');
        const quoteVolume = this.safeFloat (ticker, 'quoteVolume');
{'fraction_non_alphanumeric': 0.1390660508760355, 'fraction_numerical': 0.016127849864379443, 'mean_word_length': 1.0952234679772692, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1713211', 'n_tokens_mistral': 3573, 'n_tokens_neox': 3246, 'n_words': 749}