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.4.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.4.0
File Size Uploaded Provenance Actions
ctrader_open_api-0.4.0.tar.gz 25.4 kB Without provenance Details for ctrader_open_api-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 53.9 kB

Release files / ctrader_open_api-0.4.0.tar.gz

Download URL ctrader_open_api-0.4.0.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
fc836b17be78f92ea6c82eac88922724f3538299e2f6a2cdc95f8e480ac8c1b6
BLAKE2b-256 checksum
How to use checksums
54b8523bfb42172ea5d38f9a42816ee363e65c340d43d53fae7a1282c1c0da98
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.4.0-py3-none-any.whl

Download URL ctrader_open_api-0.4.0-py3-none-any.whl
Size 28.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4d48695e390fd0145e4bda5ddc8ac807b29da2b5acca78220e2133ae74ac931
BLAKE2b-256 checksum
How to use checksums
b623d1d1bcae6997a38f855b3435df5eca0cf2a373043fb183c90d402f4218a4
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.4.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