Skip to content

feat: export trading history to CSV#131

Open
subhajitlucky wants to merge 1 commit into
capofficial:mainfrom
subhajitlucky:export-trading-history-14
Open

feat: export trading history to CSV#131
subhajitlucky wants to merge 1 commit into
capofficial:mainfrom
subhajitlucky:export-trading-history-14

Conversation

@subhajitlucky
Copy link
Copy Markdown

Fixes #14.\n\n## Summary\n- Add optional from/to date selectors above the History table.\n- Fetch all matching history pages using the existing status filter and timestamp range.\n- Generate and download a CSV report with core trading-history fields.\n- Use a browser Worker blob for CSV escaping/joining so large exports do not block the UI formatting step.\n\n## Verification\n- npm run build\n- git diff --check\n\nNote: build passes with the repository's existing Svelte/Rollup warnings.

Copilot AI review requested due to automatic review settings May 12, 2026 07:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a CSV export feature for the Trading History view, including optional date range selection and background CSV generation to keep the UI responsive.

Changes:

  • Added an export toolbar (From/To date inputs + export button) above the History table and implemented CSV download flow.
  • Added history API helpers to fetch paginated history and aggregate pages for export.
  • Introduced a new download SVG icon for the export button.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 7 comments.

File Description
src/components/trade/account/History.svelte Adds date range selectors, export button, worker-based CSV building, and download logic.
src/api/history.js Refactors request URL building, adds a paged fetch helper, and implements multi-page export retrieval.
src/lib/icons.js Adds DOWNLOAD_ICON for the export UI.
Files not reviewed (1)
  • src/lib/icons.js: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +155 to +158
function getExportRow(rawItem) {
const item = formatHistoryItem(rawItem);
const pnlPercent = item.pnl && item.margin ? 100 * item.pnl / item.margin : '';

Comment on lines +170 to +175
item.status,
item.reason || '',
item.pnl ? `${formatForDisplay(item.pnl)} ${item.asset}` : '',
pnlPercent ? `${formatForDisplay(pnlPercent, true)}%` : '',
item.fee ? `${formatForDisplay(item.fee)} ${item.asset}` : '',
formatDate(item.expiry) || '',
self.onmessage = function(event) {
const escapeCell = function(value) {
if (value === undefined || value === null) return '';
const text = String(value);
<div class='export-toolbar'>
<label>From <input type='date' bind:value={exportFrom} aria-label='Export history from date'></label>
<label>To <input type='date' bind:value={exportTo} aria-label='Export history to date'></label>
<button on:click={exportHistory} disabled={isExporting || isLoading} use:tooltip={{content: 'Export history as CSV'}}>
Comment thread src/api/history.js Outdated
@@ -4,7 +4,7 @@
import { address, history, lastHistoryItemsCount, historySortKey, historyOrderStatusToShow } from '@lib/stores'
import { getLabelForAsset, getChainData } from '@lib/utils'
Comment thread src/api/history.js
Comment on lines 18 to 33
let {
first,
skip,
diff
} = params;

if (!first) first = DEFAULT_HISTORY_COUNT;
if (!skip) skip = 0;

const statusesToShow = get(historyOrderStatusToShow);

const sortKey = get(historySortKey); // [columnName, isDesc]

let sortBy = 'timestamp';
let sortDirection = 'desc';

Comment thread src/api/history.js Outdated
if (!url) return [];

const response = await fetch(url);
if (!response.ok) return [];
@subhajitlucky subhajitlucky force-pushed the export-trading-history-14 branch from c248f2c to 2997c0e Compare May 12, 2026 07:37
@subhajitlucky
Copy link
Copy Markdown
Author

Updated after automated review:

  • Preserve exported 0 values for P/L, P/L %, and fees.
  • Prefix spreadsheet-formula-like CSV cells before escaping.
  • Add an accessible label and busy state to the icon-only export button.
  • Remove unused history API imports/params.
  • Throw on failed history export requests so the UI shows an export error instead of "No history found".

Verification:

  • npm run build (passes; existing repo warnings remain)
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export trading history

2 participants