Implement whitelist websocket handling

This commit is contained in:
Matthias 2022-10-30 15:05:13 +01:00
parent b6b4410d37
commit a55b2bf0b4
2 changed files with 25 additions and 8 deletions

View File

@ -39,6 +39,7 @@ import axios, { AxiosResponse } from 'axios';
import { defineStore } from 'pinia';
import { showAlert } from './alerts';
import { useWebSocket } from '@vueuse/core';
import { FtWsMessageTypes } from '@/types/wsMessageTypes';
export function createBotSubStore(botId: string, botName: string) {
const userService = useUserService(botId);
@ -809,6 +810,15 @@ export function createBotSubStore(botId: string, botName: string) {
return Promise.reject(err);
}
},
_handleWebsocketMessage(ws, event: MessageEvent<any>) {
const msg = JSON.parse(event.data);
if (msg.type === FtWsMessageTypes.whitelist) {
this.whitelist = msg.data;
} else {
// Unhandled events ...
console.log(`Received event ${msg.type}`);
}
},
startWebSocket() {
if (
this.websocketStarted === true ||
@ -834,24 +844,25 @@ export function createBotSubStore(botId: string, botName: string) {
this.websocketStarted = false;
close();
},
onMessage: (ws, event) => {
// console.log('Event', event, typeof event.data);
const msg = JSON.parse(event.data);
console.log(`Received event ${msg.type}`);
// TODO: implement proper message handling
},
onMessage: this._handleWebsocketMessage,
onConnected: () => {
console.log('subscribing');
this.websocketStarted = true;
send(
JSON.stringify({
type: 'subscribe',
data: ['whitelist', 'entry_fill', 'exit_fill', 'new_candle' /*'analyzed_df'*/],
data: [
FtWsMessageTypes.whitelist,
FtWsMessageTypes.entryFill,
FtWsMessageTypes.exitFill,
// FtWsMessageTypes.newCandle,
/*'new_candle' /*'analyzed_df'*/
],
}),
);
send(
JSON.stringify({
type: 'whitelist',
type: FtWsMessageTypes.whitelist,
data: '',
}),
);

View File

@ -0,0 +1,6 @@
export enum FtWsMessageTypes {
whitelist = 'whitelist',
entryFill = 'entry_fill',
exitFill = 'exit_fill',
newCandle = 'newCandle',
}