-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtestBinanceWebsocket.js
45 lines (34 loc) · 1.17 KB
/
testBinanceWebsocket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// documentazione: https://github.com/binance-exchange/binance-api-node#candles-1
'use strict'
const dotenv = require('dotenv')
dotenv.config()
const Binance = require('binance-api-node').default
const clients = []
process.env.BINANCE_SPOT_KEY.split(',').forEach((v, i) => {
clients.push(Binance({
apiKey: process.env.BINANCE_SPOT_KEY.split(',')[i],
apiSecret: process.env.BINANCE_SPOT_SECRET.split(',')[i]
}))
})
const client = clients[0]
/* client.ws.candles('SOLUSDT', '1m', candle => {
console.log(candle)
}) */
let buy = 0
let sell = 0
client.ws.trades(['SOLUSDT'], trade => {
console.log('\ndata operazione:', new Date(trade.tradeTime))
// console.log(trade)
// console.log('soldi spesi:', trade.quantity * trade.price)
// solo i taker muovono il mercato
// i maker sono quelli che mettono gli ordini limit
// console.log('compra?', trade.isBuyerMaker === true)
if (trade.isBuyerMaker === true) {
buy += trade.quantity * trade.price
} else {
sell += trade.quantity * trade.price
}
// console.log('buy', buy)
// console.log('sell', sell)
console.log('buy', buy, 'sell', sell, 'buy % difference', ((buy - sell) / buy * 100).toFixed(2))
})