@kodiak-finance/orderly-utils 2.8.30-alpha.0 → 2.8.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +42 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.js +491 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +478 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -170,8 +170,7 @@ import {
|
|
|
170
170
|
var hex2int = (chainId) => parseInt(chainId);
|
|
171
171
|
var int2hex = (chainId) => `0x${chainId.toString(16)}`;
|
|
172
172
|
var praseChainId = (chainId) => {
|
|
173
|
-
if (typeof chainId === "string")
|
|
174
|
-
return hex2int(chainId);
|
|
173
|
+
if (typeof chainId === "string") return hex2int(chainId);
|
|
175
174
|
return chainId;
|
|
176
175
|
};
|
|
177
176
|
var praseChainIdToNumber = (chainId) => {
|
|
@@ -414,6 +413,473 @@ formatNumWithNamespace.assetValue = (num) => {
|
|
|
414
413
|
formatNumWithNamespace.collateral = (num) => {
|
|
415
414
|
return formatNum(4 /* collateral */, 2, num);
|
|
416
415
|
};
|
|
416
|
+
|
|
417
|
+
// src/csvExport.ts
|
|
418
|
+
var generateCSV = (options) => {
|
|
419
|
+
const { columns, data } = options;
|
|
420
|
+
const headers = columns.map((col) => `"${col.title}"`).join(",");
|
|
421
|
+
const rows = data.map((row) => {
|
|
422
|
+
return columns.map((col) => {
|
|
423
|
+
let value = row[col.key];
|
|
424
|
+
if (col.formatter) {
|
|
425
|
+
value = col.formatter(value);
|
|
426
|
+
}
|
|
427
|
+
const stringValue = String(value != null ? value : "");
|
|
428
|
+
const escapedValue = stringValue.replace(/"/g, '""');
|
|
429
|
+
return `"${escapedValue}"`;
|
|
430
|
+
}).join(",");
|
|
431
|
+
});
|
|
432
|
+
return [headers, ...rows].join("\n");
|
|
433
|
+
};
|
|
434
|
+
var downloadCSV = (csv, filename) => {
|
|
435
|
+
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
|
436
|
+
const link = document.createElement("a");
|
|
437
|
+
const url = URL.createObjectURL(blob);
|
|
438
|
+
link.setAttribute("href", url);
|
|
439
|
+
link.setAttribute("download", `${filename}.csv`);
|
|
440
|
+
link.style.visibility = "hidden";
|
|
441
|
+
document.body.appendChild(link);
|
|
442
|
+
link.click();
|
|
443
|
+
document.body.removeChild(link);
|
|
444
|
+
};
|
|
445
|
+
var formatTimestamp = (timestamp) => {
|
|
446
|
+
if (!timestamp) return "--";
|
|
447
|
+
const numTimestamp = Number(timestamp);
|
|
448
|
+
const date = new Date(
|
|
449
|
+
numTimestamp > 1e10 ? numTimestamp : numTimestamp * 1e3
|
|
450
|
+
);
|
|
451
|
+
return date.toISOString().split("T")[0] + " " + date.toTimeString().slice(0, 8);
|
|
452
|
+
};
|
|
453
|
+
var formatNumber = (value, decimals = 2) => {
|
|
454
|
+
if (value === null || value === void 0) return "--";
|
|
455
|
+
const num = Number(value);
|
|
456
|
+
if (isNaN(num)) return "--";
|
|
457
|
+
return num.toFixed(decimals);
|
|
458
|
+
};
|
|
459
|
+
var formatPercent = (value, decimals = 2) => {
|
|
460
|
+
if (value === null || value === void 0) return "--";
|
|
461
|
+
const num = Number(value);
|
|
462
|
+
if (isNaN(num)) return "--";
|
|
463
|
+
return (num * 100).toFixed(decimals) + "%";
|
|
464
|
+
};
|
|
465
|
+
var getPositionExportColumns = () => [
|
|
466
|
+
{ key: "symbol", title: "Symbol" },
|
|
467
|
+
{
|
|
468
|
+
key: "position_qty",
|
|
469
|
+
title: "Position Qty",
|
|
470
|
+
formatter: (v) => formatNumber(v, 4)
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
key: "average_open_price",
|
|
474
|
+
title: "Avg Open Price",
|
|
475
|
+
formatter: (v) => formatNumber(v, 4)
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
key: "mark_price",
|
|
479
|
+
title: "Mark Price",
|
|
480
|
+
formatter: (v) => formatNumber(v, 4)
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
key: "settle_price",
|
|
484
|
+
title: "Settle Price",
|
|
485
|
+
formatter: (v) => formatNumber(v, 4)
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
key: "est_liq_price",
|
|
489
|
+
title: "Est. Liquidation Price",
|
|
490
|
+
formatter: (v) => v === null ? "--" : formatNumber(v, 4)
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
key: "cost_position",
|
|
494
|
+
title: "Cost Position",
|
|
495
|
+
formatter: (v) => formatNumber(v, 2)
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
key: "unsettled_pnl",
|
|
499
|
+
title: "Unsettled PnL",
|
|
500
|
+
formatter: (v) => formatNumber(v, 2)
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
key: "pnl_24_h",
|
|
504
|
+
title: "PnL 24h",
|
|
505
|
+
formatter: (v) => formatNumber(v, 2)
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
key: "leverage",
|
|
509
|
+
title: "Leverage",
|
|
510
|
+
formatter: (v) => formatNumber(v, 2)
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
key: "imr",
|
|
514
|
+
title: "Initial Margin Ratio",
|
|
515
|
+
formatter: (v) => formatPercent(v, 4)
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
key: "mmr",
|
|
519
|
+
title: "Maintenance Margin Ratio",
|
|
520
|
+
formatter: (v) => formatPercent(v, 4)
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
key: "IMR_withdraw_orders",
|
|
524
|
+
title: "IMR with Withdraw Orders",
|
|
525
|
+
formatter: (v) => formatPercent(v, 4)
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
key: "MMR_with_orders",
|
|
529
|
+
title: "MMR with Orders",
|
|
530
|
+
formatter: (v) => formatPercent(v, 4)
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
key: "pending_long_qty",
|
|
534
|
+
title: "Pending Long Qty",
|
|
535
|
+
formatter: (v) => formatNumber(v, 4)
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
key: "pending_short_qty",
|
|
539
|
+
title: "Pending Short Qty",
|
|
540
|
+
formatter: (v) => formatNumber(v, 4)
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
key: "last_sum_unitary_funding",
|
|
544
|
+
title: "Last Sum Unitary Funding",
|
|
545
|
+
formatter: (v) => formatNumber(v, 4)
|
|
546
|
+
},
|
|
547
|
+
{
|
|
548
|
+
key: "fee_24_h",
|
|
549
|
+
title: "Fee 24h",
|
|
550
|
+
formatter: (v) => formatNumber(v, 8)
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
key: "seq",
|
|
554
|
+
title: "Sequence"
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
key: "timestamp",
|
|
558
|
+
title: "Timestamp",
|
|
559
|
+
formatter: formatTimestamp
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
key: "updated_time",
|
|
563
|
+
title: "Updated Time",
|
|
564
|
+
formatter: formatTimestamp
|
|
565
|
+
}
|
|
566
|
+
];
|
|
567
|
+
var getOrderExportColumns = (tabType) => {
|
|
568
|
+
if (tabType === "orderHistory") {
|
|
569
|
+
return [
|
|
570
|
+
{
|
|
571
|
+
key: "order_id",
|
|
572
|
+
title: "Order ID"
|
|
573
|
+
},
|
|
574
|
+
{ key: "symbol", title: "Symbol" },
|
|
575
|
+
{ key: "side", title: "Side" },
|
|
576
|
+
{ key: "type", title: "Order Type" },
|
|
577
|
+
{ key: "status", title: "Status" },
|
|
578
|
+
{
|
|
579
|
+
key: "quantity",
|
|
580
|
+
title: "Quantity",
|
|
581
|
+
formatter: (v) => formatNumber(v, 4)
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
key: "visible_quantity",
|
|
585
|
+
title: "Visible Quantity",
|
|
586
|
+
formatter: (v) => formatNumber(v, 4)
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
key: "total_executed_quantity",
|
|
590
|
+
title: "Total Executed Qty",
|
|
591
|
+
formatter: (v) => formatNumber(v, 4)
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
key: "average_executed_price",
|
|
595
|
+
title: "Avg Executed Price",
|
|
596
|
+
formatter: (v) => v === null ? "--" : formatNumber(v, 4)
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
key: "total_fee",
|
|
600
|
+
title: "Fee",
|
|
601
|
+
formatter: (v) => formatNumber(v, 8)
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
key: "fee_asset",
|
|
605
|
+
title: "Fee Asset"
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
key: "realized_pnl",
|
|
609
|
+
title: "Realized PnL",
|
|
610
|
+
formatter: (v) => formatNumber(v, 2)
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
key: "created_time",
|
|
614
|
+
title: "Created Time",
|
|
615
|
+
formatter: formatTimestamp
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
key: "updated_time",
|
|
619
|
+
title: "Updated Time",
|
|
620
|
+
formatter: formatTimestamp
|
|
621
|
+
}
|
|
622
|
+
];
|
|
623
|
+
}
|
|
624
|
+
const baseColumns = [
|
|
625
|
+
{ key: "symbol", title: "Symbol" },
|
|
626
|
+
{
|
|
627
|
+
key: "order_id",
|
|
628
|
+
title: "Order ID"
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
key: "user_id",
|
|
632
|
+
title: "User ID"
|
|
633
|
+
},
|
|
634
|
+
{ key: "side", title: "Side" },
|
|
635
|
+
{ key: "type", title: "Order Type" },
|
|
636
|
+
{ key: "status", title: "Status" },
|
|
637
|
+
{
|
|
638
|
+
key: "price",
|
|
639
|
+
title: "Price",
|
|
640
|
+
formatter: (v) => v === null ? "--" : formatNumber(v, 4)
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
key: "quantity",
|
|
644
|
+
title: "Quantity",
|
|
645
|
+
formatter: (v) => formatNumber(v, 4)
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
key: "visible",
|
|
649
|
+
title: "Visible",
|
|
650
|
+
formatter: (v) => formatNumber(v, 4)
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
key: "visible_quantity",
|
|
654
|
+
title: "Visible Quantity",
|
|
655
|
+
formatter: (v) => formatNumber(v, 4)
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
key: "executed",
|
|
659
|
+
title: "Executed",
|
|
660
|
+
formatter: (v) => formatNumber(v, 4)
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
key: "total_executed_quantity",
|
|
664
|
+
title: "Total Executed Qty",
|
|
665
|
+
formatter: (v) => formatNumber(v, 4)
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
key: "average_executed_price",
|
|
669
|
+
title: "Avg Executed Price",
|
|
670
|
+
formatter: (v) => v === null ? "--" : formatNumber(v, 4)
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
key: "amount",
|
|
674
|
+
title: "Amount",
|
|
675
|
+
formatter: (v) => v === null ? "--" : formatNumber(v, 2)
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
key: "total_fee",
|
|
679
|
+
title: "Fee",
|
|
680
|
+
formatter: (v) => formatNumber(v, 8)
|
|
681
|
+
},
|
|
682
|
+
{
|
|
683
|
+
key: "fee_asset",
|
|
684
|
+
title: "Fee Asset"
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
key: "realized_pnl",
|
|
688
|
+
title: "Realized PnL",
|
|
689
|
+
formatter: (v) => formatNumber(v, 2)
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
key: "created_time",
|
|
693
|
+
title: "Created Time",
|
|
694
|
+
formatter: formatTimestamp
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
key: "updated_time",
|
|
698
|
+
title: "Updated Time",
|
|
699
|
+
formatter: formatTimestamp
|
|
700
|
+
}
|
|
701
|
+
];
|
|
702
|
+
if (tabType === "tp_sl") {
|
|
703
|
+
baseColumns.splice(6, 0, {
|
|
704
|
+
key: "trigger_price",
|
|
705
|
+
title: "Trigger Price",
|
|
706
|
+
formatter: (v) => formatNumber(v, 4)
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
return baseColumns;
|
|
710
|
+
};
|
|
711
|
+
var getPositionHistoryExportColumns = () => [
|
|
712
|
+
{
|
|
713
|
+
key: "position_id",
|
|
714
|
+
title: "Position ID"
|
|
715
|
+
},
|
|
716
|
+
{ key: "symbol", title: "Symbol" },
|
|
717
|
+
{
|
|
718
|
+
key: "position_status",
|
|
719
|
+
title: "Status"
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
key: "type",
|
|
723
|
+
title: "Type"
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
key: "side",
|
|
727
|
+
title: "Side"
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
key: "closed_position_qty",
|
|
731
|
+
title: "Closed Position Qty",
|
|
732
|
+
formatter: (v) => formatNumber(v, 4)
|
|
733
|
+
},
|
|
734
|
+
{
|
|
735
|
+
key: "max_position_qty",
|
|
736
|
+
title: "Max Position Qty",
|
|
737
|
+
formatter: (v) => formatNumber(v, 4)
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
key: "avg_open_price",
|
|
741
|
+
title: "Avg Open Price",
|
|
742
|
+
formatter: (v) => v === null ? "--" : formatNumber(v, 4)
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
key: "avg_close_price",
|
|
746
|
+
title: "Avg Close Price",
|
|
747
|
+
formatter: (v) => v === null ? "--" : formatNumber(v, 4)
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
key: "realized_pnl",
|
|
751
|
+
title: "Realized PnL",
|
|
752
|
+
formatter: (v) => formatNumber(v, 2)
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
key: "accumulated_funding_fee",
|
|
756
|
+
title: "Accumulated Funding Fee",
|
|
757
|
+
formatter: (v) => formatNumber(v, 2)
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
key: "trading_fee",
|
|
761
|
+
title: "Trading Fee",
|
|
762
|
+
formatter: (v) => formatNumber(v, 2)
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
key: "insurance_fund_fee",
|
|
766
|
+
title: "Insurance Fund Fee",
|
|
767
|
+
formatter: (v) => formatNumber(v, 2)
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
key: "liquidator_fee",
|
|
771
|
+
title: "Liquidator Fee",
|
|
772
|
+
formatter: (v) => formatNumber(v, 2)
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
key: "leverage",
|
|
776
|
+
title: "Leverage",
|
|
777
|
+
formatter: (v) => formatNumber(v, 2)
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
key: "open_timestamp",
|
|
781
|
+
title: "Time Opened",
|
|
782
|
+
formatter: formatTimestamp
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
key: "close_timestamp",
|
|
786
|
+
title: "Time Closed",
|
|
787
|
+
formatter: (v) => v ? formatTimestamp(v) : "--"
|
|
788
|
+
},
|
|
789
|
+
{
|
|
790
|
+
key: "last_update_time",
|
|
791
|
+
title: "Updated Time",
|
|
792
|
+
formatter: formatTimestamp
|
|
793
|
+
}
|
|
794
|
+
];
|
|
795
|
+
var getLiquidationExportColumns = () => [
|
|
796
|
+
{
|
|
797
|
+
key: "timestamp",
|
|
798
|
+
title: "Time",
|
|
799
|
+
formatter: formatTimestamp
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
key: "type",
|
|
803
|
+
title: "Type"
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
key: "liquidation_id",
|
|
807
|
+
title: "Liquidation ID"
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
key: "symbol",
|
|
811
|
+
title: "Symbol"
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
key: "position_qty",
|
|
815
|
+
title: "Position Qty",
|
|
816
|
+
formatter: (v) => formatNumber(v, 4)
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
key: "mark_price",
|
|
820
|
+
title: "Mark Price",
|
|
821
|
+
formatter: (v) => formatNumber(v, 4)
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
key: "transfer_price",
|
|
825
|
+
title: "Transfer Price",
|
|
826
|
+
formatter: (v) => formatNumber(v, 4)
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
key: "liquidator_fee",
|
|
830
|
+
title: "Liquidator Fee",
|
|
831
|
+
formatter: (v) => formatNumber(v, 8)
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
key: "abs_liquidation_fee",
|
|
835
|
+
title: "Abs Liquidation Fee",
|
|
836
|
+
formatter: (v) => formatNumber(v, 2)
|
|
837
|
+
},
|
|
838
|
+
{
|
|
839
|
+
key: "insurance_fund_fee",
|
|
840
|
+
title: "Insurance Fund Fee",
|
|
841
|
+
formatter: (v) => formatNumber(v, 8)
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
key: "abs_insurance_fund_fee",
|
|
845
|
+
title: "Abs Insurance Fund Fee",
|
|
846
|
+
formatter: (v) => formatNumber(v, 2)
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
key: "cost_position_transfer",
|
|
850
|
+
title: "Cost Position Transfer",
|
|
851
|
+
formatter: (v) => formatNumber(v, 2)
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
key: "margin_ratio",
|
|
855
|
+
title: "Margin Ratio",
|
|
856
|
+
formatter: (v) => formatPercent(v, 4)
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
key: "account_mmr",
|
|
860
|
+
title: "Account MMR",
|
|
861
|
+
formatter: (v) => formatPercent(v, 4)
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
key: "position_notional",
|
|
865
|
+
title: "Position Notional",
|
|
866
|
+
formatter: (v) => formatNumber(v, 2)
|
|
867
|
+
},
|
|
868
|
+
{
|
|
869
|
+
key: "collateral_value",
|
|
870
|
+
title: "Collateral Value",
|
|
871
|
+
formatter: (v) => formatNumber(v, 2)
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
key: "transfer_amount_to_insurance_fund",
|
|
875
|
+
title: "Transfer Amount to Insurance Fund",
|
|
876
|
+
formatter: (v) => formatNumber(v, 2)
|
|
877
|
+
}
|
|
878
|
+
];
|
|
879
|
+
var exportToCSVFile = (options) => {
|
|
880
|
+
const csv = generateCSV(options);
|
|
881
|
+
downloadCSV(csv, options.filename);
|
|
882
|
+
};
|
|
417
883
|
export {
|
|
418
884
|
decimal_default as Decimal,
|
|
419
885
|
camelCaseToUnderscoreCase,
|
|
@@ -423,11 +889,21 @@ export {
|
|
|
423
889
|
commifyOptional,
|
|
424
890
|
cutNumber,
|
|
425
891
|
default2 as dayjs,
|
|
892
|
+
downloadCSV,
|
|
893
|
+
exportToCSVFile,
|
|
426
894
|
findLongestCommonSubString,
|
|
427
895
|
formatNumWithNamespace as formatNum,
|
|
896
|
+
formatNumber,
|
|
897
|
+
formatPercent,
|
|
428
898
|
formatSymbol,
|
|
899
|
+
formatTimestamp,
|
|
900
|
+
generateCSV,
|
|
429
901
|
getBBOType,
|
|
430
902
|
getGlobalObject,
|
|
903
|
+
getLiquidationExportColumns,
|
|
904
|
+
getOrderExportColumns,
|
|
905
|
+
getPositionExportColumns,
|
|
906
|
+
getPositionHistoryExportColumns,
|
|
431
907
|
getPrecisionByNumber,
|
|
432
908
|
getTPSLDirection,
|
|
433
909
|
getTimestamp,
|