Page tree
Skip to end of metadata
Go to start of metadata

How to get data

  1. Check what symbols are available for you in your IPF.

  2. Check available market depth.

  3. Make a request via API.

Java API

import com.dxfeed.api.DXFeed;
import com.dxfeed.api.DXFeedSubscription;
import com.dxfeed.event.market.Quote;

/**
 * Subscribes to Quote events for a specified symbol and prints them until terminated.
 */
public class PrintQuoteEvents {
    public static void main(String[] args) throws InterruptedException {
        String symbol = args[0];
        // Use default DXFeed instance for that data feed address is defined by dxfeed.properties file
        DXFeedSubscription<Quote> sub = DXFeed.getInstance().createSubscription(Quote.class);
        sub.addEventListener(events -> {
            for (Quote quote : events)
                System.out.println(quote);
        });
        sub.addSymbols(symbol);
        Thread.sleep(Long.MAX_VALUE);
    }
}

Rest API

Web

https://tools.dxfeed.com/webservice/rest/events.json?events=Trade&symbols=AAPL,MSFT,IBM

C# API

Python API

Currently, Python API wraps the Web API.

import requests
import sseclient
import json


def make_ipf(*args, **kwargs):
    endpoint='https://tools.dxfeed.com/ipf?'
    return '{endpoint}UNDERLYING={underlying}&SYMBOL={symbol}*'.format(
        endpoint=endpoint,
        underlying=kwargs.get('underlying'),
        symbol=kwargs.get('symbol')
    )

def build_symbol(*args, **kwargs):
    return '.{underlying}{date}'.format(
        underlying=kwargs.get('underlying'),
        date=kwargs.get('date')
    )

def get_ipf(*args, **kwargs):
    endpoint=kwargs.get('endpoint')
    credentials=kwargs.get('credentials')
    reply=requests.get(endpoint, auth=credentials)
    return reply.text

def parse_ipf(ipf):
    strings=ipf.split('\n')
    del strings[0]
    del strings[-1]
    symbols = ""

    for string in strings:
        fields=string.split(',')
        if len(fields)>1:
            symbols += fields[1]
            symbols += ','


    return symbols[:-1]


def event_generator(symbol: str='XBT/USD,AAPL',
                    event_type: str='Quote',
                    credentials: tuple=('demo', 'demo')):

    url = 'https://tools.dxfeed.com/webservice/rest/eventSource.json'
    data = {
        'events': event_type,
        'symbols': symbol
    }
    response = requests.post(url=url, data=data, auth=credentials, stream=True)
    client = sseclient.SSEClient(response)

    for event in client.events():
        event = json.loads(event.data)
        if event_type in event:
            yield event

def main():
    symbol=input('Write symbol:\n')
    date=input('Write expiration date:\n')
    option = build_symbol(underlying=symbol, date=date)
    endpoint = make_ipf(underlying=symbol, symbol=option)
    ipf = get_ipf(endpoint=endpoint, credentials=('demo','demo'))
    list = parse_ipf(ipf=ipf)
    for item in event_generator(symbol=list):
        print(item)

if __name__ == '__main__':
    main()