| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import 'dotenv/config'
- import { AsterAdapter } from '../src/exchanges/aster/asterAdapter'
- import { AsterExchangeAdapter } from '../src/exchanges/aster/AsterExchangeAdapter'
- async function main() {
- const base = process.env.ASTER_HTTP_BASE || 'https://fapi.asterdex.com'
- const symbol = process.env.ASTER_TEST_SYMBOL || 'BTCUSDT'
- const apiKey = process.env.ASTER_API_KEY || ''
- const apiSecret = process.env.ASTER_API_SECRET || ''
- const user = process.env.ASTER_ORDER_USER || ''
- const signer = process.env.ASTER_ORDER_SIGNER || ''
- const pk = process.env.PRIVATE_KEY || ''
- const adapter = new AsterAdapter({
- rpcUrl: '',
- chainId: 0,
- routerAddress: '',
- httpBase: base,
- defaultUser: user,
- defaultSigner: signer,
- apiKey,
- apiSecret,
- })
- const ex = new AsterExchangeAdapter(adapter)
- // Symbols
- const syms = await ex.symbols()
- console.log('symbols count =', syms.length)
- // Depth top
- try {
- const d = await ex.depth(symbol, 10)
- console.log('depth top', symbol, 'bid=', d.bids?.[0], 'ask=', d.asks?.[0])
- } catch (e: any) {
- console.warn('depth failed', e?.message || e)
- }
- // Balances / Positions (require HMAC keys)
- if (apiKey && apiSecret) {
- try {
- const bals = await ex.balances()
- console.log('balances[0]=', bals[0])
- } catch (e: any) {
- console.warn('balances failed', e?.message || e)
- }
- try {
- const poss = await ex.positions()
- console.log('positions[0]=', poss[0])
- } catch (e: any) {
- console.warn('positions failed', e?.message || e)
- }
- try {
- const opens = await ex.openOrders(symbol)
- console.log('openOrders len =', opens.length)
- } catch (e: any) {
- console.warn('openOrders failed', e?.message || e)
- }
- } else {
- console.log('HMAC not configured, skip balances/positions/openOrders')
- }
- // Optional order flow (requires user/signer/private key)
- if (process.env.ASTER_ENABLE_ORDER === '1') {
- if (!user || !signer || !pk) throw new Error('Missing ASTER_ORDER_USER/ASTER_ORDER_SIGNER/PRIVATE_KEY')
- const notionalUsd = process.env.ASTER_TEST_NOTIONAL_USD ? Number(process.env.ASTER_TEST_NOTIONAL_USD) : undefined
- let qty = Number(process.env.ASTER_TEST_QTY || '0')
- if (notionalUsd) {
- const px = await adapter.quote({ symbol, side: 'long', quantity: 0, slippage: 0 }).then(r => r.expectedPrice)
- if (!px) throw new Error('price not available')
- qty = +(notionalUsd / px).toFixed(3)
- }
- if (!qty || qty <= 0) qty = 0.001
- console.log('place MARKET BUY', { symbol, qty })
- const o1 = await ex.placeOrder({ symbol, side: 'BUY', type: 'MARKET', quantity: String(qty) })
- console.log('BUY result', o1)
- console.log('place MARKET SELL', { symbol, qty })
- const o2 = await ex.placeOrder({ symbol, side: 'SELL', type: 'MARKET', quantity: String(qty) })
- console.log('SELL result', o2)
- }
- }
- main().catch(e => {
- console.error('aster adapter smoke error', e?.message || e)
- process.exit(1)
- })
|