Merge pull request #194 from blockworks-foundation/clarkeni/export_trades
Add full trade history export trades history tab.
This commit is contained in:
commit
a23687d415
|
@ -25,6 +25,8 @@ import { notify } from '../../utils/notifications'
|
|||
import Button from '../Button'
|
||||
import Loading from '../Loading'
|
||||
import { fetchHourlyPerformanceStats } from './AccountOverview'
|
||||
import Tooltip from '../Tooltip'
|
||||
import { InformationCircleIcon } from '@heroicons/react/outline'
|
||||
|
||||
const historyViews = [
|
||||
{ label: 'Trades', key: 'Trades' },
|
||||
|
@ -87,54 +89,20 @@ export default function AccountHistory() {
|
|||
}
|
||||
|
||||
const exportHistoryToCSV = () => {
|
||||
let dataToExport
|
||||
let headers
|
||||
const dataToExport = history
|
||||
.filter((val) => val.activity_type == view)
|
||||
.map((row) => {
|
||||
row = row.activity_details
|
||||
const timestamp = new Date(row.block_datetime)
|
||||
|
||||
if (view == 'Trades') {
|
||||
// filter liquidations from history
|
||||
const tradeHistory = useMangoStore
|
||||
.getState()
|
||||
.tradeHistory.parsed.filter((t) => !('liqor' in t))
|
||||
|
||||
dataToExport = tradeHistory.map((trade) => {
|
||||
const timestamp = new Date(trade.loadTimestamp)
|
||||
return {
|
||||
asset: trade.marketName,
|
||||
orderType: trade.side.toUpperCase(),
|
||||
quantity: trade.size,
|
||||
price: trade.price,
|
||||
value: trade.value,
|
||||
liquidity: trade.liquidity,
|
||||
fee: trade.feeCost,
|
||||
date: `${timestamp.toLocaleDateString()} ${timestamp.toLocaleTimeString()}`,
|
||||
asset: row.symbol,
|
||||
quantity: row.quantity,
|
||||
value: row.usd_equivalent,
|
||||
}
|
||||
})
|
||||
headers = [
|
||||
'Market',
|
||||
'Side',
|
||||
'Size',
|
||||
'Price',
|
||||
'Value',
|
||||
'Liquidity',
|
||||
'Fee',
|
||||
'Approx. Time',
|
||||
]
|
||||
} else {
|
||||
dataToExport = history
|
||||
.filter((val) => val.activity_type == view)
|
||||
.map((row) => {
|
||||
row = row.activity_details
|
||||
const timestamp = new Date(row.block_datetime)
|
||||
|
||||
return {
|
||||
date: `${timestamp.toLocaleDateString()} ${timestamp.toLocaleTimeString()}`,
|
||||
asset: row.symbol,
|
||||
quantity: row.quantity,
|
||||
value: row.usd_equivalent,
|
||||
}
|
||||
})
|
||||
headers = ['Timestamp', 'Asset', 'Quantity', 'Value']
|
||||
}
|
||||
const headers = ['Timestamp', 'Asset', 'Quantity', 'Value']
|
||||
|
||||
if (dataToExport.length == 0) {
|
||||
notify({
|
||||
|
@ -194,31 +162,54 @@ export default function AccountHistory() {
|
|||
{t('use-explorer-three')}
|
||||
</div>
|
||||
</div>
|
||||
{view !== 'Trades' ? (
|
||||
<Button
|
||||
className={`flex h-8 items-center justify-center whitespace-nowrap pt-0 pb-0 pl-3 pr-3 text-xs`}
|
||||
onClick={exportHistoryToCSV}
|
||||
>
|
||||
<div className={`flex items-center`}>
|
||||
<SaveIcon className={`mr-1.5 h-4 w-4`} />
|
||||
{t('export-data')}
|
||||
</div>
|
||||
</Button>
|
||||
) : canWithdraw ? (
|
||||
<Button
|
||||
className={`flex h-8 items-center justify-center whitespace-nowrap pt-0 pb-0 pl-3 pr-3 text-xs`}
|
||||
onClick={exportPerformanceDataToCSV}
|
||||
>
|
||||
{loadExportData ? (
|
||||
<Loading />
|
||||
) : (
|
||||
<div className="flex space-x-3">
|
||||
{view === 'Trades' && canWithdraw ? (
|
||||
<Button
|
||||
className={`flex h-8 items-center justify-center whitespace-nowrap pt-0 pb-0 pl-3 pr-3 text-xs`}
|
||||
onClick={exportPerformanceDataToCSV}
|
||||
>
|
||||
{loadExportData ? (
|
||||
<Loading />
|
||||
) : (
|
||||
<div className={`flex items-center`}>
|
||||
<SaveIcon className={`mr-1.5 h-4 w-4`} />
|
||||
{t('export-pnl-csv')}
|
||||
</div>
|
||||
)}
|
||||
</Button>
|
||||
) : null}
|
||||
{view !== 'Trades' ? (
|
||||
<Button
|
||||
className={`flex h-8 items-center justify-center whitespace-nowrap pt-0 pb-0 pl-3 pr-3 text-xs`}
|
||||
onClick={exportHistoryToCSV}
|
||||
>
|
||||
<div className={`flex items-center`}>
|
||||
<SaveIcon className={`mr-1.5 h-4 w-4`} />
|
||||
{t('export-pnl-csv')}
|
||||
{t('export-data')}
|
||||
</div>
|
||||
)}
|
||||
</Button>
|
||||
) : null}
|
||||
</Button>
|
||||
) : canWithdraw ? (
|
||||
<div className={`flex items-center`}>
|
||||
<a
|
||||
className={`default-transition flex h-8 items-center justify-center whitespace-nowrap rounded-full bg-th-bkg-button pt-0 pb-0 pl-3 pr-3 text-xs font-bold text-th-fgd-1 hover:text-th-fgd-1 hover:brightness-[1.1]`}
|
||||
href={`https://event-history-api.herokuapp.com/all_trades_csv?mango_account=${mangoAccountPk}&open_orders=${mangoAccount.spotOpenOrders
|
||||
.filter(
|
||||
(e) => e.toString() !== '11111111111111111111111111111111'
|
||||
)
|
||||
.join(',')}`}
|
||||
download
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<SaveIcon className={`mr-1.5 h-4 w-4`} />
|
||||
Export Trades CSV
|
||||
</a>
|
||||
<Tooltip content={t('trade-export-disclaimer')}>
|
||||
<InformationCircleIcon className="ml-1.5 h-5 w-5 cursor-help text-th-fgd-3" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<ViewContent view={view} history={history} />
|
||||
</>
|
||||
|
|
|
@ -393,6 +393,7 @@
|
|||
"total-srm": "Total SRM in Mango",
|
||||
"totals": "Totals",
|
||||
"trade": "Trade",
|
||||
"trade-export-disclaimer": "Due to the nature of how trades are processed, it is not possible to guarantee that all trades will be exported. However, a best effort approach has been taken, combining several independent sources to reduce the likelihood of missing trades.",
|
||||
"trade-history": "Trade History",
|
||||
"trades": "Trades",
|
||||
"trades-history": "Trade History",
|
||||
|
|
|
@ -392,6 +392,7 @@
|
|||
"trade": "Comercio",
|
||||
"trade-history": "Historial comercial",
|
||||
"trades": "Trades",
|
||||
"trade-export-disclaimer": "Due to the nature of how trades are processed, it is not possible to guarantee that all trades will be exported. However, a best effort approach has been taken, combining several independent sources to reduce the likelihood of missing trades.",
|
||||
"trades-history": "Historial comercial",
|
||||
"transaction-sent": "Transacción enviada",
|
||||
"trigger-price": "Precio de activación",
|
||||
|
|
|
@ -392,6 +392,7 @@
|
|||
"trade": "交易",
|
||||
"trade-history": "交易纪录",
|
||||
"trades": "成交",
|
||||
"trade-export-disclaimer": "Due to the nature of how trades are processed, it is not possible to guarantee that all trades will be exported. However, a best effort approach has been taken, combining several independent sources to reduce the likelihood of missing trades.",
|
||||
"trades-history": "交易纪录",
|
||||
"transaction-sent": "已下订单",
|
||||
"trigger-price": "触发价格",
|
||||
|
|
|
@ -392,6 +392,7 @@
|
|||
"trade": "交易",
|
||||
"trade-history": "交易紀錄",
|
||||
"trades": "成交",
|
||||
"trade-export-disclaimer": "Due to the nature of how trades are processed, it is not possible to guarantee that all trades will be exported. However, a best effort approach has been taken, combining several independent sources to reduce the likelihood of missing trades.",
|
||||
"trades-history": "交易紀錄",
|
||||
"transaction-sent": "已下訂單",
|
||||
"trigger-price": "觸發價格",
|
||||
|
|
Loading…
Reference in New Issue