11import axios from "axios" ;
22import Binance from 'binance-api-node'
3+ import Spot from './connector/spot'
34
45const binanceApiUrl = "https://api.binance.com" ;
6+ const binanceFuturesApiUrl = "https://dapi.binance.com" ;
57const proxyUrl = "https://ntrocp887e.execute-api.eu-central-1.amazonaws.com/prod/binance" ;
68
79function extractResponse ( onSuccess ) {
@@ -26,14 +28,105 @@ const binanceApiClient = {
2628 . catch ( onError )
2729 } ,
2830 getUserInfo ( key , secret , resultConsumer , onError ) {
29- const client = Binance ( {
31+ const spotClient = Binance ( {
3032 apiKey : key ,
3133 apiSecret : secret ,
3234 httpBase : proxyUrl ,
3335 } )
34- client . accountInfo ( { recvWindow : 30000 , useServerTime : true } )
35- . then ( resultConsumer )
36- . catch ( onError )
36+
37+ spotClient . futuresAccountInfo ( { recvWindow : 30000 , useServerTime : true } ) . then ( e => {
38+ console . log ( "futuresAccountInfo" , e )
39+ } )
40+ spotClient . futuresAccountBalance ( { recvWindow : 30000 , useServerTime : true } )
41+ . then ( e => {
42+ console . log ( "futures" , e )
43+ e . filter ( f => + f . balance )
44+ . forEach ( f => console . log ( "future " + f . asset , f ) )
45+ } )
46+ . catch ( onError ) ;
47+ const client = new Spot ( key , secret , { baseURL : proxyUrl } )
48+ const futuresClient = new Spot ( key , secret , { baseURL : binanceFuturesApiUrl } )
49+ futuresClient . futuresCoinMBalance ( ) . then ( response => {
50+ console . log ( "futures COIN-M balances" , response . data )
51+ response . data . filter ( balance => + balance . balance )
52+ . forEach ( balance => console . log ( "futures COIN-M balance " + balance . asset , balance ) )
53+ } )
54+ client . isolatedMarginAccountInfo ( ) . then ( response => {
55+ console . log ( "margin isolated" , response . data )
56+ response ?. data ?. assets
57+ ?. reduce ( ( arr , o ) => {
58+ arr . push ( o . baseAsset )
59+ arr . push ( o . quoteAsset )
60+ return arr ;
61+ } , [ ] )
62+ . filter ( p => + p . netAsset )
63+ . forEach ( position => console . log ( "margin isolated " + position . asset , position ) )
64+ } )
65+ client . marginAccount ( ) . then ( response => {
66+ console . log ( "margin cross" , response . data )
67+ response ?. data ?. userAssets ?. filter ( p => + p . netAsset )
68+ . forEach ( position => console . log ( "margin cross " + position . asset , position ) )
69+ } )
70+ client . fundingWallet ( ) . then ( response => {
71+ console . log ( "fundingWallet" , response . data )
72+ response . data . filter ( asset => + asset . free )
73+ . forEach ( asset => console . log ( "funding " + asset . asset , asset ) )
74+ } )
75+ /*`STAKING`,`F_DEFI`,`L_DEFI`*/
76+ client . stakingProductPosition ( 'STAKING' ) . then ( response => {
77+ console . log ( "stakingProductPosition STAKING" , response . data )
78+ } )
79+ client . stakingProductPosition ( 'F_DEFI' ) . then ( response => {
80+ console . log ( "stakingProductPosition F_DEFI" , response . data )
81+ } )
82+ client . stakingProductPosition ( 'L_DEFI' ) . then ( response => {
83+ console . log ( "stakingProductPosition L_DEFI" , response . data )
84+ } )
85+ client . bswapUnclaimedRewards ( 0 ) . then ( response => {
86+ console . log ( "bswapUnclaimedRewards Swap rewards" , response . data )
87+ } )
88+ client . bswapUnclaimedRewards ( 1 ) . then ( response => {
89+ console . log ( "bswapUnclaimedRewards Liquidity rewards" , response . data )
90+ } )
91+ client . bswapLiquidity ( ) . then ( response => {
92+ console . log ( "bswapLiquidity" , response . data )
93+ response . data . filter ( data => + data . share . shareAmount )
94+ . reduce ( ( arr , o ) => {
95+ let keys = Object . keys ( o . share . asset ) ;
96+ let first = { ...o } ;
97+ first . symbol = keys [ 0 ]
98+ first . description = `${ first . symbol } (${ o . poolName } )`
99+ first . amount = o . share . asset [ first . symbol ]
100+ let second = { ...o } ;
101+ second . symbol = keys [ 1 ]
102+ second . description = `${ second . symbol } (${ o . poolName } )`
103+ second . amount = o . share . asset [ second . symbol ]
104+ arr . push ( first )
105+ arr . push ( second )
106+ return arr ;
107+ } , [ ] )
108+ . forEach ( data => console . log ( "bswapLiquidity " + data . description , data ) )
109+ } )
110+ client . savingsAccount ( ) . then ( response => {
111+ console . log ( "savingsAccount" , response . data )
112+ response . data . positionAmountVos ?. filter ( p => + p . amount )
113+ . forEach ( position => {
114+ client . savingsFlexibleProductPosition ( position . asset )
115+ . then ( response => {
116+ console . log ( "saving flexible " + position . asset , response . data )
117+ return client . savingsCustomizedPosition ( position . asset )
118+ } )
119+ . then ( response => {
120+ if ( ! response . data || ( response . data . __proto__ === [ ] . __proto__ && ! response . data . length ) ) {
121+ return
122+ }
123+ console . log ( "saving fixed " + position . asset , response . data )
124+ } )
125+ } )
126+ } )
127+ // client.savingsFlexibleProductPosition('USDT').then(response => console.log("savingsFlexibleProductPosition USDT", response.data))
128+ // client.savingsFlexibleProductPosition('BUSD').then(response => console.log("savingsFlexibleProductPosition BUSD", response.data))
129+ // client.isolatedMarginAccountInfo().then(response => console.log("isolatedMarginAccountInfo", response.data))
37130 }
38131} ;
39132
0 commit comments