Fix healthcheck and tradingbot positions

This commit is contained in:
2025-04-25 15:50:12 +07:00
parent 5844d89175
commit ea1a25e699
4 changed files with 291 additions and 316 deletions

View File

@@ -411,6 +411,8 @@ public class TradingBot : Bot, ITradingBot
{ {
Logger.LogInformation( Logger.LogInformation(
$"Position {signal.Identifier} don't need to be update. Position still opened"); $"Position {signal.Identifier} don't need to be update. Position still opened");
await SetPositionStatus(signal.Identifier, PositionStatus.Filled);
} }
} }
@@ -445,6 +447,10 @@ public class TradingBot : Bot, ITradingBot
{ {
Logger.LogInformation( Logger.LogInformation(
$"Position {signal.Identifier} don't need to be update. Position still opened"); $"Position {signal.Identifier} don't need to be update. Position still opened");
position.Status = PositionStatus.Filled;
await SetPositionStatus(signal.Identifier, PositionStatus.Filled);
} }
} }
} }

View File

@@ -1,12 +1,6 @@
import {ArrowDownIcon, ArrowUpIcon} from '@heroicons/react/solid' import {ArrowDownIcon, ArrowUpIcon} from '@heroicons/react/solid'
import React from 'react' import React from 'react'
import { import {useExpanded, useFilters, usePagination, useSortBy, useTable,} from 'react-table'
useTable,
usePagination,
useSortBy,
useFilters,
useExpanded,
} from 'react-table'
import type {TableInstanceWithHooks} from '../../../global/type' import type {TableInstanceWithHooks} from '../../../global/type'
@@ -31,7 +25,7 @@ export default function Table({
columns, columns,
data, data,
renderRowSubCompontent, renderRowSubCompontent,
showPagination, showPagination = true,
hiddenColumns, hiddenColumns,
showTotal = false, showTotal = false,
}: any) { }: any) {
@@ -49,10 +43,7 @@ export default function Table({
headerGroups, headerGroups,
prepareRow, prepareRow,
visibleColumns, visibleColumns,
page, // Instead of using 'rows', we'll use page, page,
// which has only the rows for the active page
// The rest of these things are super handy, too ;)
canPreviousPage, canPreviousPage,
canNextPage, canNextPage,
pageOptions, pageOptions,

View File

@@ -1,25 +1,14 @@
import { import {ArrowDownIcon, ArrowUpIcon, ChevronDownIcon, ChevronRightIcon, PlayIcon,} from '@heroicons/react/solid'
ArrowDownIcon,
ArrowUpIcon,
ChevronDownIcon,
ChevronRightIcon,
PlayIcon,
} from '@heroicons/react/solid'
import React, {useEffect, useState} from 'react' import React, {useEffect, useState} from 'react'
import {Hub} from '../../../app/providers/Hubs' import {Hub} from '../../../app/providers/Hubs'
import useApiUrlStore from '../../../app/store/apiStore' import useApiUrlStore from '../../../app/store/apiStore'
import type {Account, TradingBot} from '../../../generated/ManagingApi' import type {Account, TradingBot} from '../../../generated/ManagingApi'
import { import {AccountClient, BotClient, TradeDirection, TradeStatus,} from '../../../generated/ManagingApi'
AccountClient,
BotClient,
TradeDirection,
TradeStatus,
} from '../../../generated/ManagingApi'
import {SelectColumnFilter, Table} from '../../mollecules' import {SelectColumnFilter, Table} from '../../mollecules'
import BacktestRowDetails from '../Backtest/backtestRowDetails'
import StatusBadge from '../StatusBadge/StatusBadge' import StatusBadge from '../StatusBadge/StatusBadge'
import Summary from '../Trading/Summary' import Summary from '../Trading/Summary'
import BotRowDetails from './botRowDetails'
export default function ActiveBots() { export default function ActiveBots() {
const [bots, setBots] = useState<TradingBot[]>([]) const [bots, setBots] = useState<TradingBot[]>([])
@@ -63,10 +52,14 @@ export default function ActiveBots() {
Header: 'Status', Header: 'Status',
accessor: 'status', accessor: 'status',
disableFilters: true, disableFilters: true,
sortType: 'basic', disableSortBy: true,
search: false,
}, },
{ {
accessor: 'isForWatchingOnly', accessor: 'isForWatchingOnly',
disableFilters: true,
disableSortBy: true,
search: false,
}, },
{ {
Filter: SelectColumnFilter, Filter: SelectColumnFilter,
@@ -185,10 +178,9 @@ export default function ActiveBots() {
const renderRowSubComponent = React.useCallback( const renderRowSubComponent = React.useCallback(
({ row }: any) => ( ({ row }: any) => (
<> <>
<BacktestRowDetails <BotRowDetails
candles={row.original.candles} bot={row.original}
positions={row.original.positions} ></BotRowDetails>
></BacktestRowDetails>
</> </>
), ),
[] []
@@ -204,6 +196,7 @@ export default function ActiveBots() {
columns={columns} columns={columns}
data={bots} data={bots}
renderRowSubCompontent={renderRowSubComponent} renderRowSubCompontent={renderRowSubComponent}
hiddenColumns={['isForWatchingOnly']}
/> />
</div> </div>
</> </>

View File

@@ -1,5 +1,5 @@
import React, {useEffect, useState} from 'react' import React from 'react'
import {useQuery} from '@tanstack/react-query'
import useApiUrlStore from '../../../app/store/apiStore' import useApiUrlStore from '../../../app/store/apiStore'
import {Table} from '../../../components/mollecules' import {Table} from '../../../components/mollecules'
@@ -37,44 +37,30 @@ interface Web3ProxyHealthDetail {
const HealthChecks: React.FC = () => { const HealthChecks: React.FC = () => {
const {apiUrl, workerUrl} = useApiUrlStore() const {apiUrl, workerUrl} = useApiUrlStore()
const [apiHealth, setApiHealth] = useState<HealthCheckResponse | null>(null)
const [workerHealth, setWorkerHealth] = useState<HealthCheckResponse | null>(null)
const [web3ProxyHealth, setWeb3ProxyHealth] = useState<HealthCheckResponse | null>(null)
const [isLoading, setIsLoading] = useState(true)
useEffect(() => { // Use TanStack Query for API health check
const fetchHealthChecks = async () => { const {data: apiHealth, isLoading: isLoadingApi} = useQuery({
setIsLoading(true) queryKey: ['health', 'api'],
try { queryFn: async () => {
// Fetch API health check const response = await fetch(`${apiUrl}/health`)
const apiResponse = await fetch(`${apiUrl}/health`) if (!response.ok) throw new Error('Failed to fetch API health')
if (apiResponse.ok) { return response.json() as Promise<HealthCheckResponse>
const data = await apiResponse.json()
setApiHealth(data)
} }
})
// Fetch Worker health check // Use TanStack Query for Worker health check
const workerResponse = await fetch(`${workerUrl}/health`) const {data: workerHealth, isLoading: isLoadingWorker} = useQuery({
if (workerResponse.ok) { queryKey: ['health', 'worker'],
const data = await workerResponse.json() queryFn: async () => {
setWorkerHealth(data) const response = await fetch(`${workerUrl}/health`)
if (!response.ok) throw new Error('Failed to fetch Worker health')
return response.json() as Promise<HealthCheckResponse>
} }
})
// Fetch Web3Proxy health check - use the dedicated endpoint we created
const web3Response = await fetch(`${apiUrl}/health/web3proxy`)
if (web3Response.ok) {
const data = await web3Response.json()
setWeb3ProxyHealth(data)
}
} catch (error) {
console.error('Error fetching health checks:', error)
} finally {
setIsLoading(false)
}
}
fetchHealthChecks() // Determine overall loading state
}, [apiUrl, workerUrl]) const isLoading = isLoadingApi || isLoadingWorker
// Helper function to prepare table data from health response // Helper function to prepare table data from health response
const prepareHealthData = ( const prepareHealthData = (
@@ -219,9 +205,8 @@ const HealthChecks: React.FC = () => {
// Combine all health check data for display // Combine all health check data for display
const healthData = [ const healthData = [
...prepareHealthData('Managing API', apiHealth), ...prepareHealthData('Managing API', apiHealth || null),
...prepareHealthData('Managing Worker', workerHealth), ...prepareHealthData('Managing Worker', workerHealth || null),
...prepareHealthData('Web3 Proxy', web3ProxyHealth),
] ]
// Define columns for the table // Define columns for the table
@@ -305,7 +290,7 @@ const HealthChecks: React.FC = () => {
<Table <Table
columns={columns} columns={columns}
data={healthData} data={healthData}
showPagination={false} showPagination={true}
/> />
)} )}
</div> </div>