|
|
@@ -1,71 +1,33 @@
|
|
|
+const logger = require('../../../kit/logger-kit').getLogger('binance-spot-test')
|
|
|
const BinanceSpot = require('../binance-spot')
|
|
|
const BinanceKit = require('../binance-kit')
|
|
|
-const logger = require('../../../kit/logger-kit').getLogger('binance-spot-test')
|
|
|
const Config = require('../../../config/config')
|
|
|
const PrivateConfig = require('../../../PrivateConfig')
|
|
|
+const assert = require("assert");
|
|
|
|
|
|
-async function realPriceTest() {
|
|
|
- logger.info('real price test:')
|
|
|
- logger.info(await BinanceSpot.realPrice())
|
|
|
- logger.info('')
|
|
|
-}
|
|
|
-
|
|
|
-async function exchangeInfoTest() {
|
|
|
- logger.info('exchange info test:')
|
|
|
- const pairs = Object.values(PrivateConfig.tokenMapping).map(coin => `${coin}${Config.baseIerc20Token.symbol}` )
|
|
|
- const exchangeInfo = await BinanceSpot.exchangeInfo(pairs)
|
|
|
-
|
|
|
- // logger.info(BinanceKit.parsePriceTickFilterMap(exchangeInfo.symbols))
|
|
|
- logger.info('')
|
|
|
-}
|
|
|
-
|
|
|
-async function accountInfoTest(context) {
|
|
|
- logger.info('account info test:')
|
|
|
-
|
|
|
- const binanceSpot = context.binanceSpot
|
|
|
-
|
|
|
- const accountInfoRst = await binanceSpot.accountInfo()
|
|
|
- const accountAssetMap = BinanceKit.parseBalancesToAccountAssetMap(accountInfoRst.balances)
|
|
|
-
|
|
|
- logger.info(accountAssetMap)
|
|
|
-}
|
|
|
-
|
|
|
-async function orderTest(context) {
|
|
|
- logger.info('order info test:')
|
|
|
+describe('binance-spot-test', () => {
|
|
|
+ const context = {}
|
|
|
+ context.binanceSpot = new BinanceSpot(PrivateConfig.binanceAPIKey, PrivateConfig.binanceSecretKey)
|
|
|
|
|
|
const binanceSpot = context.binanceSpot
|
|
|
|
|
|
- const orderRst = await binanceSpot.buy('HOOKBUSD', -1, Config.baseTokenAmount)
|
|
|
- logger.info(orderRst)
|
|
|
+ it('real price test', async () => {
|
|
|
+ logger.info(await BinanceSpot.realPrice())
|
|
|
+ })
|
|
|
|
|
|
- if (orderRst.executedQty) {
|
|
|
- const cummulativeQuoteQty = orderRst.cummulativeQuoteQty
|
|
|
- let executedQty = 0
|
|
|
- for (const fill of orderRst.fills) {
|
|
|
- executedQty += parseFloat(fill.qty)
|
|
|
- // 扣除支付的手续费
|
|
|
- if (fill.commissionAsset === 'HOOK') {
|
|
|
- executedQty -= parseFloat(fill.commission)
|
|
|
- }
|
|
|
- }
|
|
|
- const price = cummulativeQuoteQty / executedQty
|
|
|
+ it('exchange info test', async () => {
|
|
|
+ const pairs = Object.values(PrivateConfig.tokenMapping).map(coin => `${coin}${Config.baseIerc20Token.symbol}` )
|
|
|
+ const exchangeInfo = await BinanceSpot.exchangeInfo(pairs)
|
|
|
|
|
|
- logger.info(`消耗${Config.baseIerc20Token.symbol} ${cummulativeQuoteQty}, 买入${executedQty}, 均价${price}.`)
|
|
|
- logger.info(await binanceSpot.sell('HOOKBUSD', -1, executedQty))
|
|
|
- } else {
|
|
|
- logger.error(orderRst)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-async function main() {
|
|
|
- const context = {}
|
|
|
-
|
|
|
- context.binanceSpot = new BinanceSpot(PrivateConfig.binanceAPIKey, PrivateConfig.binanceSecretKey)
|
|
|
+ assert.notEqual(exchangeInfo.symbols, undefined, 'exchangeInfo获取失败,请重试。')
|
|
|
|
|
|
- // await realPriceTest()
|
|
|
- // await exchangeInfoTest()
|
|
|
- // await accountInfoTest(context)
|
|
|
- await orderTest(context)
|
|
|
-}
|
|
|
+ logger.info(BinanceKit.parsePriceTickFilterMap(exchangeInfo.symbols))
|
|
|
+ logger.info(BinanceKit.parseLotSizeFilterMap(exchangeInfo.symbols))
|
|
|
+ })
|
|
|
|
|
|
-main()
|
|
|
+ it('account info test', async () => {
|
|
|
+ const accountInfoRst = await binanceSpot.accountInfo()
|
|
|
+ assert.notEqual(accountInfoRst.balances, undefined, 'account info 获取失败')
|
|
|
+ logger.info(BinanceKit.parseBalancesToAccountAssetMap(accountInfoRst.balances))
|
|
|
+ })
|
|
|
+})
|