Python Software Developement Kit for GTN Fintech API
Project description
Python SDK for GTN Embed
This is a lightweight SDK which wraps the REST APIs of the GTN Embed set as documented in the API Portal
installing packages
The GTN Embed SDK is now available on PyPi
pip install gtn-embed-sdk
API Authentication
The GTN Embed uses the notion of Institutions, which represent customers that build their platform upon the GTN Embed. The end-users of the institution, are referred to as customers. An institution is able to manage their customers directly and is also able to initiate actions on the user's behalf.
As describe in the API Portal you are required to authenticate first to the Institution and then as a customer. And resulting keys expire in a certain period, which require renewing using authentication APIs. However when using the SDK, key renewing is not required since it is handled by the SDK in background.
The api_url is the API hub where customers are connected to access the GTN Embed. This URL can change depending on
customer's registered country.
Initiating API connection
For a connection to be establish, it is required to have following information
API URL, provided by GTN. Can vary depending on the environment (Sandbox, UAT, Production)App Key, provided by GTNApp Secret, provided by GTNInstitutionCode, provided by GTNCustomer Numberof the customer initiating the connection. (Optional: only in the customer mode)Private Keyof the institution, provided by GTN
import gtnapi
api_credentials = {
"api_url": "https://api-mena-uat.globaltradingnetwork.com",
"app_key": "my-app-key",
"app_secret": "my-app-secret",
"institution": "MY-INST-CODE",
"customer_number": "12345678",
"private_key": "RTRGDBCNKVGJTURI49857YURIEOLFMKJTU5I4O847YRHFJDKDKVFLKTUEJFHRU"
}
status = gtnapi.init(**api_credentials)
authentication status is in the format
{
"http_status": 200,
"auth_status": "SUCCESS"
}
Once the gtnapi.init() is success (i.e. http_code == 200), it is possible to access any REST endpoint (authorised to the customer) by using the SDK.
Request, response parameter and formats are as per the API Documentation
Since the SDK is just a wrapper to the REST API, only following methods are available for API endpoints
gtnapi.Requests.get()- for HTTP GET endpointsgtnapi.Requests.post()- for HTTP POST endpointsgtnapi.Requests.patch()- for HTTP UPDATE endpointsgtnapi.Requests.delete()- for HTTP DELETE endpoints
and for streaming data
gtnapi.Streaming.TradeData- for receiving streaming Trade Datagtnapi.Streaming.MarketData- for receiving streaming Market Data
[!IMPORTANT] SDK does not provide anything not supported by the REST API. See API Documentation
Examples
Handling Customers
Creating a customer 
Call the HTTP Post method to the endpoint customer/account to create a customer
customer = {
"referenceNumber": "546446546",
"firstName": "Kevin",
"lastName": "Smith",
"passportNumber": "123456",
...
}
response = gtnapi.Requests.post('/trade/bo/v1.2.1/customer/account', **customer)
print(json.dumps(response, indent=4))
Getting customer details 
Call the HTTP Get method to the endpoint customer/account to get customer details
response = gtnapi.Requests.get('/trade/bo/v1.2.1/customer/account', customerNumber="12345678")
print(json.dumps(response, indent=4))
Response is in the format
{
"http_status" : 200, # http status of the api call as per the API documentation
"response" : {data dict} # response data of the api as per the API documentation
}
Initiate the Trade Data streaming connection 
Can initiate the session by passing endpoint, event type and call-back method references
gtnapi.Streaming.TradeData.connect('/trade/sse/v1.2.1', 'ORDER',
on_message=onMessage,
on_close=onClose,
on_error=onError)
Above connection will respond with Order related events when available. The sdk will call onMessage and other relevant methods when required with relevant data
Close the streaming connection
can close the Trade Streaming session by calling
gtnapi.Streaming.TradeData.disconnect()
Market Data APIs
Getting snapshot data 
search_params = {
"source-id": 'NSDQ',
"keys": "NSDQ~AAPL"
}
response = gtnapi.Requests.get('/market-data/realtime/keys/data', **search_params)
print(json.dumps(response, indent=4))
Initiate the Market Data streaming connection 
Can initiate the WS session by passing call-back method references
gtnapi.Streaming.MarketData.connect("/market-data/websocket/price",
on_message=onMessage, on_open=onOpen,
on_close=onClose, on_error=onError)
The sdk will call onMessage and other relevant methods when required with relevant data
Close the websocket connection
can close the WS session by calling
gtnapi.Streaming.MarketData.disconnect()
Terminate the API session
The while GTN Embed session will be terminated by calling the following.
gtnapi.stop()
Will terminate
- Access token refresh process
- Active Market Data streaming session
- Active Trade Data streaming session
[!IMPORTANT] Once the session is terminated, any attempt to access endpoints will result in an unauthorised response
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gtn_embed_sdk-1.0.1.tar.gz.
File metadata
- Download URL: gtn_embed_sdk-1.0.1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12ce2feff1394d1ab222a17e4557b48106561168d7c0ac66553b1bfc7858222b
|
|
| MD5 |
aa10748f402d0194784867bc1d6ca48a
|
|
| BLAKE2b-256 |
d3b63f09192834aa047168c02b95e792937943cb1492fd9f355cba1b6a1cf9e6
|
File details
Details for the file gtn_embed_sdk-1.0.1-py3-none-any.whl.
File metadata
- Download URL: gtn_embed_sdk-1.0.1-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfcdd01cb971beaa37ca5c3b5c02cf08ff72a4cad2c126183d0f6981ffc5b732
|
|
| MD5 |
e75141dd14d0733f94cb37ce10108225
|
|
| BLAKE2b-256 |
dd2b0b66713f6767a57f6aa169ea336fb50669017d7734aa33d0b900e3c50d85
|