Beispiel #1
0
Datei: test.js Projekt: keon/ccxt
let testBadNonce = async (exchange, symbol) => {

    log.green ('AuthenticationError (bad nonce) test...')

    const hasFetchBalance  = exchange.has.fetchBalance
    const hasFetchMyTrades = exchange.has.fetchMyTrades
    const hasFetchOrders   = exchange.has.fetchOrders

    if (hasFetchBalance || hasFetchMyTrades || hasFetchOrders) {

        // save the nonce temporarily and replace it with a fake one
        const nonce = exchange.nonce
        exchange.nonce = () => 1

        try {

            // check if handleErrors() throws AuthenticationError if an exchange
            // responds with an error on a bad nonce
            // (still, some exchanges that require nonce silently eat bad nonce w/o an error)

            if (hasFetchBalance)
                await exchange.fetchBalance ()
            else if (hasFetchMyTrades)
                await exchange.fetchMyTrades (symbol, 0)
            else
                await exchange.fetchOrders (symbol)

            // restore the nonce so the caller may proceed in case bad nonce was accepted by an exchange
            exchange.nonce = nonce
            log.warn (exchange.id + ': AuthenticationError: bad nonce swallowed')

        } catch (e) {

            // restore the nonce so the caller may proceed in case the test failed
            exchange.nonce = nonce
            if (e instanceof ccxt.AuthenticationError || e instanceof ccxt.InvalidNonce) {

                // it has thrown the exception as expected
                log.green ('AuthenticationError test passed')

            } else {

                // rethrow an unexpected error if any
                throw e
            }
        }

    } else {

        log (exchange.id + ' has no means of testing for bad nonce')

    }

}
Beispiel #2
0
 downloadFile: function (cfg) {
     if (cfg.overwrite === false && fs.existsSync (cfg.dst)) {
         log.green ('downloadFile: already exists at', cfg.dst)
         cfg.success (cfg.dst)
     } else {
         log.warn ('downloadFile: downloading', cfg.src.path)
         var req = (cfg.src.port === 443 ? https : http).get (cfg.src, function (response) {
             module.exports.writeRequestDataToFile (_.extend (_.pick (cfg, 'success', 'failure'), {
                 request: response,
                 filePath: cfg.dst
             }))
         })
         req.on ('error', function(err) {
             cfg.failure (err.message)
         })
     }
 },