From 475b9edf8042bc5ee1547c5160733b4f3f07f3ea Mon Sep 17 00:00:00 2001 From: Lu Ken Date: Mon, 23 Dec 2024 22:59:39 +0800 Subject: [PATCH] enable the asset select function (#10) Signed-off-by: Lu Ken --- src/GenTradeAgent/src/main/data.ts | 27 +++++++-- src/GenTradeAgent/src/main/index.ts | 2 +- .../src/components/TradingChatAgent.vue | 12 ++-- .../src/components/TradingDashboard.vue | 43 ++++++++++---- .../renderer/src/components/TradingMain.vue | 57 +++++++++++++++---- src/GenTradeAgent/src/renderer/src/const.ts | 17 ++++++ src/GenTradeAgent/src/renderer/src/main.ts | 3 +- 7 files changed, 126 insertions(+), 35 deletions(-) create mode 100644 src/GenTradeAgent/src/renderer/src/const.ts diff --git a/src/GenTradeAgent/src/main/data.ts b/src/GenTradeAgent/src/main/data.ts index 0e32374..1061112 100644 --- a/src/GenTradeAgent/src/main/data.ts +++ b/src/GenTradeAgent/src/main/data.ts @@ -4,7 +4,6 @@ import { readFileSync } from 'fs' import { join } from 'path' import { parse } from 'csv-parse' - interface ohlcvData { time: number | string open: number | string @@ -17,7 +16,7 @@ export class LocalStore { private rootDir: string private cryptoAssets: object | null = null private stockUSAssets: object | null = null - private ohlcBTC_1h: ohlcvData[] = [] + private ohlcDB: { [assetName: string]: { [timeFrame: string]: ohlcvData[] } } = {} public constructor(cacheDir: string) { this.rootDir = cacheDir } @@ -70,8 +69,24 @@ export class LocalStore { public init(): boolean { this.cryptoAssets = this.loadJsonData(join(this.rootDir, 'Binance/crypto_assets.json')) this.stockUSAssets = this.loadJsonData(join(this.rootDir, 'StockUS/stock_us_ticker.json')) - this.loadCsvData(join(this.rootDir, 'Binance/btc_usdt-1hour.csv'), this.ohlcBTC_1h) - // setTimeout(() => console.log(this.ohlcBTC_1h), 200) + const arr = ['btc', 'msft'] + arr.forEach((item: string) => { + this.ohlcDB[item] = { + '1h': [], + '1d': [], + '1w': [], + '1M': [] + } + }) + this.loadCsvData(join(this.rootDir, 'Binance/btc_usdt-1hour.csv'), this.ohlcDB['btc']['1h']) + this.loadCsvData(join(this.rootDir, 'Binance/btc_usdt-1mon.csv'), this.ohlcDB['btc']['1M']) + this.loadCsvData(join(this.rootDir, 'Binance/btc_usdt-1day.csv'), this.ohlcDB['btc']['1d']) + this.loadCsvData(join(this.rootDir, 'Binance/btc_usdt-1week.csv'), this.ohlcDB['btc']['1w']) + + this.loadCsvData(join(this.rootDir, 'StockUS/msft-1hour.csv'), this.ohlcDB['msft']['1h']) + this.loadCsvData(join(this.rootDir, 'StockUS/msft-1mon.csv'), this.ohlcDB['msft']['1M']) + this.loadCsvData(join(this.rootDir, 'StockUS/msft-1day.csv'), this.ohlcDB['msft']['1d']) + this.loadCsvData(join(this.rootDir, 'StockUS/msft-1week.csv'), this.ohlcDB['msft']['1w']) return true } @@ -83,7 +98,7 @@ export class LocalStore { return this.stockUSAssets } - public getOhlcvBTC(): ohlcvData[] { - return this.ohlcBTC_1h + public getOhlcvDB(): { [assetName: string]: { [timeFrame: string]: ohlcvData[] } } { + return this.ohlcDB } } diff --git a/src/GenTradeAgent/src/main/index.ts b/src/GenTradeAgent/src/main/index.ts index f0da41f..8403fd9 100644 --- a/src/GenTradeAgent/src/main/index.ts +++ b/src/GenTradeAgent/src/main/index.ts @@ -54,7 +54,7 @@ app.whenReady().then(() => { ipcMain.on('loadCache', () => store.init()) ipcMain.handle('getCryptoAssets', () => store.getCryptoAssets()) ipcMain.handle('getStockUSAssets', () => store.getStockUSAssets()) - ipcMain.handle('getOhlcvBTC', () => store.getOhlcvBTC()) + ipcMain.handle('getOhlcvDB', () => store.getOhlcvDB()) createWindow() diff --git a/src/GenTradeAgent/src/renderer/src/components/TradingChatAgent.vue b/src/GenTradeAgent/src/renderer/src/components/TradingChatAgent.vue index e0251d8..143e130 100644 --- a/src/GenTradeAgent/src/renderer/src/components/TradingChatAgent.vue +++ b/src/GenTradeAgent/src/renderer/src/components/TradingChatAgent.vue @@ -38,12 +38,12 @@ adoption and acceptance of digital assets worldwide.`) const prompt = ref('') onMounted(() => { - window.electron.ipcRenderer.invoke('getCryptoAssets').then((response) => { - //console.log(response) - console.log(Object.keys(response)) - //placeholder_output.value = Object.keys(response).toString - //placeholder_output.value = JSON.stringify(response) - }) + // window.electron.ipcRenderer.invoke('getCryptoAssets').then((response) => { + // //console.log(response) + // //console.log(Object.keys(response)) + // //placeholder_output.value = Object.keys(response).toString + // //placeholder_output.value = JSON.stringify(response) + // }) }) const handleInput = (v: string) => { diff --git a/src/GenTradeAgent/src/renderer/src/components/TradingDashboard.vue b/src/GenTradeAgent/src/renderer/src/components/TradingDashboard.vue index d2534df..c7f11bc 100644 --- a/src/GenTradeAgent/src/renderer/src/components/TradingDashboard.vue +++ b/src/GenTradeAgent/src/renderer/src/components/TradingDashboard.vue @@ -6,11 +6,40 @@