Feed Saxo Bank instruments price into sqlite database

Though Saxo Bank has dropped MetaTrader support back in 2015. Open API allows to implement a custom broker.

We are going to consider read-only mode, when price of instruments is continuously put into sqlite database.

Authentication is required prior. A user friendly token generator allows to use a single header instead.

def k1(uic, asset_type, token):
    assert re.compile(r'[a-zA-Z]+').match(asset_type)
    with requests.get(
        'https://gateway.saxobank.com/sim/openapi/ref/v1/instruments/details/%d/%s' % (
            uic,
            asset_type
        ),
        headers=dict(
            authorization='Bearer %s' % token,
        ),
    ) as p:
        market_info = p.json()
    assert 'Symbol' in market_info
    return market_info
  

token is generated at https://www.developer.saxo/openapi/token/current

Available instruments vary between forex, stocks and derivatives.

Price monitoring requires uid and asset_type fields for an instrument. https://gateway.saxobank.com/sim/openapi/ref/v1/instruments allows to search based on keyword

Uid=4, AssetType=FxSpot are the values for AUDUSD forex symbol.

search instruments with pandas via open api
Fig 1. search instruments with pandas via open api

At the end we are able to identify the symbol being tracked and see database updates in real time.

data feed execution with price monitoring in real time
Fig 2. data feed execution with price monitoring in real time

Comments