mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-22 19:15:15 +00:00
improve WS message typing
This commit is contained in:
parent
be90f855a7
commit
e9478bfaab
|
@ -39,7 +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';
|
||||
import { FTWsMessage, FtWsMessageTypes } from '@/types/wsMessageTypes';
|
||||
|
||||
export function createBotSubStore(botId: string, botName: string) {
|
||||
const userService = useUserService(botId);
|
||||
|
@ -811,7 +811,7 @@ export function createBotSubStore(botId: string, botName: string) {
|
|||
}
|
||||
},
|
||||
_handleWebsocketMessage(ws, event: MessageEvent<any>) {
|
||||
const msg = JSON.parse(event.data);
|
||||
const msg: FTWsMessage = JSON.parse(event.data);
|
||||
switch (msg.type) {
|
||||
case FtWsMessageTypes.whitelist:
|
||||
this.whitelist = msg.data;
|
||||
|
@ -824,9 +824,13 @@ export function createBotSubStore(botId: string, botName: string) {
|
|||
console.log('exitFill', msg);
|
||||
showAlert(`Exit fill for ${msg.pair} at ${msg.open_rate}`, 'success');
|
||||
break;
|
||||
case FtWsMessageTypes.newCandle:
|
||||
console.log('exitFill', msg);
|
||||
showAlert(`New Candle`, 'success');
|
||||
break;
|
||||
default:
|
||||
// Unhandled events ...
|
||||
console.log(`Received event ${msg.type}`);
|
||||
console.log(`Received event ${(msg as any).type}`);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -4,3 +4,38 @@ export enum FtWsMessageTypes {
|
|||
exitFill = 'exit_fill',
|
||||
newCandle = 'newCandle',
|
||||
}
|
||||
|
||||
export interface FtBaseWsMessage {
|
||||
type: FtWsMessageTypes;
|
||||
}
|
||||
|
||||
export interface FtWhitelistMessage extends FtBaseWsMessage {
|
||||
type: FtWsMessageTypes.whitelist;
|
||||
data: string[];
|
||||
}
|
||||
|
||||
export interface FtEntryFillMessage extends FtBaseWsMessage {
|
||||
type: FtWsMessageTypes.entryFill;
|
||||
pair: string;
|
||||
open_rate: number;
|
||||
amount: number;
|
||||
// ...
|
||||
}
|
||||
export interface FtExitFillMessage extends FtBaseWsMessage {
|
||||
type: FtWsMessageTypes.exitFill;
|
||||
pair: string;
|
||||
open_rate: number;
|
||||
amount: number;
|
||||
// ...
|
||||
}
|
||||
|
||||
export interface FtNewCandleMessage extends FtBaseWsMessage {
|
||||
type: FtWsMessageTypes.newCandle;
|
||||
// ...
|
||||
}
|
||||
|
||||
export type FTWsMessage =
|
||||
| FtWhitelistMessage
|
||||
| FtEntryFillMessage
|
||||
| FtExitFillMessage
|
||||
| FtNewCandleMessage;
|
||||
|
|
Loading…
Reference in New Issue
Block a user