├── .gitignore ├── README.md ├── acceptor ├── Logs │ └── GLOBAL.messages.current.log ├── application.py ├── model │ ├── Field.py │ ├── Message.py │ ├── __init__.py │ └── logger.py ├── server.cfg ├── server.py ├── spec │ ├── FIX40.xml │ ├── FIX41.xml │ ├── FIX42.xml │ ├── FIX43.xml │ ├── FIX44.xml │ ├── FIX50.xml │ ├── FIX50SP1.xml │ ├── FIX50SP2.xml │ └── FIXT11.xml └── start.sh ├── docker ├── .env ├── Dockerfile └── docker-compose.yml ├── initiator ├── Logs │ ├── GLOBAL.event.current.log │ └── GLOBAL.messages.current.log ├── application.py ├── client.cfg ├── client.py ├── model │ ├── Field.py │ ├── Message.py │ ├── __init__.py │ └── logger.py ├── spec │ ├── FIX40.xml │ ├── FIX41.xml │ ├── FIX42.xml │ ├── FIX43.xml │ ├── FIX44.xml │ ├── FIX50.xml │ ├── FIX50SP1.xml │ ├── FIX50SP2.xml │ └── FIXT11.xml └── start.sh └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.cpython-37.pyc 2 | *.pyc 3 | *.log 4 | .vscode 5 | __pycache__ 6 | /acceptor/Logs/* 7 | /acceptor/Sessions/* 8 | /initiator/Logs/* 9 | /initiator/Sessions/* 10 | /Pipfile 11 | /Pipfile.lock 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QuickFIX Python Samples # 2 | * Established connection by [FIX protocol](https://www.fixtrading.org/standards/) 3 | * Author: Rin Le . 4 | * Details: [Configuration for quickfix](https://www.quickfixj.org/usermanual/2.3.0/usage/configuration.html) 5 | 6 | ## Requirements 7 | * Python 3.x 8 | * [QuickFIX Engine 1.15.1](http://www.quickfixengine.org/) 9 | 10 | ## Installing Requirements 11 | ``` 12 | pip install -r requirements.txt 13 | ``` 14 | 15 | ## Run Project 16 | ### With Docker 17 | 18 | Please edit file initiator/client.cfg: Tag SocketConnectHost=acceptor 19 | 20 | ```sh 21 | cd ./docker 22 | docker-compose up --build 23 | ``` 24 | 25 | ### Without Docker 26 | 27 | Please edit file initiator/client.cfg: Tag SocketConnectHost=127.0.0.1
28 | *You must launch the server side first, then launch the client side for the quickfix to establish a standard FIX protocol connection.* 29 | 30 | #### Run Server 31 | ```sh 32 | cd ./acceptor 33 | python server.py server.cfg 34 | ``` 35 | 36 | #### Run Client 37 | ```sh 38 | cd ./initiator 39 | python client.py client.cfg 40 | ``` 41 | 42 | 43 | -------------------------------------------------------------------------------- /acceptor/Logs/GLOBAL.messages.current.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rinlevan/quickfix-python-samples/a01466247435046ae9f5b561f0bb3f99b9727c4f/acceptor/Logs/GLOBAL.messages.current.log -------------------------------------------------------------------------------- /acceptor/application.py: -------------------------------------------------------------------------------- 1 | """FIX Application""" 2 | import quickfix as fix 3 | import logging 4 | import time 5 | from model.logger import setup_logger 6 | __SOH__ = chr(1) 7 | 8 | setup_logger('logfix', 'Logs/message.log') 9 | logfix = logging.getLogger('logfix') 10 | 11 | class Application(fix.Application): 12 | """FIX Application""" 13 | orderID = 0 14 | execID = 0 15 | 16 | 17 | def onCreate(self, sessionID): 18 | """onCreate""" 19 | print("onCreate : Session (%s)" % sessionID.toString()) 20 | return 21 | 22 | def onLogon(self, sessionID): 23 | """onLogon""" 24 | self.sessionID = sessionID 25 | print("Successful Logon to session '%s'." % sessionID.toString()) 26 | return 27 | 28 | def onLogout(self, sessionID): 29 | """onLogout""" 30 | print("Session (%s) logout !" % sessionID.toString()) 31 | return 32 | 33 | def toAdmin(self, message, sessionID): 34 | msg = message.toString().replace(__SOH__, "|") 35 | logfix.debug("(Admin) S >> %s" % msg) 36 | return 37 | 38 | def fromAdmin(self, message, sessionID): 39 | msg = message.toString().replace(__SOH__, "|") 40 | logfix.debug("(Admin) R << %s" % msg) 41 | return 42 | 43 | def toApp(self, message, sessionID): 44 | msg = message.toString().replace(__SOH__, "|") 45 | logfix.debug("(App) S >> %s" % msg) 46 | return 47 | 48 | def fromApp(self, message, sessionID): 49 | msg = message.toString().replace(__SOH__, "|") 50 | logfix.debug("(App) R << %s" % msg) 51 | self.onMessage(message, sessionID) 52 | return 53 | 54 | 55 | def onMessage(self, message, sessionID): 56 | """Mockup execution report for newordersingle""" 57 | beginString = fix.BeginString() 58 | msgType = fix.MsgType() 59 | message.getHeader().getField( beginString ) 60 | message.getHeader().getField( msgType ) 61 | 62 | symbol = fix.Symbol() 63 | side = fix.Side() 64 | ordType = fix.OrdType() 65 | orderQty = fix.OrderQty() 66 | price = fix.Price() 67 | clOrdID = fix.ClOrdID() 68 | 69 | message.getField( ordType ) 70 | if ordType.getValue() != fix.OrdType_LIMIT: 71 | raise fix.IncorrectTagValue( ordType.getField() ) 72 | 73 | message.getField( symbol ) 74 | message.getField( side ) 75 | message.getField( orderQty ) 76 | message.getField( price ) 77 | message.getField( clOrdID ) 78 | 79 | executionReport = fix.Message() 80 | executionReport.getHeader().setField( beginString ) 81 | executionReport.getHeader().setField( fix.MsgType(fix.MsgType_ExecutionReport) ) 82 | 83 | executionReport.setField( fix.OrderID(self.genOrderID()) ) 84 | executionReport.setField( fix.ExecID(self.genExecID()) ) 85 | executionReport.setField( fix.OrdStatus(fix.OrdStatus_FILLED) ) 86 | executionReport.setField( symbol ) 87 | executionReport.setField( side ) 88 | executionReport.setField( fix.CumQty(orderQty.getValue()) ) 89 | executionReport.setField( fix.AvgPx(price.getValue()) ) 90 | executionReport.setField( fix.LastShares(orderQty.getValue()) ) 91 | executionReport.setField( fix.LastPx(price.getValue()) ) 92 | executionReport.setField( clOrdID ) 93 | executionReport.setField( orderQty ) 94 | 95 | if beginString.getValue() == fix.BeginString_FIX40 or beginString.getValue() == fix.BeginString_FIX41 or beginString.getValue() == fix.BeginString_FIX42: 96 | executionReport.setField( fix.ExecTransType(fix.ExecTransType_NEW) ) 97 | 98 | if beginString.getValue() >= fix.BeginString_FIX41: 99 | executionReport.setField( fix.ExecType(fix.ExecType_FILL) ) 100 | executionReport.setField( fix.LeavesQty(0) ) 101 | 102 | try: 103 | fix.Session.sendToTarget( executionReport, sessionID ) 104 | except fix.SessionNotFound as e: 105 | return 106 | 107 | def genOrderID(self): 108 | self.orderID += 1 109 | return str(self.orderID).zfill(5) 110 | 111 | def genExecID(self): 112 | self.execID += 1 113 | return str(self.execID).zfill(5) 114 | 115 | def run(self): 116 | """Run""" 117 | while 1: 118 | time.sleep(2) 119 | -------------------------------------------------------------------------------- /acceptor/model/Field.py: -------------------------------------------------------------------------------- 1 | BeginString = 8 2 | BodyLength = 9 3 | MsgType = 35 4 | SenderCompID = 49 5 | TargetCompID = 56 6 | TargetSubID = 57 7 | SenderSubID = 50 8 | MsgSeqNum = 34 9 | SendingTime = 52 10 | CheckSum = 10 11 | TestReqID = 112 12 | EncryptMethod = 98 13 | HeartBtInt = 108 14 | ResetSeqNum = 141 15 | Username = 553 16 | Password = 554 17 | Text = 58 18 | BeginSeqNo = 7 19 | EndSeqNo = 16 20 | GapFillFlag = 123 21 | NewSeqNo = 36 22 | MDReqID = 262 23 | SubscriptionRequestType = 263 24 | MarketDepth = 264 25 | MDUpdateType = 265 26 | NoMDEntryTypes = 267 27 | NoMDEntries = 268 28 | MDEntryType = 269 29 | NoRelatedSym = 146 30 | Symbol = 55 31 | MDEntryPx = 270 32 | MDUpdateAction = 279 33 | MDEntryID = 278 34 | MDEntrySize = 271 35 | ClOrdID = 11 36 | Side = 54 37 | TransactTime = 60 38 | OrderQty = 38 39 | OrdType = 40 40 | Price = 44 41 | StopPx = 99 42 | TimeInForce = 59 43 | ExpireTime = 126 44 | PosMaintRptID = 721 45 | OrderID = 37 46 | ExecType = 150 47 | OrdStatus = 39 48 | AvgPx = 6 49 | LeavesQty = 151 50 | CumQty = 14 51 | Currency = 15 52 | ExecID = 17 53 | OnBehalfOfSubID = 116 #note 54 | OnBehalfOfCompID = 115 #note 55 | OrigClOrdID = 41 56 | OrdRejReason = 103 57 | DeliverToCompID = 128 58 | DeliverToSubID = 129 59 | PossDupFlag = 43 60 | PossResend = 97 61 | OrigSendingTime = 122 62 | ClientID = 109 63 | Account = 1 64 | Commission = 12 65 | CommType = 13 66 | SettlmntTyp = 63 67 | FutSettDate = 64 68 | HandlInst = 21 69 | ExecInst = 18 70 | CxlType = 125 71 | ExDestination = 100 72 | IDSource = 22 73 | SecurityType = 167 74 | SecurityID = 48 75 | SettlCurrency = 120 76 | -------------------------------------------------------------------------------- /acceptor/model/Message.py: -------------------------------------------------------------------------------- 1 | from model import Field 2 | 3 | class Types(object): 4 | Logon = 'A' 5 | Heartbeat = '0' 6 | TestRequest = '1' 7 | Logout = '5' 8 | ResendRequest = '2' 9 | Reject = '3' 10 | SequenceReset = '4' 11 | MarketDataRequest = 'V' 12 | MarketDataSnapshot = 'W' 13 | MarketDataRefresh = 'X' 14 | NewOrder = 'D' 15 | ListOrder = 'E' 16 | OrderCancel = 'F' 17 | OrderCancelReplace = 'G' 18 | DontKnowTrade = 'Q' 19 | OrderStatus = 'H' 20 | ExecutionReport = '8' 21 | OrderCancelReject = '9' 22 | MessageReject = 'j' 23 | PositionRequest = 'AN' 24 | PositionReport = 'AP' 25 | 26 | __SOH__ = chr(1) 27 | 28 | def build_checksum(message): 29 | checksum = sum([ord(i) for i in list(message)]) % 256 30 | return make_pair((10, str(checksum).zfill(3))) 31 | 32 | 33 | def make_pair(pair): 34 | return str(pair[0]) + "=" + str(pair[1]) + __SOH__ 35 | 36 | 37 | class Base(object): 38 | default_session = None 39 | current_session = None 40 | msg_type = None 41 | fields = [] 42 | length = None 43 | string = None 44 | 45 | def __init__(self, fields=None, session=None): 46 | self.msg_type = None 47 | self.fields = [] 48 | 49 | if fields is None: 50 | fields = [] 51 | 52 | for pair in fields: 53 | self.set_field(pair) 54 | 55 | self.length = None 56 | self.string = None 57 | 58 | if not session and not self.default_session: 59 | raise RuntimeError('Session must be provided if default session is not set') 60 | 61 | if not session: 62 | self.current_session = self.default_session 63 | else: 64 | self.current_session = session 65 | 66 | def __getitem__(self, item): 67 | return self.get_field(item) 68 | 69 | def __setitem__(self, key, value): 70 | return self.set_field((key, value)) 71 | 72 | def get_type(self): 73 | return self.msg_type 74 | 75 | def get_field(self, field_type): 76 | for pair in self.fields: 77 | if str(pair[0]) == str(field_type): 78 | return pair[1] 79 | return b'' 80 | 81 | def set_field(self, pair): 82 | if str(pair[0]) == str(Field.MsgType): 83 | self.msg_type = pair[1] 84 | 85 | self.fields.append(pair) 86 | self.length = None 87 | self.string = None 88 | return self 89 | 90 | def get_all_by(self, field_type): 91 | result = [] 92 | for pair in self.fields: 93 | if str(pair[0]) == str(field_type): 94 | result.append(pair[1]) 95 | return result 96 | 97 | def get_group(self, group): 98 | result = [] 99 | for field_id in group: 100 | values = self.get_all_by(field_id) 101 | for i, value in enumerate(values): 102 | if len(result) - 1 < i: 103 | result.append({}) 104 | result[i][field_id] = value 105 | return result 106 | -------------------------------------------------------------------------------- /acceptor/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rinlevan/quickfix-python-samples/a01466247435046ae9f5b561f0bb3f99b9727c4f/acceptor/model/__init__.py -------------------------------------------------------------------------------- /acceptor/model/logger.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | def setup_logger(logger_name, log_file, level=logging.DEBUG): 4 | lz = logging.getLogger(logger_name) 5 | formatter = logging.Formatter('%(asctime)s : %(message)s') 6 | fileHandler = logging.FileHandler(log_file, mode='w') 7 | fileHandler.setFormatter(formatter) 8 | streamHandler = logging.StreamHandler() 9 | streamHandler.setFormatter(formatter) 10 | 11 | lz.setLevel(level) 12 | lz.addHandler(fileHandler) 13 | lz.addHandler(streamHandler) -------------------------------------------------------------------------------- /acceptor/server.cfg: -------------------------------------------------------------------------------- 1 | 2 | [DEFAULT] 3 | #settings which apply to all the Sessions. 4 | ConnectionType=acceptor 5 | #This specifies if you are creating an acceptor(Server) or initiator (Client) 6 | SocketReuseAddress=Y 7 | # FIX messages have a sequence ID, which shouldn't be used for uniqueness as specification doesn't guarantee anything about them. If Y is provided every time logon message is sent, server will reset the sequence. 8 | FileLogPath=./Logs/ 9 | #Path where logs will be written 10 | StartTime=00:00:00 11 | # Time when session starts and ends 12 | EndTime=00:00:00 13 | UseDataDictionary=Y 14 | #ReconnectInterval=60 15 | # LogoutTimeout=5 16 | # LogonTimeout=30 17 | # Time in seconds before reconnecting 18 | ResetOnLogon=Y 19 | ResetOnLogout=Y 20 | ResetOnDisconnect=Y 21 | SendRedundantResendRequests=Y 22 | #RefreshOnLogon=Y 23 | # ValidateLengthAndChecksum=Y 24 | 25 | # session definition 26 | [SESSION] 27 | BeginString=FIX.4.3 28 | SenderCompID=SERVER 29 | TargetCompID=CLIENT 30 | SocketAcceptPort=3000 31 | # Specifies if data dictionary will be used 32 | DataDictionary=./spec/FIX43.xml 33 | FileStorePath=./Sessions/ 34 | -------------------------------------------------------------------------------- /acceptor/server.py: -------------------------------------------------------------------------------- 1 | """Client FIX""" 2 | import sys 3 | import argparse 4 | import quickfix 5 | from application import Application 6 | 7 | def main(config_file): 8 | """Main""" 9 | try: 10 | settings = quickfix.SessionSettings(config_file) 11 | application = Application() 12 | storefactory = quickfix.FileStoreFactory(settings) 13 | logfactory = quickfix.FileLogFactory(settings) 14 | acceptor = quickfix.SocketAcceptor(application, storefactory, settings, logfactory) 15 | 16 | acceptor.start() 17 | application.run() 18 | acceptor.stop() 19 | 20 | 21 | except (quickfix.ConfigError, quickfix.RuntimeError) as e: 22 | print(e) 23 | acceptor.stop() 24 | sys.exit() 25 | 26 | if __name__=='__main__': 27 | parser = argparse.ArgumentParser(description='FIX Client') 28 | parser.add_argument('file_name', type=str, help='Name of configuration file') 29 | args = parser.parse_args() 30 | main(args.file_name) 31 | -------------------------------------------------------------------------------- /acceptor/spec/FIX40.xml: -------------------------------------------------------------------------------- 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 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 |
-------------------------------------------------------------------------------- /acceptor/spec/FIX41.xml: -------------------------------------------------------------------------------- 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 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | 1048 | 1049 | 1050 | 1051 | 1052 | 1053 | 1054 | 1055 | 1056 | 1057 | 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1065 | 1066 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | 1073 | 1074 | 1075 | 1076 | 1077 | 1078 | 1079 | 1080 | 1081 | 1082 | 1083 | 1084 | 1085 | 1086 | 1087 | 1088 | 1089 | 1090 | 1091 | 1092 | 1093 | 1094 | 1095 | 1096 | 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1108 | 1109 | 1110 | 1111 | 1112 | 1113 | 1114 | 1115 | 1116 | 1117 | 1118 | 1119 | 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1186 | 1187 | 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1194 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1235 | 1236 | 1237 | 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1252 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1269 | 1270 | 1271 | 1272 | 1273 | 1274 | 1275 | 1276 | 1277 | 1278 | 1279 | 1280 | 1281 | 1282 | 1283 | 1284 | 1285 |
-------------------------------------------------------------------------------- /acceptor/spec/FIXT11.xml: -------------------------------------------------------------------------------- 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 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 |
314 | -------------------------------------------------------------------------------- /acceptor/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd ./acceptor 3 | python server.py server.cfg 4 | -------------------------------------------------------------------------------- /docker/.env: -------------------------------------------------------------------------------- 1 | APP_PORT=3000 2 | WORKING_DIR=/app 3 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.7.3 2 | ENV WORKING_DIR /app 3 | WORKDIR ${WORKING_DIR} 4 | COPY ./requirements.txt ${WORKING_DIR}/requirements.txt 5 | RUN pip install -U pip && pip install -r ${WORKING_DIR}/requirements.txt 6 | ADD . ${WORKING_DIR} 7 | RUN rm -fr ${WORKING_DIR}/initiator/Logs/* 8 | RUN rm -fr ${WORKING_DIR}/initiator/Sessions/* 9 | RUN rm -fr ${WORKING_DIR}/acceptor/Logs/* 10 | RUN rm -fr ${WORKING_DIR}/acceptor/Sessions/* 11 | -------------------------------------------------------------------------------- /docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | acceptor: 5 | build: 6 | context: ../ 7 | dockerfile: ./docker/Dockerfile 8 | restart: always 9 | working_dir: ${WORKING_DIR} 10 | volumes: 11 | - ../:${WORKING_DIR} 12 | command: 13 | - ${WORKING_DIR}/acceptor/start.sh 14 | stdin_open: true 15 | tty: true 16 | env_file: 17 | - .env 18 | ports: 19 | - ${APP_PORT}:${APP_PORT} 20 | networks: 21 | - quickfix 22 | 23 | initiator: 24 | build: 25 | context: ../ 26 | dockerfile: ./docker/Dockerfile 27 | restart: always 28 | working_dir: ${WORKING_DIR} 29 | volumes: 30 | - ../:${WORKING_DIR} 31 | command: 32 | - ${WORKING_DIR}/initiator/start.sh 33 | stdin_open: true 34 | tty: true 35 | env_file: 36 | - .env 37 | links: 38 | - acceptor 39 | networks: 40 | - quickfix 41 | 42 | networks: 43 | quickfix: 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /initiator/Logs/GLOBAL.event.current.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rinlevan/quickfix-python-samples/a01466247435046ae9f5b561f0bb3f99b9727c4f/initiator/Logs/GLOBAL.event.current.log -------------------------------------------------------------------------------- /initiator/Logs/GLOBAL.messages.current.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rinlevan/quickfix-python-samples/a01466247435046ae9f5b561f0bb3f99b9727c4f/initiator/Logs/GLOBAL.messages.current.log -------------------------------------------------------------------------------- /initiator/application.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf8 -*- 3 | """FIX Application""" 4 | import sys 5 | import quickfix as fix 6 | import time 7 | import logging 8 | from datetime import datetime 9 | from model.logger import setup_logger 10 | __SOH__ = chr(1) 11 | 12 | # Logger 13 | setup_logger('logfix', 'Logs/message.log') 14 | logfix = logging.getLogger('logfix') 15 | 16 | 17 | class Application(fix.Application): 18 | """FIX Application""" 19 | ClOrdID = 0 20 | 21 | def onCreate(self, sessionID): 22 | print("onCreate : Session (%s)" % sessionID.toString()) 23 | return 24 | 25 | def onLogon(self, sessionID): 26 | self.sessionID = sessionID 27 | print("Successful Logon to session '%s'." % sessionID.toString()) 28 | return 29 | 30 | def onLogout(self, sessionID): 31 | print("Session (%s) logout !" % sessionID.toString()) 32 | return 33 | 34 | def toAdmin(self, message, sessionID): 35 | msg = message.toString().replace(__SOH__, "|") 36 | logfix.info("(Admin) S >> %s" % msg) 37 | return 38 | def fromAdmin(self, message, sessionID): 39 | msg = message.toString().replace(__SOH__, "|") 40 | logfix.info("(Admin) R << %s" % msg) 41 | return 42 | def toApp(self, message, sessionID): 43 | msg = message.toString().replace(__SOH__, "|") 44 | logfix.info("(App) S >> %s" % msg) 45 | return 46 | def fromApp(self, message, sessionID): 47 | msg = message.toString().replace(__SOH__, "|") 48 | logfix.info("(App) R << %s" % msg) 49 | self.onMessage(message, sessionID) 50 | return 51 | 52 | def onMessage(self, message, sessionID): 53 | """Processing application message here""" 54 | pass 55 | 56 | def genClOrdID(self): 57 | """Generate ClOrdID""" 58 | self.ClOrdID += 1 59 | return str(self.ClOrdID).zfill(5) 60 | 61 | def put_new_order(self): 62 | """Request sample new order single""" 63 | message = fix.Message() 64 | header = message.getHeader() 65 | 66 | header.setField(fix.MsgType(fix.MsgType_NewOrderSingle)) #39 = D 67 | 68 | message.setField(fix.ClOrdID(self.genClOrdID())) #11 = Unique Sequence Number 69 | message.setField(fix.Side(fix.Side_BUY)) #43 = 1 BUY 70 | message.setField(fix.Symbol("MSFT")) #55 = MSFT 71 | message.setField(fix.OrderQty(10000)) #38 = 1000 72 | message.setField(fix.Price(100)) 73 | message.setField(fix.OrdType(fix.OrdType_LIMIT)) #40=2 Limit Order 74 | message.setField(fix.HandlInst(fix.HandlInst_MANUAL_ORDER_BEST_EXECUTION)) #21 = 3 75 | message.setField(fix.TimeInForce('0')) 76 | message.setField(fix.Text("NewOrderSingle")) 77 | trstime = fix.TransactTime() 78 | trstime.setString(datetime.now().strftime("%Y%m%d-%H:%M:%S.%f")[:-3]) 79 | message.setField(trstime) 80 | 81 | fix.Session.sendToTarget(message, self.sessionID) 82 | 83 | def run(self): 84 | """Run""" 85 | while 1: 86 | options = str(input("Please choose 1 for Put New Order or 2 for Exit!\n")) 87 | if options == '1': 88 | self.put_new_order() 89 | print("Done: Put New Order\n") 90 | continue 91 | if options == '2': 92 | sys.exit(0) 93 | else: 94 | print("Valid input is 1 for order, 2 for exit\n") 95 | time.sleep(2) 96 | -------------------------------------------------------------------------------- /initiator/client.cfg: -------------------------------------------------------------------------------- 1 | # This is a client (initiator) 2 | [DEFAULT] 3 | DefaultApplVerID=FIX.4.3 4 | #settings which apply to all the Sessions. 5 | ConnectionType=initiator 6 | # FIX messages have a sequence ID, which shouldn't be used for uniqueness as specification doesn't guarantee anything about them. If Y is provided every time logon message is sent, server will reset the sequence. 7 | FileLogPath=./Logs/ 8 | #Path where logs will be written 9 | StartTime=00:00:00 10 | # Time when session starts and ends 11 | EndTime=00:00:00 12 | UseDataDictionary=Y 13 | #Time in seconds before your session will expire, keep sending heartbeat requests if you don't want it to expire 14 | ReconnectInterval=60 15 | LogoutTimeout=5 16 | LogonTimeout=30 17 | # Time in seconds before reconnecting 18 | ResetOnLogon=Y 19 | ResetOnLogout=Y 20 | ResetOnDisconnect=Y 21 | SendRedundantResendRequests=Y 22 | # RefreshOnLogon=Y 23 | SocketNodelay=N 24 | # PersistMessages=Y 25 | ValidateUserDefinedFields=N 26 | ValidateFieldsOutOfOrder=N 27 | # CheckLatency=Y 28 | 29 | 30 | # session definition 31 | [SESSION] 32 | BeginString=FIX.4.3 33 | SenderCompID=CLIENT 34 | TargetCompID=SERVER 35 | HeartBtInt=30 36 | SocketConnectPort=3000 37 | SocketConnectHost=127.0.0.1 38 | DataDictionary=./spec/FIX43.xml 39 | FileStorePath=./Sessions/ 40 | -------------------------------------------------------------------------------- /initiator/client.py: -------------------------------------------------------------------------------- 1 | """FIX GATEWAY""" 2 | import sys 3 | import argparse 4 | import quickfix 5 | from application import Application 6 | 7 | def main(config_file): 8 | """Main""" 9 | try: 10 | settings = quickfix.SessionSettings(config_file) 11 | application = Application() 12 | storefactory = quickfix.FileStoreFactory(settings) 13 | logfactory = quickfix.FileLogFactory(settings) 14 | initiator = quickfix.SocketInitiator(application, storefactory, settings, logfactory) 15 | 16 | initiator.start() 17 | application.run() 18 | initiator.stop() 19 | 20 | except (quickfix.ConfigError, quickfix.RuntimeError) as e: 21 | print(e) 22 | initiator.stop() 23 | sys.exit() 24 | 25 | if __name__=='__main__': 26 | parser = argparse.ArgumentParser(description='FIX Client') 27 | parser.add_argument('file_name', type=str, help='Name of configuration file') 28 | args = parser.parse_args() 29 | main(args.file_name) 30 | -------------------------------------------------------------------------------- /initiator/model/Field.py: -------------------------------------------------------------------------------- 1 | BeginString = 8 2 | BodyLength = 9 3 | MsgType = 35 4 | SenderCompID = 49 5 | TargetCompID = 56 6 | TargetSubID = 57 7 | SenderSubID = 50 8 | MsgSeqNum = 34 9 | SendingTime = 52 10 | CheckSum = 10 11 | TestReqID = 112 12 | EncryptMethod = 98 13 | HeartBtInt = 108 14 | ResetSeqNum = 141 15 | Username = 553 16 | Password = 554 17 | Text = 58 18 | BeginSeqNo = 7 19 | EndSeqNo = 16 20 | GapFillFlag = 123 21 | NewSeqNo = 36 22 | MDReqID = 262 23 | SubscriptionRequestType = 263 24 | MarketDepth = 264 25 | MDUpdateType = 265 26 | NoMDEntryTypes = 267 27 | NoMDEntries = 268 28 | MDEntryType = 269 29 | NoRelatedSym = 146 30 | Symbol = 55 31 | MDEntryPx = 270 32 | MDUpdateAction = 279 33 | MDEntryID = 278 34 | MDEntrySize = 271 35 | ClOrdID = 11 36 | Side = 54 37 | TransactTime = 60 38 | OrderQty = 38 39 | OrdType = 40 40 | Price = 44 41 | StopPx = 99 42 | TimeInForce = 59 43 | ExpireTime = 126 44 | PosMaintRptID = 721 45 | OrderID = 37 46 | ExecType = 150 47 | OrdStatus = 39 48 | AvgPx = 6 49 | LeavesQty = 151 50 | CumQty = 14 51 | Currency = 15 52 | ExecID = 17 53 | ExecRefID = 19 54 | ExecTransType=20 55 | OnBehalfOfSubID = 116 56 | OnBehalfOfCompID = 115 57 | OrigClOrdID = 41 58 | OrdRejReason = 103 59 | DeliverToCompID = 128 60 | DeliverToSubID = 129 61 | PossDupFlag = 43 62 | PossResend = 97 63 | OrigSendingTime = 122 64 | ClientID = 109 65 | Account = 1 66 | Commission = 12 67 | CommType = 13 68 | SettlmntTyp = 63 69 | FutSettDate = 64 70 | HandlInst = 21 71 | ExecInst = 18 72 | CxlType = 125 73 | ExDestination = 100 74 | IDSource = 22 75 | SecurityType = 167 76 | SecurityID = 48 77 | SettlCurrency = 120 78 | SecurityExchange = 207 79 | DKReason = 127 80 | RefSeqNum = 45 81 | RefMsgType = 372 82 | BusinessRejectRefID = 379 83 | BusinessRejectReason = 380 84 | 85 | -------------------------------------------------------------------------------- /initiator/model/Message.py: -------------------------------------------------------------------------------- 1 | from model import Field 2 | 3 | class Types(object): 4 | Logon = 'A' 5 | Heartbeat = '0' 6 | TestRequest = '1' 7 | Logout = '5' 8 | ResendRequest = '2' 9 | Reject = '3' 10 | SequenceReset = '4' 11 | MarketDataRequest = 'V' 12 | MarketDataSnapshot = 'W' 13 | MarketDataRefresh = 'X' 14 | NewOrderSingle = 'D' 15 | ListOrder = 'E' 16 | OrderCancel = 'F' 17 | OrderCancelReplace = 'G' 18 | DontKnowTrade = 'Q' 19 | OrderStatus = 'H' 20 | ExecutionReport = '8' 21 | OrderCancelReject = '9' 22 | BusinessMessageReject = 'j' 23 | PositionRequest = 'AN' 24 | PositionReport = 'AP' 25 | 26 | __SOH__ = chr(1) 27 | 28 | def build_checksum(message): 29 | checksum = sum([ord(i) for i in list(message)]) % 256 30 | return make_pair((10, str(checksum).zfill(3))) 31 | 32 | 33 | def make_pair(pair): 34 | return str(pair[0]) + "=" + str(pair[1]) + __SOH__ 35 | 36 | class Base(object): 37 | default_session = None 38 | current_session = None 39 | 40 | def __init__(self, fields=None, session=None): 41 | self.msg_type = None 42 | self.fields = [] 43 | 44 | if fields is None: 45 | fields = [] 46 | 47 | for pair in fields: 48 | self.set_field(pair) 49 | 50 | self.length = None 51 | self.string = None 52 | 53 | if not session and not self.default_session: 54 | raise RuntimeError('Session must be provided if default session is not set') 55 | 56 | if not session: 57 | self.current_session = self.default_session 58 | else: 59 | self.current_session = session 60 | 61 | def __getitem__(self, item): 62 | return self.get_field(item) 63 | 64 | def __setitem__(self, key, value): 65 | return self.set_field((key, value)) 66 | 67 | def toString(self): 68 | return self.string.replace(__SOH__, "|") 69 | 70 | def get_type(self): 71 | return self.msg_type 72 | 73 | def get_field(self, field_type): 74 | for pair in self.fields: 75 | if str(pair[0]) == str(field_type): 76 | return pair[1] 77 | return None 78 | 79 | def set_field(self, pair): 80 | if str(pair[0]) == str(Field.MsgType): 81 | self.msg_type = pair[1] 82 | 83 | self.fields.append(pair) 84 | # self.length = None 85 | # self.string = None 86 | return self 87 | 88 | def get_all_by(self, field_type): 89 | result = [] 90 | for pair in self.fields: 91 | if str(pair[0]) == str(field_type): 92 | result.append(pair[1]) 93 | return result 94 | 95 | def get_group(self, group): 96 | result = [] 97 | for field_id in group: 98 | values = self.get_all_by(field_id) 99 | for i, value in enumerate(values): 100 | if len(result) - 1 < i: 101 | result.append({}) 102 | result[i][field_id] = value 103 | return result 104 | 105 | def parse_string(self, string, session): 106 | result = Base(None, session) 107 | for pair in string.split(__SOH__): 108 | if len(pair): 109 | values = pair.split('=') 110 | if len(values) == 2: 111 | result.set_field((values[0], values[1])) 112 | result.string = string 113 | return result 114 | -------------------------------------------------------------------------------- /initiator/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rinlevan/quickfix-python-samples/a01466247435046ae9f5b561f0bb3f99b9727c4f/initiator/model/__init__.py -------------------------------------------------------------------------------- /initiator/model/logger.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf8 -*- 3 | import logging 4 | def setup_logger(logger_name, log_file, level=logging.INFO): 5 | lz = logging.getLogger(logger_name) 6 | formatter = logging.Formatter('%(asctime)s : %(message)s') 7 | fileHandler = logging.FileHandler(log_file, mode='w') 8 | fileHandler.setFormatter(formatter) 9 | lz.setLevel(level) 10 | lz.addHandler(fileHandler) 11 | streamHandler = logging.StreamHandler() 12 | streamHandler.setFormatter(formatter) 13 | lz.addHandler(streamHandler) -------------------------------------------------------------------------------- /initiator/spec/FIX40.xml: -------------------------------------------------------------------------------- 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 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 |
-------------------------------------------------------------------------------- /initiator/spec/FIXT11.xml: -------------------------------------------------------------------------------- 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 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 |
314 | -------------------------------------------------------------------------------- /initiator/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd ./initiator 3 | sleep 5 4 | python client.py client.cfg 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | quickfix==1.15.1 2 | --------------------------------------------------------------------------------