From a9965589dcfe8cfe3f483b916fcb6d2f3b6b8f2f Mon Sep 17 00:00:00 2001 From: Lu Ken Date: Tue, 31 Dec 2024 12:15:48 +0800 Subject: [PATCH 1/2] test with agent server Signed-off-by: Lu Ken --- .../src/components/TradingDashboard.vue | 21 ++++++++++ .../renderer/src/components/TradingMain.vue | 26 +++++++++++++ src/GenTradeAgent/src/renderer/src/server.ts | 38 +++++++++++++++++++ src/GenTradeAgent/src/renderer/src/store.ts | 24 +++++++++++- 4 files changed, 107 insertions(+), 2 deletions(-) diff --git a/src/GenTradeAgent/src/renderer/src/components/TradingDashboard.vue b/src/GenTradeAgent/src/renderer/src/components/TradingDashboard.vue index d0bf404..b042fff 100644 --- a/src/GenTradeAgent/src/renderer/src/components/TradingDashboard.vue +++ b/src/GenTradeAgent/src/renderer/src/components/TradingDashboard.vue @@ -25,10 +25,13 @@ import { onMounted, ref, nextTick } from 'vue' import { createChart, IChartApi, TickMarkType } from 'lightweight-charts' import { useStore } from '@renderer/store' import { NDropdown } from 'naive-ui' +import { agentServer } from '@renderer/server' let chartObj: IChartApi | null = null let chartElement: HTMLElement | null = null let candlestickSeries +let isConnect = false +let serverAsset = {} const contextMenuOptions = [ { @@ -69,10 +72,28 @@ const store = useStore() store.watch( (state) => state.currentOhlcv, (value) => { + console.log('change ohlcv') + console.log(value) candlestickSeries.setData(value) } ) +store.watch( + (state) => state.currentAsset, + () => { + console.log('change Asset') + candlestickSeries.setData(store.state.currentOhlcv) + } +) + +store.watch( + (state) => state.currentInterval, + () => { + console.log('change Interval') + candlestickSeries.setData(store.state.currentOhlcv) + } +) + const resizeHandler = () => { if (chartElement) { const dimensions = chartElement.getBoundingClientRect() diff --git a/src/GenTradeAgent/src/renderer/src/components/TradingMain.vue b/src/GenTradeAgent/src/renderer/src/components/TradingMain.vue index ca4237f..332d4a4 100644 --- a/src/GenTradeAgent/src/renderer/src/components/TradingMain.vue +++ b/src/GenTradeAgent/src/renderer/src/components/TradingMain.vue @@ -97,6 +97,7 @@ store.watch( ) const handleUpdateCurrentAsset = (value: string) => { + console.log('handleUpdateCurrentAsset:' + value) store.commit('updateCurrentAsset', value) } @@ -110,6 +111,31 @@ const handlerPingServer = () => { setTimeout(handlerPingServer, agentServer.pingInterval) } handlerPingServer() + +let isConnect = false +const onAssetFromServer = (retval) => { + optionsAsset.value.length = 0 + Object.keys(retval).forEach((item) => { + optionsAsset.value.push({ + label: item, + value: item + }) + }) +} + +store.watch( + (state) => state.serverLatency, + (value) => { + if (isConnect && value == -1) { + isConnect = false + } + + if (!isConnect && value != -1) { + isConnect = true + agentServer.get_assets(onAssetFromServer) + } + } +)