metaapi.cloud-sdk
Version:
SDK for MetaApi, a professional cloud forex API which includes MetaTrader REST API and MetaTrader websocket API. Supports both MetaTrader 5 (MT5) and MetaTrader 4 (MT4). CopyFactory copy trading API included. (https://metaapi.cloud)
30 lines (23 loc) • 724 B
text/typescript
export default (customEmitter) => {
const Emitter = customEmitter;
const emit = Emitter.prototype.emit;
const onevent = function (packet) {
var args = packet.data || [];
if (packet.id != null) { // eslint-disable-line no-eq-null, eqeqeq
args.push(this.ack(packet.id));
}
emit.call(this, '*', packet);
return emit.apply(this, args);
}
return (socket, next?) => {
let boundOnevent = onevent;
const namespaces = (process as any).namespaces || {};
for (const key of Object.keys(namespaces)) {
const ns = namespaces[key];
boundOnevent = ns.bind(boundOnevent);
}
socket.onevent = boundOnevent;
return next ? next() : null;
}
}