Python client for Open Api 2

Created at 27 Feb 2020, 16:31
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
MA

marcussantos

Joined 13.12.2018

Python client for Open Api 2
27 Feb 2020, 16:31


HI !

I would like to share a Python client for Spotware Connect Open Api 2 which I just launched.

It is open source (GNU GPL-3) and very simple to use.

Sample code to get server version (ProtoOAVersionReq):

import spotware_connect as sc

c = sc.Client()

@c.event
def connect():
    c.emit("VersionReq")

@c.message(msgtype="VersionRes")
def version(msg, payload, version, **kargs):
    print("Server version: ", version)
    c.stop()

c.start(timeout=5) # optional timeout in seconds

If you enjoy, please star it: https://github.com/marcus-santos/spotware_connect


@marcussantos
Replies

shoaibmalek02
28 May 2021, 07:17

Account Authorization Not Working
# send a ProtoOAAccountAuthReq with data
c.emit("AccountAuthReq", ctidTraderAccountId=<cTraderID>,
       accessToken="<token>")
# handle ProtoOAAccountAuthRes messages
@c.message(msgtype="AccountAuthRes")
def on_account_auth_ok(**kargs):
    print("Account Authorized")
    c.stop()  # stops client

@shoaibmalek02