mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-26 21:15:15 +00:00
Implement whitelist websocket handling
This commit is contained in:
parent
b6b4410d37
commit
a55b2bf0b4
|
@ -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: '',
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
6
src/types/wsMessageTypes.ts
Normal file
6
src/types/wsMessageTypes.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
export enum FtWsMessageTypes {
|
||||||
|
whitelist = 'whitelist',
|
||||||
|
entryFill = 'entry_fill',
|
||||||
|
exitFill = 'exit_fill',
|
||||||
|
newCandle = 'newCandle',
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user