-
Notifications
You must be signed in to change notification settings - Fork 1
/
ordersender.py
32 lines (27 loc) · 1.39 KB
/
ordersender.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
from logon import Logon
from createorder import CreateOrder
from tcpclient import TcpClient
from exceptions import ClosedConnection
class OrderSender(TcpClient):
def __init__(self, login, password, marshaller, host, port):
TcpClient.__init__(self, host, port)
self.login = login
self.password = password
self.marshaller = marshaller
self.handle_callbacks = {}
def on_connect(self):
logon = Logon(self.login, self.password)
encoded_logon = self.marshaller.encode_logon(logon)
self.output_message_stacks[self.server_socket].append(encoded_logon)
def push_order(self, way, price, quantity, instrument_identifier):
create_order = CreateOrder(way=way, price=price, quantity=quantity,
instrument_identifier=instrument_identifier)
encoded_create_order = self.marshaller.encode_create_order(create_order)
if not self.server_socket:
raise ClosedConnection
self.output_message_stacks[self.server_socket].append(encoded_create_order)
def on_read_from_server(self):
decoded_messages_count, self.received_buffer = self.marshaller.decode_buffer(self.received_buffer,
self.handle_callbacks)
if decoded_messages_count == 0:
print('--- No decoded messages ---')