# data-source

> data-source for stock data

Latest version **5.3.2** (published 2017-12-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install data-source
pnpm add data-source
yarn add data-source
bun add data-source
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.3.2 |
| Published | 2017-12-11 |
| First published | 2016-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 11 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kaelzhang |
| Maintainers | kael |
| Keywords | data-source |

## Links

- npm: https://www.npmjs.com/package/data-source
- Repository: https://github.com/kaelzhang/compton
- Homepage: https://github.com/kaelzhang/compton#readme
- Issues: https://github.com/kaelzhang/soros/issues
- npm.io page: https://npm.io/package/data-source

## Dependencies (11)

- [mysql](https://npm.io/package/mysql.md) ^2.15.0
- [skema](https://npm.io/package/skema.md) ^5.0.1
- [moment](https://npm.io/package/moment.md) ^2.19.3
- [lru-cache](https://npm.io/package/lru-cache.md) ^4.0.2
- [err-object](https://npm.io/package/err-object.md) ^1.0.2
- [time-spans](https://npm.io/package/time-spans.md) ^3.2.0
- [lazy-concat](https://npm.io/package/lazy-concat.md) ^1.0.2
- [ready-queue](https://npm.io/package/ready-queue.md) ^1.0.0
- [layered-cache](https://npm.io/package/layered-cache.md) ^2.2.2
- [array-map-sorted](https://npm.io/package/array-map-sorted.md) ^1.3.1
- [lodash.findlastindex](https://npm.io/package/lodash.findlastindex.md) ^4.6.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 5.3.2 (latest) — 2017-12-11
- 5.3.1 — 2017-12-08
- 5.3.0 — 2017-12-08
- 5.2.0 — 2017-12-08
- 5.1.3 — 2017-12-08
- 5.1.2 — 2017-12-08
- 5.1.1 — 2017-12-08
- 5.1.0 — 2017-12-07
- 5.0.13 — 2017-12-07
- 5.0.12 — 2017-12-06
- 5.0.11 — 2017-12-06
- 5.0.10 — 2017-12-06
- 5.0.9 — 2017-12-06
- 5.0.8 — 2017-12-06
- 5.0.7 — 2017-12-05
- … 27 more at https://npm.io/package/data-source/versions

## README

[![Build Status](https://travis-ci.org/kaelzhang/data-source.svg?branch=master)](https://travis-ci.org/kaelzhang/data-source)
<!-- optional appveyor tst
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/data-source?branch=master&svg=true)](https://ci.appveyor.com/project/kaelzhang/data-source)
-->
<!-- optional npm version
[![NPM version](https://badge.fury.io/js/data-source.svg)](http://badge.fury.io/js/data-source)
-->
<!-- optional npm downloads
[![npm module downloads per month](http://img.shields.io/npm/dm/data-source.svg)](https://www.npmjs.org/package/data-source)
-->
<!-- optional dependency status
[![Dependency Status](https://david-dm.org/kaelzhang/data-source.svg)](https://david-dm.org/kaelzhang/data-source)
-->

# data-source

data-source for stock data

## Install

```sh
$ npm install data-source --save
```

## Usage

```js
import DataSource from 'data-source'

const dataSource = new DataSource({
  connection: {
    host: '127.0.0.1',
    user: 'root',
    password: '',
    database: ''
  },
  code: 'sz300131',
  loader: Loader,

  // Whether the given time of the span is trading
  // - span: day, will not check hours and minutes
  // -
  isTrading: ({time, span}) => true
})

const span = dataSource.span('MONTH')

const {
  // `Number` open price
  open,
  // `Number` the highest price
  high,
  // `Number` the lowest price
  low,
  // `Number` the close price
  close,
  // `Number` the volume of transactions
  volume,
  // `Date` time
  time
} = await span.get(new Date(2017, 4, 1))

console.log(`sz300131 opened with ${open} at 2017-05-01`)
```

## span.get(time)

Gets a single datum

- **time** `Date|Array<Date>`

Returns `Candlestick|null`

## span.get(...times)

Returns `Array<Candlestick>`

## span.between([from, to])

- **from** `Date` the closed left of the region
- **to** `Date` the closed right of the region

Returns `Array<Candlestick>` data between a period.

## span.latest(limit)

- **limit** `Number` limit the number of results.

Returns `Array<Candlestick>`

## span.sync([from, to])

Sync data from `from` to `to`, and update db, and update last-updated record.

## License

MIT

---
_Source: https://npm.io/package/data-source · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
