@watsonserve/stock-base 0.0.17 → 0.0.19

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.
Files changed (3) hide show
  1. package/dao.js +11 -1
  2. package/package.json +1 -1
  3. package/types/dao.d.ts +1 -0
package/dao.js CHANGED
@@ -45,6 +45,14 @@ export function toDivPoints(market, nc, data) {
45
45
  new Point('Dividend').tag('nc', `${nc}.${market}`).tag('type', 'paid').tag('currency', curr).floatField('amount', amount).timestamp(paid)
46
46
  ];
47
47
  }
48
+ export function toBonusPoint(fullNc, data) {
49
+ const { ratio, ex } = data;
50
+ return new Point('Bonus')
51
+ .tag('nc', fullNc)
52
+ .tag('type', 'ex')
53
+ .floatField('radio', ratio)
54
+ .timestamp(ex);
55
+ }
48
56
  function groupBy(key, list, delKey = false) {
49
57
  return list.reduce((pre, item) => {
50
58
  const foo = item[key];
@@ -97,11 +105,13 @@ export class InfluxDAO {
97
105
  const ncQuery = ncs.map(nc => `r["nc"] == "${nc}"`).join(' or ');
98
106
  const fdQuery = fileds.map(fd => `r["_field"] == "${fd}"`).join(' or ');
99
107
  const filters = [mkQuery, ncQuery, fdQuery].filter(Boolean).map(str => `|> filter(fn: (r) => ${str})`).join('\n');
108
+ const start = new Date(lt.getTime() - 30 * A_DAY_MS).toJSON().substring(0, 10);
100
109
  const fluxQuery = `from(bucket: "${bucket}")
101
- |> range(start: ${new Date(lt.getTime() - 30 * A_DAY_MS).toJSON().substring(0, 10)}, end: ${lt.toJSON()})
110
+ |> range(start: ${start}, stop: ${lt.toJSON()})
102
111
  ${filters}
103
112
  |> last()
104
113
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")`;
114
+ // console.debug(fluxQuery);
105
115
  return new Promise((resolve, reject) => {
106
116
  const list = [];
107
117
  queryClient.queryRows(fluxQuery, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@watsonserve/stock-base",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],
package/types/dao.d.ts CHANGED
@@ -28,6 +28,7 @@ export declare function latestDay(): string;
28
28
  export declare function toFxPoint(sgd: number, hkd: number, cny: number, timestamp: number): Point;
29
29
  export declare function toStockPoint(market: EnMarket, st: IStock, timestamp: number): Point;
30
30
  export declare function toDivPoints(market: string, nc: string, data: IDividend): Point[];
31
+ export declare function toBonusPoint(fullNc: string, data: IDividend): Point;
31
32
  export declare class InfluxDAO {
32
33
  private origin;
33
34
  private org;