forked from cqg/WebAPIPythonSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4account.py
43 lines (37 loc) · 1.52 KB
/
4account.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from WebAPI.webapi_2_pb2 import *
from WebAPI import webapi_client
host_name = 'wss://demoapi.cqg.com:443'
user_name = ''
password = ''
def logon(user_name, password,
client_app_id='WebApiTest', client_version='python-client-test-2-87',
protocol_version_major=2,protocol_version_minor = 87):
client_msg = ClientMsg()
logon = client_msg.logon
logon.user_name = user_name
logon.password = password
logon.client_app_id = client_app_id
logon.client_version = client_version
logon.protocol_version_major = protocol_version_major
logon.protocol_version_minor = protocol_version_minor
client.send_client_message(client_msg)
server_msg = client.receive_server_message()
if server_msg.logon_result.result_code == 0:
return server_msg.logon_result.base_time
else:
raise Exception("Can't login: " + server_msg.logon_result.text_message)
# Request for all accounts this user is authorized to trade/monitor
# Accounts are grouped by sales series, which are grouped by brokerages
def resolve_account(msg_id=1, subscribe=None):
client_msg = ClientMsg()
information_request = client_msg.information_requests.add()
information_request.id = msg_id
information_request.accounts_request.SetInParent()
client.send_client_message(client_msg)
server_msg = client.receive_server_message()
if __name__ == "__main__":
client = webapi_client.WebApiClient()
client.connect(host_name)
logon(user_name, password)
resolve_account()
client.disconnect()