A Python package for interacting with cTrader Open API
Project description
OpenApiPy
A Python package for interacting with cTrader Open API.
This package uses Twisted and it works asynchronously.
- Free software: MIT
- Documentation: https://spotware.github.io/OpenApiPy/.
Features
-
Works asynchronously by using Twisted
-
Methods return Twisted deferreds
-
It contains the Open API messages files so you don't have to do the compilation
-
Makes handling request responses easy by using Twisted deferreds
Insallation
pip install ctrader-open-api
Usage
from ctrader_open_api import Client, Protobuf, TcpProtocol, Auth, EndPoints
from ctrader_open_api.messages.OpenApiCommonMessages_pb2 import *
from ctrader_open_api.messages.OpenApiCommonMessages_pb2 import *
from ctrader_open_api.messages.OpenApiMessages_pb2 import *
from ctrader_open_api.messages.OpenApiModelMessages_pb2 import *
from twisted.internet import reactor
hostType = input("Host (Live/Demo): ")
host = EndPoints.PROTOBUF_LIVE_HOST if hostType.lower() == "live" else EndPoints.PROTOBUF_DEMO_HOST
client = Client(host, EndPoints.PROTOBUF_PORT, TcpProtocol)
def onError(failure): # Call back for errors
print("Message Error: ", failure)
def connected(client): # Callback for client connection
print("\nConnected")
# Now we send a ProtoOAApplicationAuthReq
request = ProtoOAApplicationAuthReq()
request.clientId = "Your application Client ID"
request.clientSecret = "Your application Client secret"
# Client send method returns a Twisted deferred
deferred = client.send(request)
# You can use the returned Twisted deferred to attach callbacks
# for getting message response or error backs for getting error if something went wrong
# deferred.addCallbacks(onProtoOAApplicationAuthRes, onError)
deferred.addErrback(onError)
def disconnected(client, reason): # Callback for client disconnection
print("\nDisconnected: ", reason)
def onMessageReceived(client, message): # Callback for receiving all messages
print("Message received: \n", Protobuf.extract(message))
# Setting optional client callbacks
client.setConnectedCallback(connected)
client.setDisconnectedCallback(disconnected)
client.setMessageReceivedCallback(onMessageReceived)
# Starting the client service
client.startService()
# Run Twisted reactor
reactor.run()
Please check documentation or samples for a complete example.
Dependencies
Project details
Release history Release notifications | RSS feed
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 ctrader_open_api-0.9.2.tar.gz.
File metadata
- Download URL: ctrader_open_api-0.9.2.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1022-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81d651e13477268a12ad2da4ebcc80af71e1f8d0b0ab86a3480542e3ba8031eb
|
|
| MD5 |
3a0c7bd8f3eef01424f32d903d990857
|
|
| BLAKE2b-256 |
77f1811654a771166093ae15bb96a2e6a239de417ff852f9168ab6d9cc670b83
|
File details
Details for the file ctrader_open_api-0.9.2-py3-none-any.whl.
File metadata
- Download URL: ctrader_open_api-0.9.2-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1022-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd163d9c590b264196146cc3fb2e3daf42d7331148ab9b15e03dfa0685f0fc53
|
|
| MD5 |
5f88e7b81084bc79a497f04ea3abe1fa
|
|
| BLAKE2b-256 |
074f5495d4530d20abe9ac025332c0291e6d9370bb725a779085f82918b1fb99
|