Update closing trade date on SL or TP
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import React, {useEffect, useState} from 'react'
|
||||
import type {ClosePositionRequest, Position, UserStrategyDetailsViewModel} from '../../../generated/ManagingApi'
|
||||
import type {
|
||||
ClosePositionRequest,
|
||||
PositionViewModel,
|
||||
UserStrategyDetailsViewModel
|
||||
} from '../../../generated/ManagingApi'
|
||||
import {BotClient, DataClient} from '../../../generated/ManagingApi'
|
||||
import useApiUrlStore from '../../../app/store/apiStore'
|
||||
import Modal from '../Modal/Modal'
|
||||
@@ -9,6 +13,7 @@ interface TradesModalProps {
|
||||
showModal: boolean
|
||||
agentName: string | null
|
||||
strategyName: string | null
|
||||
botIdentifier: string | undefined
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
@@ -16,6 +21,7 @@ const TradesModal: React.FC<TradesModalProps> = ({
|
||||
showModal,
|
||||
strategyName,
|
||||
agentName,
|
||||
botIdentifier,
|
||||
onClose,
|
||||
}) => {
|
||||
const { apiUrl } = useApiUrlStore()
|
||||
@@ -49,7 +55,7 @@ const TradesModal: React.FC<TradesModalProps> = ({
|
||||
}
|
||||
}
|
||||
|
||||
const closePosition = async (position: Position) => {
|
||||
const closePosition = async (position: PositionViewModel) => {
|
||||
if (!agentName) return
|
||||
|
||||
try {
|
||||
@@ -60,7 +66,7 @@ const TradesModal: React.FC<TradesModalProps> = ({
|
||||
// Use BotClient instead of fetch
|
||||
const botClient = new BotClient({}, apiUrl)
|
||||
const request: ClosePositionRequest = {
|
||||
identifier: position.initiatorIdentifier,
|
||||
identifier: botIdentifier,
|
||||
positionId: position.identifier
|
||||
}
|
||||
|
||||
@@ -115,7 +121,7 @@ const TradesModal: React.FC<TradesModalProps> = ({
|
||||
</thead>
|
||||
<tbody>
|
||||
{strategyData.positions && strategyData.positions.length > 0 ? (
|
||||
strategyData.positions.map((position: Position) => (
|
||||
strategyData.positions.map((position: PositionViewModel) => (
|
||||
<tr key={position.identifier}>
|
||||
<td>{new Date(position.date).toLocaleString()}</td>
|
||||
<td className={position.originDirection === 'Long' ? 'text-success' : 'text-error'}>
|
||||
|
||||
@@ -72,7 +72,7 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
||||
const [showManualPositionModal, setShowManualPositionModal] = useState(false)
|
||||
const [selectedBotForManualPosition, setSelectedBotForManualPosition] = useState<string | null>(null)
|
||||
const [showTradesModal, setShowTradesModal] = useState(false)
|
||||
const [selectedBotForTrades, setSelectedBotForTrades] = useState<{ name: string; agentName: string } | null>(null)
|
||||
const [selectedBotForTrades, setSelectedBotForTrades] = useState<{ name: string; agentName: string; identifier: string } | null>(null)
|
||||
const [showBotConfigModal, setShowBotConfigModal] = useState(false)
|
||||
const [selectedBotForUpdate, setSelectedBotForUpdate] = useState<{
|
||||
identifier: string
|
||||
@@ -144,10 +144,10 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
||||
)
|
||||
}
|
||||
|
||||
function getTradesBadge(name: string, agentName: string) {
|
||||
function getTradesBadge(name: string, agentName: string, botIdentifier: string) {
|
||||
const classes = baseBadgeClass() + ' bg-secondary'
|
||||
return (
|
||||
<button className={classes} onClick={() => openTradesModal(name, agentName)}>
|
||||
<button className={classes} onClick={() => openTradesModal(name, agentName, botIdentifier)}>
|
||||
<p className="text-primary-content flex">
|
||||
<ChartBarIcon width={15}></ChartBarIcon>
|
||||
</p>
|
||||
@@ -160,8 +160,8 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
||||
setShowManualPositionModal(true)
|
||||
}
|
||||
|
||||
function openTradesModal(name: string, agentName: string) {
|
||||
setSelectedBotForTrades({ name: name, agentName })
|
||||
function openTradesModal(name: string, agentName: string, botIdentifier: string) {
|
||||
setSelectedBotForTrades({ name: name, agentName, identifier: botIdentifier })
|
||||
setShowTradesModal(true)
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
||||
<div className={baseBadgeClass(true)}>
|
||||
PNL {bot.profitAndLoss.toFixed(2).toString()} $
|
||||
</div>
|
||||
{getTradesBadge(bot.name, bot.agentName)}
|
||||
{getTradesBadge(bot.name, bot.agentName, bot.identifier)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -337,6 +337,7 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
||||
showModal={showTradesModal}
|
||||
strategyName={selectedBotForTrades?.name ?? null}
|
||||
agentName={selectedBotForTrades?.agentName ?? null}
|
||||
botIdentifier={selectedBotForTrades?.identifier ?? undefined}
|
||||
onClose={() => {
|
||||
setShowTradesModal(false)
|
||||
setSelectedBotForTrades(null)
|
||||
|
||||
Reference in New Issue
Block a user