项目作者: jspdown

项目描述 :
Aggregate OHLC data
高级语言: JavaScript
项目地址: git://github.com/jspdown/candle-collector.git
创建时间: 2018-02-26T06:42:37Z
项目社区:https://github.com/jspdown/candle-collector

开源协议:MIT License

下载


candle-collector

Collects markets prices, aggregate them into OHLC buckets and make them available
over HTTP.

Markets and timeframes are just entries in the database. Please see
sql-data/V1_1__Add_timeframes_and_pairs.sql.

Markets prices are fetched directly on the exchange. Currently, only one
exchange is available: Poloniex.

Setup

Prerequisites:

  • NodeJs v8.9.3
  • RabbitMQ 3.6.4
  • MySQL v5.7.21
  • Flyway v5.0.7

Environment variables:

  1. export CANDLE_COLLECTOR_MYSQL_USER="root"
  2. export CANDLE_COLLECTOR_MYSQL_PASS=""
  3. export CANDLE_COLLECTOR_MYSQL_HOST='localhost'
  4. export CANDLE_COLLECTOR_MYSQL_PORT=3306
  5. export CANDLE_COLLECTOR_MYSQL_DATABASE='candle_collector'
  6. export CANDLE_COLLECTOR_PORT=8080
  7. export CANDLE_COLLECTOR_AMQP_HOST="localhost"
  8. export CANDLE_COLLECTOR_AMQP_PORT=5672
  9. export CANDLE_COLLECTOR_AMQP_USER="guest"
  10. export CANDLE_COLLECTOR_AMQP_PASS="guest"

Start the API:

  1. // Start API
  2. npm run api
  3. // Start candle collector
  4. npm run collector
  5. // Start workers:
  6. npm run worker:save-candle

Or you can start all the services at once using Forever

Start collecting candles:

  1. npm run collector

“REST” API:

Method Path Description
GET /timeframes Get available timeframes
GET /pairs Get collected pairs
GET /candles Get collected candles

Errors have to following format:

  1. {
  2. "code": 2,
  3. "message": "Error message"
  4. }

Errors codes:

Name Code Status
INTERNAL_ERROR 1 500
NOT_FOUND 2 404
INVALID_PARAMETERS 3 400
MISSING_PARAMETERS 4 400

GET /timeframes

  1. $> http GET localhost:8080/timeframes
  2. HTTP/1.1 200 OK
  3. [
  4. {
  5. "unit": "minute",
  6. "value": 1
  7. }
  8. ]

GET /pairs

Query parameters:

Name Required Description
exchange no Filter by exchange
  1. $> http GET localhost:8080/pairs
  2. HTTP/1.1 200 OK
  3. [
  4. {
  5. "base": "ETH",
  6. "decimals": 8,
  7. "exchange": "poloniex",
  8. "quote": "BTC"
  9. }
  10. ]

GET /candles

Query parameters:

Name Required Description
exchange yes Exchange name
pair yes Pair you want (format: {BASE}_{QUOTE})
timeframe yes Timeframe you want (format: {VALUE}_{UNIT})

Errors:

  • INVALID_PARAMETERS: Parameter doesn’t conform to pair/timeframe’s format
  • MISSING_PARAMETERS: Missing query parameter
  • NOT_FOUND: Pair/exchange/timeframe not found
  1. $> http GET localhost:8080/candles exchange==poloniex pair==ETH_BTC timeframe==1_minute
  2. HTTP/1.1 200 OK
  3. [
  4. {
  5. "close": "0.08667571",
  6. "date": "2018-02-25T11:29:00.000Z",
  7. "high": "0.08683594",
  8. "low": "0.0866757",
  9. "open": "0.08671316",
  10. "volume": "95.5340148"
  11. },
  12. ...
  13. ]

Licence

See the LICENSE file for license rights and limitations (MIT).