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

View File

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