| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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')
- 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(Config.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:')
- const binanceSpot = context.binanceSpot
- const orderRst = await binanceSpot.buy('HOOKBUSD', -1, Config.baseTokenAmount)
- logger.info(orderRst)
- 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
- 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)
- // await realPriceTest()
- // await exchangeInfoTest()
- // await accountInfoTest(context)
- await orderTest(context)
- }
- main()
|