Loading repository data…
Loading repository data…
Nasdaq / repository
Nasdaq Data Link provides a modern and efficient method of delivery for real-time exchange data and other financial information. This repository provides a Python SDK for developing applications using Nasdaq Data Link's real-time data.
Nasdaq Data Link provides a modern and efficient method of delivery for realtime exchange data and other financial information. Data is made available through a suite of APIs, allowing for effortless integration of data from disparate sources, and a dramatic reduction in time to market for customer-designed applications. The API is highly scalable, and robust enough to support the delivery of real-time exchange data.
The SDK currently supports Python 3.9 and above
The source code is currently hosted on GitHub at: https://github.com/Nasdaq/NasdaqCloudDataService-SDK-Python
git clone https://github.com/Nasdaq/NasdaqCloudDataService-SDK-Python.gitcd NasdaqCloudDataService-SDK-Pythonpip install -e .Optional: to use the Jupyter notebook provided,
pip3 install notebook or conda conda install -c conda-forge notebookjupyter notebook and the Notebook Dashboard will open in your browserpython_sdk_examples.ipynbReplace example stream properties in the file kafka-config.json (https://github.com/Nasdaq/NasdaqCloudDataService-SDK-Python/blob/master/ncdssdk_client/src/main/python/resources/kafka-config.json) with provided values during on-boarding.
Required kafka configuration
"bootstrap.servers": {streams_endpoint_url}:9094
For optional consumer configurations see: https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
Replace example client authentication properties in the file client-authentication-config.json (https://github.com/Nasdaq/NasdaqCloudDataService-SDK-Python/blob/master/ncdssdk_client/src/main/python/resources/client-authentication-config.json) with valid credentials provided during on-boarding.
oauth.token.endpoint.uri: "https://{auth_endpoint_url}/auth/realms/pro-realm/protocol/openid-connect/token"
oauth.client.id: "client_id"
oauth.client.secret: "client_secret"
To enable debug logging, edit the file (https://github.com/Nasdaq/NasdaqCloudDataService-SDK-Python/blob/master/ncdssdk/src/main/resources/logging.json) and change the logging levels in whichever handler you would like output to go to.
For example, to enable debug logging to a file:
"file_handler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "simple",
"filename": "logging.log",
"maxBytes": 10485760,
"backupCount": 20,
"encoding": "utf8"
}
},
"loggers": {
"": {
"level": "DEBUG",
"handlers": ["console", "file_handler"],
"propogate": false
}
}
}
Next, add a debug option to your kafka configurations:
kafka_cfg = {
"bootstrap.servers": "{streams_endpoint_url}:9094",
"auto.offset.reset": "earliest",
"debug": "all"
}
How to run:
-opt -- Provide the operation you want to perform \n" +
" * TOP - View the top nnn records in the Topic/Stream\n" +
" * SCHEMA - Display the Schema for the topic\n" +
" * METRICS - Display the Metrics for the topic\n" +
" * TOPICS - List of streams available on Nasdaq Cloud DataService\n" +
" * GETMSG - Get one example message for the given message name\n" +
" * CONTSTREAM - Retrieve continuous stream \n" +
" * FILTERSTREAM - Retrieve continuous stream filtered by symbols and/or msgtypes \n" +
" * HELP - help \n" +
"-topic -- Provide topic for selected option --- REQUIRED for TOP,SCHEMA,METRICS,GETMSG,CONTSTREAM and FILTERSTREAM \n" +
"-symbols -- Provide symbols comma separated list --- OPTIONAL for FILTERSTREAM" +
"-msgnames -- Provide msgnames comma separated list --- OPTIONAL for FILTERSTREAM" +
"-authprops -- Provide Client Properties File path --- For using different set of Client Authentication Properties \n" +
"-kafkaprops -- Provide Kafka Properties File path --- For using different set of Kafka Properties \n" +
"-n -- Provide number of messages to retrieve --- REQUIRED for TOP \n" +
"-msgName -- Provide name of message based on schema --- REQUIRED for GETMSG \n" +
"-timestamp -- Provide timestamp in milliseconds --- OPTIONAL for TOP, CONTSTREAM and FILTERSTREAM\n"
A few examples:
Get first 100 records for given stream
python3.9 ncdssdk_client/src/main/python/ncdsclient/NCDSSession.py -opt TOP -n 100 -topic NLSPLUS-CTA-V4
Get all available streams
python3.9 ncdssdk_client/src/main/python/ncdsclient/NCDSSession.py -opt TOPICS
Below are several examples for how to access data using the SDK. A Jupyter notebook with this same code and information is provided in the file python_sdk_examples.ipnyb
To run these examples, you will need the import and configuration dictionaries below. Replace the config information with your credentials.
from ncdssdk import NCDSClient
security_cfg = {
"oauth.token.endpoint.uri": "https://{auth_endpoint_url}/auth/realms/demo/protocol/openid-connect/token",
"oauth.client.id": "client",
"oauth.client.secret": "client-secret"
}
kafka_cfg = {
"bootstrap.servers": "{streams_endpoint_url}:9094",
"auto.offset.reset": "earliest"
}
List all available data stream for the user
ncds_client = NCDSClient(security_cfg, kafka_cfg)
topics = ncds_client.list_topics_for_client()
print("Data set topics:")
for topic_entry in topics:
print(topic_entry)
Example output:
List of streams available on Nasdaq Cloud Data Service:
GIDS
NLSPLUS-UTP-V4
NLSPLUS-CTA-V4
This method returns the schema for the stream in Apache Avro format (https://avro.apache.org/docs/current/spec.html)
ncds_client = NCDSClient(security_cfg, kafka_cfg)
topic = "NLSPLUS-CTA-V4"
schema = ncds_client.get_schema_for_topic(topic)
print(schema)
Example output:
[ {
"type" : "record",
"name" : "SeqAdjClosingPrice",
"namespace" : "com.nasdaq.equities.trades.applications.nls.messaging.binary21",
"fields" : [ {
"name" : "SoupPartition",
"type" : "int"
}, {
"name" : "SoupSequence",
"type" : "long"
}, {
"name" : "trackingID",
"type" : "long"
}, {
"name" : "msgType",
"type" : "string"
}, {
"name" : "symbol",
"type" : "string"
}, {
"name" : "securityClass",
"type" : "string"
}, {
"name" : "adjClosingPrice",
"type" : "int"
} ],
"version" : "1"
}, {...
} .......
.... ]
ncds_client = NCDSClient(security_cfg, kafka_cfg)
topic = "NLSPLUS-CTA-V4"
records = ncds_client.top_messages(topic)
for i in range(0, 10):
print("key: ", records[i].key())
print("value: ", str(records[i].value()))
Example output:
Top 10 Records for the Topic: NLSPLUS-CTA-V4
key: 14600739
value: {"SoupPartition": 0, "SoupSequence": 14600739, "trackingID": 72000000024569, "msgType": "S", "event": "E", "schema_name": "SeqSystemEventMessage"}
key: 14600740
value: {"SoupPartition": 0, "SoupSequence": 14600740, "trackingID": 72900000006514, "msgType": "J", "symbol": "A", "securityClass": "N", "consHigh": 1487799, "consLow": 1466600, "consClose": 1478100, "cosolidatedVolume": 1259303, "consOpen": 1486800, "schema_name": "SeqEndOfDayTradeSummary"}
key: 14600741
value: {"SoupPartition": 0, "SoupSequence": 14600741, "trackingID": 72900000006514, "msgType": "J", "symbol": "AA", "securityClass": "N", "consHigh": 378039, "consLow": 366800, "consClose": 368400, "cosolidatedVolume": 6047752, "consOpen": 372000, "schema_name": "SeqEndOfDayTradeSummary"}
key: 14600742
value: {"SoupPartition": 0, "SoupSequence": 14600742, "trackingID": 72900000006514, "msgType": "