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

Metadata

Release files for ctrader_open_api 0.9.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.9.0
File Size Uploaded Provenance Actions
ctrader_open_api-0.9.0.tar.gz 26.1 kB Without provenance Details for ctrader_open_api-0.9.0.tar.gz

Built distribution (wheel)

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

Total release size: 55.2 kB

Release files / ctrader_open_api-0.9.0.tar.gz

Download URL ctrader_open_api-0.9.0.tar.gz
Size 26.1 kB
Tags Source
SHA-256 checksum
How to use checksums
aae9a62487a5f68cf6f086855c264ea26d9cf6dda37fd6d5652f6a682acfdada
BLAKE2b-256 checksum
How to use checksums
21b067f68171a534d8e2bfc2b939fdc91e9f2129d50f9ccbefa2bf005cdb7ff5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.10 Linux/5.11.0-1028-azure

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

Download URL ctrader_open_api-0.9.0-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eee4ce6decea69bf3fc815c14da03e6c6704714c45910f34ec60b3147692af3f
BLAKE2b-256 checksum
How to use checksums
3e3c544ffe0e9478b5e700b3bee923c2953dead357afb05b8f2d2eed997fdbe3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.10 Linux/5.11.0-1028-azure

Security for ctrader_open_api 0.9.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