Current Folder

This commit is contained in:
Luis Fernando Molina committed 2020-11-20 14:05:59 +01:00
1 parent 8b3382289b
commit cfcada880d
4379 files changed

No files matched your search

-90
View File
@@ -1,90 +0,0 @@
'use strict'
// ----------------------------------------------------------------------------
const log = require ('ololog')
, ansi = require ('ansicolor').nice
, chai = require ('chai')
, ccxt = require ('../../../ccxt.js')
, expect = chai.expect
, assert = chai.assert
/* ------------------------------------------------------------------------ */
// will try to place a buy order at the minimum price level on minimum amount possible
// will skip if balance is positive or market limits are not set
module.exports = async (exchange, symbol, balance) => {
if (!exchange.has.createOrder) {
log ('createOrder not supported')
return
}
const markets = await exchange.loadMarkets ()
const market = markets[symbol]
if (market.limits === undefined) {
log ('market.limits property is not set, will not test order creation')
return
}
const { price, amount, cost } = market.limits
if (price === undefined || amount === undefined || cost === undefined) {
log ('market.limits.[price|amount|cost] property is not set, will not test order creation')
return
}
let minPrice = price.min
let minAmount = amount.min // will be adjusted co cover minCost if needed
const minCost = cost.min
if (minPrice === undefined || minAmount === undefined || minCost === undefined) {
log ('min limits are not set, will not test order creation')
return
}
if (minCost > minPrice * minAmount) {
minAmount = minCost / minPrice
}
minPrice = exchange.priceToPrecision (symbol, minPrice)
minAmount = exchange.amountToPrecision (symbol, minAmount)
if (balance === undefined) {
log ('balance is not set, cannot ensure safety, will not test order creation')
return
}
const { base, quote } = market
if (balance[quote] !== undefined && balance[quote].total > 0) {
log ('balance is not empty, will not test order creation')
return
}
try {
log ('creating limit buy order...', symbol, minAmount, minPrice)
let order = await exchange.createLimitBuyOrder (symbol, minAmount, minPrice)
log ('order created although it should not had to - cleaning up')
log (order)
await exchange.cancelOrder (order.id, symbol)
assert.fail ()
} catch (e) {
if (e instanceof ccxt.InsufficientFunds) {
log ('InsufficientFunds thrown as expected')
} else {
log ('InsufficientFunds failed, exception follows:')
throw e
}
}
}
-67
View File
@@ -1,67 +0,0 @@
'use strict'
// ----------------------------------------------------------------------------
const log = require ('ololog')
, ansi = require ('ansicolor').nice
, chai = require ('chai')
, ccxt = require ('../../../ccxt.js')
, expect = chai.expect
, assert = chai.assert
/* ------------------------------------------------------------------------ */
module.exports = 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')
}
}
-39
View File
@@ -1,39 +0,0 @@
'use strict'
// ----------------------------------------------------------------------------
const log = require ('ololog')
, ansi = require ('ansicolor').nice
, chai = require ('chai')
, ccxt = require ('../../../ccxt.js')
, expect = chai.expect
, assert = chai.assert
/* ------------------------------------------------------------------------ */
module.exports = async (exchange, symbol) => {
if (!exchange.has.createOrder) {
log ('createOrder not supported')
return
}
try {
await exchange.createLimitBuyOrder (symbol, 0, 0)
assert.fail ()
} catch (e) {
if (e instanceof ccxt.InvalidOrder) {
log ('InvalidOrder thrown as expected')
return
} else {
log ('InvalidOrder failed, exception follows:')
throw e
}
}
}
-43
View File
@@ -1,43 +0,0 @@
'use strict'
// ----------------------------------------------------------------------------
const log = require ('ololog')
, ansi = require ('ansicolor').nice
, chai = require ('chai')
, ccxt = require ('../../../ccxt.js')
, expect = chai.expect
, assert = chai.assert
/* ------------------------------------------------------------------------ */
module.exports = async (exchange, symbol) => {
if (!exchange.has.createOrder) {
log ('createOrder not supported -> test skipped')
return
}
let id = 1
try {
await exchange.cancelOrder (id, symbol)
log ('test failed')
assert.fail ()
} catch (e) {
if (e instanceof ccxt.OrderNotFound) {
log ('OrderNotFound thrown as expected')
} else {
log ('OrderNotFound test failed')
throw e
}
}
}