Skip to content

Commit

Permalink
Merge pull request ccxt#4746 from ccxt/npm_tags_generation
Browse files Browse the repository at this point in the history
NPM keywords are now added automatically from exchanges' definitions
  • Loading branch information
kroitor authored Feb 26, 2019
2 parents 15678b6 + d409a88 commit 437fb19
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 16 deletions.
41 changes: 27 additions & 14 deletions export-exchanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const fs = require ('fs')
const countries = require ('./countries')
const asTable = require ('as-table')
const util = require ('util')
const execSync = require ('child_process').execSync
const log = require ('ololog').unlimited
const ansi = require ('ansicolor').nice
const { keys, values } = Object

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

Expand Down Expand Up @@ -121,18 +121,14 @@ for (let id in exchanges) {
exchanges[id].verbose = verbose
}

// console.log (Object.values (ccxt).length)

var countryName = function (code) {
return ((countries[code] !== undefined) ? countries[code] : code)
}

let sleep = async ms => await new Promise (resolve => setTimeout (resolve, ms))

// ---------------------------------------------------------------------------
// list all supported exchanges

let values = Object.values (exchanges).map (exchange => {
let tableData = values (exchanges).map (exchange => {
let logo = exchange.urls['logo']
let website = Array.isArray (exchange.urls.www) ? exchange.urls.www[0] : exchange.urls.www
let url = exchange.urls.referral || website
Expand All @@ -153,7 +149,7 @@ let values = Object.values (exchanges).map (exchange => {
]
})

values.splice (0, 0, tableHeadings)
tableData.splice (0, 0, tableHeadings)

function makeTable (jsonArray) {
let table = asTable.configure ({ 'delimiter': ' | ' }) (jsonArray)
Expand All @@ -166,8 +162,8 @@ function makeTable (jsonArray) {
return lines.map (line => '|' + line + '|').join ("\n")
}

let exchangesTable = makeTable (values)
let numExchanges = Object.keys (exchanges).length
let exchangesTable = makeTable (tableData)
let numExchanges = keys (exchanges).length
let beginning = "The ccxt library currently supports the following "
let ending = " cryptocurrency exchange markets and trading APIs:\n\n"
let totalString = beginning + numExchanges + ending
Expand All @@ -178,18 +174,18 @@ replaceInFile (wikiPath + '/Manual.md', allExchangesRegex, howMany)
replaceInFile (wikiPath + '/Exchange-Markets.md', allExchangesRegex, howMany)

let certifiedFieldIndex = tableHeadings.indexOf ('certified')
let certified = values.filter ((x) => x[certifiedFieldIndex] !== '' )
let certified = tableData.filter ((x) => x[certifiedFieldIndex] !== '' )
let allCertifiedRegex = new RegExp ("^(## Certified Cryptocurrency Exchanges\n{3})(?:\\|.+\\|$\n)+", 'm')
let certifiedTable = makeTable (certified)
let certifiedTableReplacement = '$1' + certifiedTable + "\n"
replaceInFile ('README.md', allCertifiedRegex, certifiedTableReplacement)


let exchangesByCountries = []
Object.keys (countries).forEach (code => {
keys (countries).forEach (code => {
let country = countries[code]
let result = []
Object.keys (exchanges).forEach (id => {
keys (exchanges).forEach (id => {
let exchange = exchanges[id]
let logo = exchange.urls['logo']
let website = Array.isArray (exchange.urls.www) ? exchange.urls.www[0] : exchange.urls.www
Expand Down Expand Up @@ -250,7 +246,7 @@ fs.truncateSync (filename)
fs.writeFileSync (filename, result)

log.bright ('Exporting exchange ids to'.cyan, 'exchanges.json'.yellow)
fs.writeFileSync ('exchanges.json', JSON.stringify ({ ids: Object.keys (exchanges) }, null, 4))
fs.writeFileSync ('exchanges.json', JSON.stringify ({ ids: keys (exchanges) }, null, 4))

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

Expand All @@ -262,10 +258,27 @@ const ccxtWikiFileMapping = {
'Exchange-Markets-By-Country.md': 'Exchange-Markets-By-Country.md',
}

Object.keys (ccxtWikiFileMapping)
keys (ccxtWikiFileMapping)
.forEach (file =>
fs.writeFileSync (gitWikiPath + '/' + ccxtWikiFileMapping[file], fs.readFileSync (wikiPath + '/' + file)))

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

log.bright ('Exporting exchange keywords to'.cyan, 'package.json'.yellow)

const packageJSON = require ('./package.json')
const keywords = new Set (packageJSON.keywords)

for (const ex of values (exchanges)) {
for (const url of Array.isArray (ex.urls.www) ? ex.urls.www : [ex.urls.www]) {
keywords.add (url.replace (/(http|https):\/\/(www\.)?/, '').replace (/\/.*/, ''))
}
keywords.add (ex.name)
}

packageJSON.keywords = [...keywords]
fs.writeFileSync ('./package.json', JSON.stringify (packageJSON, null, 2))

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

log.bright.green ('Exchanges exported successfully.')
164 changes: 162 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,171 @@
"yobit.net",
"YUNBI",
"Zaif",
"ZB"
"ZB",
"1btcxe.com",
"Allcoin",
"anxpro.com",
"anybits.com",
"Anybits",
"bcex.top",
"BCEX",
"Bibox",
"big.one",
"BigONE",
"bitbank.cc",
"bitbank",
"bitbay.net",
"bitfinex.com",
"bitFlyer",
"bitforex.com",
"Bitforex",
"Bithumb",
"bitibu.com",
"Bitibu",
"bitkk.com",
"bitkk",
"bitlish.com",
"Bitlish",
"bitmarket.pl",
"bitmarket.net",
"bitmex.com",
"bitsane.com",
"Bitsane",
"bitso.com",
"bitstamp.net",
"bittrex.com",
"bit-z.com",
"Bit-Z",
"bl3p.eu",
"bitonic.nl",
"Braziliex",
"btc-alpha.com",
"BTC-Alpha",
"btcchina.com",
"btctrade.im",
"BtcTrade.im",
"buda.com",
"Buda",
"bx.in.th",
"c-cex.com",
"cex.io",
"trade.chbtc.com",
"cobinhood.com",
"COBINHOOD",
"coinbase.com",
"Coinbase",
"prime.coinbase.com",
"Coinbase Prime",
"pro.coinbase.com",
"Coinbase Pro",
"coincheck.com",
"coinegg.com",
"CoinEgg",
"coinex.com",
"CoinEx",
"coinfalcon.com",
"CoinFalcon",
"coinfloor.co.uk",
"coinfloor",
"Coingi",
"coinmarketcap.com",
"coinmate.io",
"coinnest.co.kr",
"coinnest",
"coinone.co.kr",
"CoinOne",
"cointiger.pro",
"CoinTiger",
"coolcoin.com",
"CoolCoin",
"coss.io",
"COSS",
"crex24.com",
"CREX24",
"cryptonbtc.com",
"Crypton",
"deribit.com",
"Deribit",
"ethfinex.com",
"Ethfinex",
"exmo.me",
"exx.com",
"EXX",
"fcoin.com",
"FCoin",
"trader.flowbtc.com",
"fybse.se",
"fybsg.com",
"gatecoin.com",
"gate.io",
"Gate.io",
"gdax.com",
"gemini.com",
"getbtc.org",
"GetBTC",
"hadax.com",
"HADAX",
"hitbtc.com",
"Huobi Pro",
"huobi.com.ru",
"Huobi Russia",
"ice3x.com",
"ice3x.co.za",
"ICE3X",
"indodax.com",
"INDODAX",
"itbit.com",
"kkex.com",
"KKEX",
"kraken.com",
"kucoin.com",
"KuCoin",
"kuna.io",
"lbank.info",
"LBank",
"liquid.com",
"Liquid",
"livecoin.net",
"luno.com",
"lykke.com",
"Lykke",
"mercadobitcoin.com.br",
"Mercado Bitcoin",
"MixCoins",
"negociecoins.com.br",
"NegocieCoins",
"Novaexchange",
"okcoin.cn",
"OKCoin CNY",
"okcoin.com",
"OKCoin USD",
"paymium.com",
"poloniex.com",
"quadrigacx.com",
"rightbtc.com",
"RightBTC",
"southxchange.com",
"SouthXchange",
"stronghold.co",
"Stronghold",
"theocean.trade",
"The Ocean",
"therocktrading.com",
"tidebit.com",
"TideBit",
"uex.com",
"UEX",
"upbit.com",
"Upbit",
"vaultoro.com",
"virwox.com",
"yunbi.com",
"zaif.jp",
"zb.com"
],
"collective": {
"type": "opencollective",
"url": "https://opencollective.com/ccxt",
"logo": "https://opencollective.com/ccxt/logo.txt"
}
}
}

0 comments on commit 437fb19

Please sign in to comment.