index.d.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import React from 'react';
  2. import * as d3Scale from 'd3-scale';
  3. import * as d3Array from 'd3-array';
  4. import * as d3Color from 'd3-color';
  5. import * as d3Format from 'd3-format';
  6. import * as d3Interpolate from 'd3-interpolate';
  7. import * as d3Shape from 'd3-shape';
  8. import * as d3Timer from 'd3-timer';
  9. import * as d3Ease from 'd3-ease';
  10. export const d3: typeof d3Scale & typeof d3Array & typeof d3Color & typeof d3Format & typeof d3Interpolate & typeof d3Shape & typeof d3Ease & typeof d3Timer;
  11. /**
  12. * Stock Heatmap configurations.
  13. */
  14. export interface StockHeatmapOptions {
  15. /** Border Padding: [ top, right, bottom, left ] */
  16. borderPadding?: number[];
  17. /** Bid Ask Graph Width */
  18. bidAskWidth?: number,
  19. /** Y Axis Width */
  20. axisYWidth?: number,
  21. /** X Axis Height */
  22. axisXHeight?: number,
  23. /** Buy Color (RBG format) */
  24. buyColor?: string,
  25. /** Contrast text color on top of buy color (RBG format) */
  26. textOnBuyColor?: string,
  27. /** Sell Color (RBG format) */
  28. sellColor?: string,
  29. /** Contrast text color on top of sell color (RBG format) */
  30. textOnSellColor?: string,
  31. /** Contrast text color on top of background color (RBG format) */
  32. textOnBackground?: string,
  33. /** Contrast text highlight color on top of background color (RBG format) */
  34. textHighlightOnBackground?: string,
  35. /** Price line color (RBG format) */
  36. tradeColor?: string,
  37. /** Axis tick hight */
  38. axisTickSize?: number,
  39. /** Axis line color contrast to background color (RBG format) */
  40. axisColor?: string,
  41. /** X Axis padding between tick and text */
  42. xAxisTextPadding?: number,
  43. /** Y Axis padding between tick and text */
  44. yAxisTextPadding?: number,
  45. /** Padding between Main graph and Bid ask graph */
  46. bidAskGraphPaddingLeft?: number,
  47. /** Bid ask graph transition animation duration (miliseconds) */
  48. bidAskTransitionDuration?: number,
  49. /** Trade volume circle maximum radius */
  50. volumeCircleMaxRadius?: number,
  51. /** Seconds to accumulate to calculate running buy/sell ratio. */
  52. runningRatioSeconds?: number,
  53. /** Graph background color (RBG format) */
  54. clearColor?: string,
  55. }
  56. /** Data format for the Stock heatmap graph */
  57. export interface StockData {
  58. /** Market depth data at this data point */
  59. marketDepth: {
  60. lastTradedPrice: number,
  61. lastTradedQty: number,
  62. priceChangeAmt: number,
  63. priceChangePct: number,
  64. lastTradedTS: number,
  65. open: number,
  66. high: number,
  67. low: number,
  68. close: number,
  69. volume: number,
  70. avgPrice: number,
  71. buyOrderVolume: number,
  72. buys: { rate: number, orders: number, qty: number }[],
  73. sellOrderVolume: number,
  74. sells: { rate: number, orders: number, qty: number }[]
  75. },
  76. /** Timestamp for this data point HH:mm:ss */
  77. ts: string,
  78. /** The Stock symbol */
  79. tradingsymbol: string,
  80. /** Currently pending orders for this data point */
  81. pendingOrders: any[]
  82. }
  83. /**
  84. * Stock Heatmap
  85. * @author Rounak Saha
  86. *
  87. * © Copyright 2020, Rounak Saha
  88. */
  89. export default class StockHeatmap extends React.Component<{
  90. /** The width of the heatmap */
  91. width: number,
  92. /** The height of the heatmap */
  93. height: number,
  94. /** Stock Heatmap configurations */
  95. options: StockHeatmapOptions,
  96. }> {
  97. /**
  98. * Set Data for the Heatmap to generate
  99. * @param {StockData[]} data The data to set
  100. */
  101. setData: (data: StockData[]) => void;
  102. /**
  103. * Add as extra data to existing data array.
  104. * @param {StockData} data
  105. */
  106. addData: (data: StockData) => void;
  107. /**
  108. * This sets the Heatmap Zoom level aka. window.
  109. * @param {number} zoom The seconds to zoom into
  110. */
  111. setZoomLevel: (zoom: number) => void;
  112. /**
  113. * Move the position of data window within the main data.
  114. * @param {number} position The target position of the window to be moved to.
  115. */
  116. moveDataWindow: (position: number) => void
  117. }