binance-spot-test.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const logger = require('../../../kit/logger-kit').getLogger('binance-spot-test')
  2. const BinanceSpot = require('../binance-spot')
  3. const BinanceKit = require('../binance-kit')
  4. const assert = require("assert");
  5. describe('binance-spot-test', () => {
  6. const context = {}
  7. const binanceSpot = context.binanceSpot
  8. const config = context.config
  9. context.binanceSpot = new BinanceSpot(config.binanceAPIKey, config.binanceSecretKey)
  10. it('real price test', async () => {
  11. logger.info(await BinanceSpot.realPrice())
  12. })
  13. it('exchange info test', async () => {
  14. const pairs = Object.values(config.tokenMapping).map(coin => `${coin}${config.baseIerc20Token.symbol}` )
  15. const exchangeInfo = await BinanceSpot.exchangeInfo(pairs)
  16. assert.notEqual(exchangeInfo.symbols, undefined, 'exchangeInfo获取失败,请重试。')
  17. logger.info(BinanceKit.parsePriceTickFilterMap(exchangeInfo.symbols))
  18. logger.info(BinanceKit.parseLotSizeFilterMap(exchangeInfo.symbols))
  19. })
  20. it('account info test', async () => {
  21. const accountInfoRst = await binanceSpot.accountInfo()
  22. assert.notEqual(accountInfoRst.balances, undefined, 'account info 获取失败')
  23. logger.info(BinanceKit.parseBalancesToAccountAssetMap(accountInfoRst.balances))
  24. })
  25. it('buy market test', async () => {
  26. try {
  27. const buyMarketRst = await binanceSpot.buyMarket('DOGEBUSD', 150)
  28. logger.info(buyMarketRst)
  29. } catch (e) {
  30. logger.error(`${e}`)
  31. }
  32. })
  33. it('sell market test', async () => {
  34. const sellMarketRst = await binanceSpot.sellMarket('DOGEBUSD', 160)
  35. logger.info(sellMarketRst)
  36. })
  37. })