Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OKEX future support #60

Open
secwang opened this issue Aug 10, 2019 · 1 comment
Open

OKEX future support #60

secwang opened this issue Aug 10, 2019 · 1 comment

Comments

@secwang
Copy link

secwang commented Aug 10, 2019

Okex future support please.
Thanks for you hard work for this handy tool.

@secwang
Copy link
Author

secwang commented Aug 11, 2019

` okexWebSocketClient(c) {

        console.log("okex start")

        var socket


        const socketMessageListener = (event) => {
            if (okexEnabled) {
                // let trade = JSON.parse(event)
                // console.log(event)
                // console.log(event.data)

                var json
                var data = event.data

                try {
                    if (data instanceof String) {
                        json = JSON.parse(data);
                        cosole.log("json",json);
                    } else { json = JSON.parse(pako.inflateRaw(data, { to: 'string' }));
                        // console.log("json",json);
                    }
                } catch (error) {
                    console.log(error)
                }

                // var msg = pako.inflate(event.data)
                //
                // console.log("msg: " + msg)
                // debugger;;

                // console.log("okex trade " + JSON.stringify(event))


                var tradeRaw = json.data[0]
                let trade = Start.okexTrade(tradeRaw)
                // console.log(trade[0],okexMinMarket)
                console.log(trade[0])

                if(trade[0].size >= okexMinMarket){
                    trades = trade.concat(trades)
                }

            }
        }

        const socketOpenListener = (event) => {
            console.log('okex open')
            socket.send("{\"op\": \"subscribe\", \"args\": [\"futures\/trade:BTC-USD-190816\"]}")
        }

        const socketCloseListener = (event) => {
            if (socket) {
                console.error('okex close')
            }
            socket = new WebSocket('wss://okexcomreal.bafang.com:8443/ws/v3?compress=true')
            socket.binaryType = 'arraybuffer'
            socket.addEventListener('open', socketOpenListener)
            socket.addEventListener('message', socketMessageListener)
            socket.addEventListener('close', socketCloseListener)
        }
        socketCloseListener()
    }


    static okexTrade(tradeRaw) {
        let trade = []
        trade.push({
            symbol: "BTCUSD",
            price: tradeRaw['price'],
            size: Math.abs(parseInt(tradeRaw['qty'] * 10)),
            timestamp: tradeRaw['timestamp'],
            side: tradeRaw['side'] == 'buy',
            exchangeName: "okex",
            startTime: Date.now(),
            btcAmt: Math.abs(parseInt(tradeRaw['qty'] * 10)) / tradeRaw['price'],
            firstPrice: tradeRaw['price'],
            lastPrice: tradeRaw['price']
        })
        return trade
    }

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant