Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified doc/ui-mock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/GenTradeAgent/src/renderer/src/components/TradingDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,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()
Expand Down
26 changes: 26 additions & 0 deletions src/GenTradeAgent/src/renderer/src/components/TradingMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ store.watch(
)

const handleUpdateCurrentAsset = (value: string) => {
console.log('handleUpdateCurrentAsset:' + value)
store.commit('updateCurrentAsset', value)
}

Expand All @@ -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)
}
}
)
</script>

<style lang="scss" scoped>
Expand Down
38 changes: 38 additions & 0 deletions src/GenTradeAgent/src/renderer/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Store } from 'vuex'

class AgentServer {
serverAddress: string = 'http://47.100.216.225:8000/api/v1'
//serverAddress: string = 'http://127.0.0.1:8000/api/v1'
apiKey: string = 'e54d4431-5dab-474e-b71a-0db1fcb9e659'
tzName: string = ''
tzOffset: number = 0
Expand Down Expand Up @@ -55,6 +56,43 @@ class AgentServer {
console.log(err)
})
}

get_assets(callback: (retval) => void) {
const address = this.serverAddress + '/public/assets/'
axios
.get(address)
.then((response) => {
console.log(response)
callback(response.data)
})
.catch((err: AxiosError) => {
console.log(err)
})
}

get_ohlcv(assetName: string, interval: string, callback: (data) => void) {
const address = this.serverAddress + '/public/asset/fetch_ohlcv/'
console.log('get_ohlcv: ' + assetName)
axios.interceptors.request.use((request) => {
console.log('Starting Request', JSON.stringify(request, null, 2))
return request
})
axios
.get(address, {
params: {
assetname: assetName,
interval: interval,
limit: 200
}
})
.then((response) => {
console.log(response)
callback(response.data)
})
.catch((err: AxiosError) => {
console.log(err)
})
}
}

export const agentServer = new AgentServer()
24 changes: 22 additions & 2 deletions src/GenTradeAgent/src/renderer/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { InjectionKey } from 'vue'
import { createStore, Store, useStore as baseUseStore } from 'vuex'
import { agentServer } from './server'

export interface ohlcvData {
time: number
Expand Down Expand Up @@ -58,19 +59,38 @@ export const store = createStore<IState>({
},
updateOhlcvDB(state, newOhlcvDB) {
console.log('updateOhlcvDB')
console.log(newOhlcvDB)
state.ohlcvDB = newOhlcvDB
state.currentAsset = Object.keys(newOhlcvDB)[0]
state.currentOhlcv = state.ohlcvDB[state.currentAsset][state.currentInterval]
},
updateCurrentAsset(state, newAsset: string) {
console.log('updateCurrentAsset')
state.currentAsset = newAsset
state.currentOhlcv = state.ohlcvDB[state.currentAsset][state.currentInterval]
if (state.currentAsset in state.ohlcvDB) {
state.currentOhlcv = state.ohlcvDB[state.currentAsset][state.currentInterval]
}
//console.log(state.c)
const callback = ((data) => {
console.log(data)
state.currentOhlcv = data
console.log(state.currentOhlcv)
})
agentServer.get_ohlcv(newAsset, state.currentInterval, callback)
},
updateCurrentInterval(state, newInterval: string) {
console.log('updateCurrentInterval')
state.currentInterval = newInterval
state.currentOhlcv = state.ohlcvDB[state.currentAsset][state.currentInterval]
if (state.currentAsset in state.ohlcvDB) {
state.currentOhlcv = state.ohlcvDB[state.currentAsset][state.currentInterval]
console.log(state.currentOhlcv)
console.log("222")
}
const callback = ((data) => {
console.log(data)
state.currentOhlcv = data
})
agentServer.get_ohlcv(state.currentAsset, state.currentInterval, callback)
},
updateNotification(state, notifyMessage) {
state.notifyMessage = notifyMessage
Expand Down
Loading