Code Monkey home page Code Monkey logo

stock-bot-api's Introduction

stock-bot-api

Retrieve info related to dividend stocks.

You might also be interested in: stock-bot

Requirements

  • Docker
  • Node.js (only tested against v14)
  • Yarn

Setup

To get started, run: docker-compose up, which will start a Redis instance and Fastify + GraphQL server.

Usage

To retrieve a dividend, you must first acquire an instrument to query against.

All requests must be authenticated

Retrieve an instrument with an ISIN

Request

curl --location --request POST 'http://localhost:3000/graphql' \
--header 'x-api-key: [YOUR API KEY]' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query": "query { fetchInstrumentWithIsin(isin: \"US5949181045\") { id } }"
}'

Response

{
    "data": {
        "fetchInstrumentWithIsin": {
            "id": "17ae97b6-94cc-5543-b671-b862b1a6d5b7"
        }
    }
}

Retrieve an instrument with a stock symbol (ticker)

Request

curl --location --request POST 'http://localhost:3000/graphql' \
--header 'x-api-key: [YOUR API KEY]' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query": "query { fetchInstrumentWithSymbol(symbol: \"MSFT\") { id } }"
}'

Response

{
    "data": {
        "fetchInstrumentWithSymbol": {
            "id": "17ae97b6-94cc-5543-b671-b862b1a6d5b7"
        }
    }
}

Now that you have an instrument, you can use this to retrieve a dividend

Retrieve a dividend

Request

curl --location --request POST 'http://localhost:3000/graphql' \
--header 'x-api-key: c7dd7869-d701-4259-8d36-18dd295ebb49' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query": "query { fetchDividend(id: \"17ae97b6-94cc-5543-b671-b862b1a6d5b7\"){ dividendYield } }"
}'

Response

{
    "data": {
        "fetchDividend": {
            "dividendYield": 0.009189
        }
    }
}

Authentication

An API key is used as an anonymous way to rate limit the service.

In order to generate API keys, you must set a value in the config under the server.authKey property.

Once this value is set, API keys can be generated using the following request:

curl --location --request POST 'http://localhost:3000/api/key-store' \
--header 'Content-Type: application/json' \
--data-raw '{
    "authKey": "[YOUR server.authKey VALUE]"
}'

Response

{
    "created": "2021-02-25T11:01:52.189Z",
    "isBanned": false,
    "key": "47ccf4d9-1ff8-453a-8286-5a96d7f842c3",
    "lastUsed": "2021-02-25T11:01:52.189Z"
}

Rate Limits

If a consumer makes more requests than the server.apiLimit.maxRequestsPerMinute value in the config (default: 300), they will receive a HTTP 429 response.

If the consumer continues to make requests whilst limited, and exceeds the server.apiLimit.banAfterMaxHttp429Responses value in the config (default: 30), the API key will be banned and the response code will be HTTP 409.

Integration Tests

Run yarn test:integration from the Fastify container to test the suppliers are working as expected.

Future development tasks

  • Break dividend cache
  • Config option to allow supplier preference for stock yield
  • Add dividend payout ratio
  • Add dividend next payment date

stock-bot-api's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.