This project demonstrates some aspects of working with real-time time series (stock tickers) data.
There are two ways to run server: as a Docker container (simplest) or locally in current environment.
- Fetch ticker prices from third-party service in realtime
- Cache requested data
- Execute queries on historical data
- Supported data providers: IEX
- Docker >= 18.03
sudo su curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" apt update apt install -y docker-ce curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose usermod -aG docker $USER
git clone https://github.com/kirgene/stock-monitor.git
cd stock-monitor
docker-compose up -d
Note: if you receive error like
Couldn't connect to Docker daemon
try to reboot your system.
http://localhost:8000
- Node.js >= 12.5
- PostgreSQL >= 11
build-essentials
package
CREATE DATABASE stock_db;
CREATE USER stock_admin WITH PASSWORD 'stock_pass';
GRANT ALL PRIVILEGES ON DATABASE stock_db TO stock_admin;
git clone https://github.com/kirgene/stock-monitor.git
cd stock-monitor
npm install
Copy
.env.example
template to.env
and modify according to your environment
cp .env.example .env
npm run migrate
- Development mode:
npm run start-dev
- Production mode:
npm run build
npm start
http://localhost:8000
-
Success Response:
- Code: 200
Content:{ data: [{...}, {...}, ...] }
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:{ errors : ["...", "....", ...] }
- Code: 404 NOT FOUND
Return available stocks.
-
URL
/stocks
-
Method:
GET
-
URL Params
Field Required Data Type Description Examples name JSON string array Case insensitive filter on stock symbols and company names with wildcard *
matching support["ab*","f*p"]
,["abc"]
-
Response:
Object key Value Type Description Examples id integer Item ID 23
,35
name string Company name Intel Corporation
,Alphabet Inc.
symbol string Stock symbol INTC
,GOOG
Return stock prices using different filters.
-
URL
/prices
-
Method:
GET
-
URL Params
Field Data Type Description Examples name JSON string array Case insensitive filter on stock symbols and company names with wildcard *
matching support["ab*","f*p"]
,["abc"]
start ISO 8601 date Start datetime 2019-06-27T14:00:00
,2019-06-27T16:00:00
end ISO 8601 date End datetime 2019-06-27T14:00:00
,2019-06-27T16:00:00
high float List stocks with prices below this value (high water mark) 150.40
,600
low float List stocks with prices above this value (low water mark) 10.25
,50
NOTICE: specifying
start
andend
params on a fresh database will lead to downloading historical data for a given time range and the amount of that data can be HUGE ( ~ 700 - 900 MB for a single day).
The progress and estimated completion time of this processing are displayed in real-time in logs.
-
Response:
Object key Value Type Description Examples id integer Item ID 23
,35
name string Company name Intel Corporation
,Alphabet Inc.
symbol string Stock symbol INTC
,GOOG
price float Stock price 150.40
,600
time ISO 8601 Timestamp 2019-06-26T15:33:46.812Z
Subscribe for latest stocks prices
-
URL
/latest-prices
-
Method:
WebSocket (ws://)
-
Request Message
Object Key Data Type Description Examples type string Use subscribe
/unsubscribe
to subscribe/unsubscribe for/from a given stock["ab*","f*p"]
,["abc"]
name JSON string array Case insensitive filter on stock symbols and company names with wildcard *
matching support["ab*","f*p"]
,["abc"]
-
Response:
Refer to
Response
section ofList Stocks Prices
API.
-
Show latest prices for single company:
http://localhost:8000/demo/?name=["baba"]
-
Show latest prices for multiple companies:
http://localhost:8000/demo/?name=["baba", "v"]
-
Show prices for a given time range (from 12:00 to 18:10 of March 20, 2019):
http://localhost:8000/demo/?name=["BABA"]&start=2019-03-20T12:00:00&end=2019-03-20T18:10:00
-
Show prices for a given time range with high ($180.5) and low ($180) price filter:
http://localhost:8000/demo/?name=["BABA"]&start=2019-03-20T12:00:00&end=2019-03-20T18:10:00&low=180&high=180.5