Skip to main content

OpenApiPy

PyPI version versions GitHub license

A Python package for interacting with cTrader Open API.

This package uses Twisted and it works asynchronously.

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(_): # 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(reason): # Callback for client disconnection
    print("\nDisconnected: ", reason)

def onMessageReceived(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

Metadata

Release files for ctrader_open_api 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ctrader_open_api 0.6.0
File Size Uploaded Provenance Actions
ctrader_open_api-0.6.0.tar.gz 25.8 kB Without provenance Details for ctrader_open_api-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ctrader_open_api 0.6.0
File Interpreter ABI Platform Actions
ctrader_open_api-0.6.0-py3-none-any.whl Python 3 none any Details for ctrader_open_api-0.6.0-py3-none-any.whl

Total release size: 54.8 kB

Release files / ctrader_open_api-0.6.0.tar.gz

Download URL ctrader_open_api-0.6.0.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5cfbce8c86022b0fba714b442bea34820533ceae00214038a5a6ec433be939df
BLAKE2b-256 checksum
How to use checksums
277ca4dae97e9d71b1a74943200cd642cb54d849e4f06c0ee0ec14a9555852c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1022-azure

Release files / ctrader_open_api-0.6.0-py3-none-any.whl

Download URL ctrader_open_api-0.6.0-py3-none-any.whl
Size 28.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b24217a8865cfc9b55e552ae5afc88032a276e8277faad7784549a5e4206ede
BLAKE2b-256 checksum
How to use checksums
b6af296c1b82182b7318cdb8cbe4ad75c8c226a04ffdd7c7f3b782b93ed2d779
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1022-azure

Security for ctrader_open_api 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page