Repository navigation
Expand file tree
/
Copy pathclient.py
More file actions
104 lines (96 loc) · 3.22 KB
/
Copy pathclient.py
File metadata and controls
104 lines (96 loc) · 3.22 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import sys
import time
import thread
import argparse
from datetime import datetime
import quickfix as fix
from tools.echo import echo
ECHO_DEBUG=True
if ECHO_DEBUG:
from tools.echo import echo
else:
def echo(f):
def decorated(*args, **kwargs):
f(*args, **kwargs)
return decorated
class Application(fix.Application):
orderID = 0
execID = 0
def gen_ord_id(self):
global orderID
orderID+=1
return orderID
@echo
def onCreate(self, sessionID):
return
@echo
def onLogon(self, sessionID):
self.sessionID = sessionID
print ("Successful Logon to session '%s'." % sessionID.toString())
return
@echo
def onLogout(self, sessionID): return
@echo
def toAdmin(self, sessionID, message):
return
@echo
def fromAdmin(self, sessionID, message):
return
@echo
def toApp(self, sessionID, message):
print "Recieved the following message: %s" % message.toString()
return
@echo
def fromApp(self, message, sessionID):
return
@echo
def genOrderID(self):
self.orderID = self.orderID+1
return `self.orderID`
@echo
def genExecID(self):
self.execID = self.execID+1
return `self.execID`
def put_order(self):
print("Creating the following order: ")
trade = fix.Message()
trade.getHeader().setField(fix.BeginString(fix.BeginString_FIX42)) #
trade.getHeader().setField(fix.MsgType(fix.MsgType_NewOrderSingle)) #39=D
trade.setField(fix.ClOrdID(self.genExecID())) #11=Unique order
trade.setField(fix.HandlInst(fix.HandlInst_MANUAL_ORDER_BEST_EXECUTION)) #21=3 (Manual order, best executiona)
trade.setField(fix.Symbol('SMBL')) #55=SMBL ?
trade.setField(fix.Side(fix.Side_BUY)) #43=1 Buy
trade.setField(fix.OrdType(fix.OrdType_LIMIT)) #40=2 Limit order
trade.setField(fix.OrderQty(100)) #38=100
trade.setField(fix.Price(10))
trade.setField(fix.TransactTime(int(datetime.utcnow().strftime("%s"))))
print trade.toString()
fix.Session.sendToTarget(trade, self.sessionID)
def main(config_file):
try:
settings = fix.SessionSettings( config_file )
application = Application()
storeFactory = fix.FileStoreFactory( settings )
logFactory = fix.FileLogFactory( settings )
initiator = fix.SocketInitiator( application, storeFactory, settings, logFactory )
initiator.start()
while 1:
input = raw_input()
if input == '1':
print "Putin Order"
application.put_order()
if input == '2':
sys.exit(0)
if input == 'd':
import pdb
pdb.set_trace()
else:
print "Valid input is 1 for order, 2 for exit"
continue
except (fix.ConfigError, fix.RuntimeError), e:
print e
if __name__=='__main__':
parser = argparse.ArgumentParser(description='FIX Client')
parser.add_argument('file_name', type=str, help='Name of configuration file')
args = parser.parse_args()
main(args.file_name)