futu-rx
Version:
Futu Open API rxjs client
47 lines (41 loc) • 1.37 kB
JavaScript
const path = require("path");
const uuid = require('../util/uuid');
const protoLoader = require('./helper/protoLoader');
const header = require('./helper/header');
const tap = require('rxjs/operators').tap;
const protoPath = path.resolve(__dirname, "../pb/InitConnect.proto");
const [Request, Response] = protoLoader.load(protoPath);
// https://futunnopen.github.io/futu-api-doc/protocol/base_define.html#initconnect-proto-1001
module.exports = function () {
const protoId = "1001";
const self = this;
const args = Array.prototype.slice.call(arguments);
const c2sPayload = {
clientVer: 220,
clientID: uuid.v4(),
recvNotify: true,
packetEncAlgo: -1,
pushProtoFmt: 0
};
self
.dataRecv()
.subscribe(
(respBuf) => {
var h = header.parse(respBuf)
}
);
return self._requestProcessor
.process(protoId, Request, Response, c2sPayload, {
func: "InitConnect",
args: args
})
.pipe(
tap((context) => {
const response = context.response;
self._protocolStateObj["connID"] = response['s2c']['connID']
self._protocolStateObj['aesKey'] = response['s2c']['connAESKey'];
self._protocolStateObj['keepAliveInterval'] = response['s2c']['keepAliveInterval'];
self._protocolStateSubject.next(new Set(["aesKey", "keepAliveInterval"]));
})
);
}