More Effective API Use

We put together an example script that will help you track the market in near real-time via the Empirasign API without prematurely exhausting your API daily quota.

In short, it performs a costless (from a quota perspective) API call to detect changes in BWICs in the market sectors you are following. If there are any changes (new lists, new pxtalk, or new color) it then queries the relevant bonds. This second query has a quota cost, but is only made when there is new market data to retrieve.

The script is written in Python and does not import anything outside of the standard library (other than the ubiquitous requests library).

pseudo code

start of loop
if after 6pm then exit

get all bwics for a sector
are they are any new bwics or changes to existing bwics
if yes:
    run queries for bonds on new bwics or bwics with changes (e.g. new talk, or color)
    wait 60 seconds, return to top of loop
if no:
    wait 120 seconds, return to top of loop.

You can find the actual code on github at the following URL: