def quote_response(self,quote_req_id,quote_id,quote_resp_type,symbol,product,side,dealer_id,price=None,currency = None,quantity = None): #HEADER quote_resp = fix50sp2.QuoteRequest() quote_resp.getHeader().setField(fix.StringField(8,'FIXT.1.1')) #BeginMessage quote_resp.getHeader().setField(fix.StringField(35,'AJ'))#MessageType quote_resp.getHeader().setField(fix.StringField(1128,'9')) #ApplVerID - FIX50SP2 quote_resp.getHeader().setField(fix.StringField(49,'ORP_RESZ_B')) quote_resp.getHeader().setField(fix.StringField(56,'BLPORPBETA')) quote_resp.getHeader().setField(fix.StringField(128,'DOR')) quote_resp.getHeader().setField(fix.SendingTime(1))#52 quote_resp.getHeader().setField(fix.StringField(1156,'208'))#ApplExtID quote_resp.getHeader().setField(fix.StringField(1129,'1.5'))#CstmApplVerID quote_resp.getHeader().setField(fix.SendingTime(1)) #BODY quote_resp.setField(fix.QuoteRespID(quote_req_id[:-4] + 'RESP' + self.genOrderID()))#693 quote_resp.setField(fix.QuoteReqID(quote_req_id)) #131 quote_resp.setField(fix.QuoteRespType(quote_resp_type))#694 quote_resp.setField(fix.Symbol(symbol))#55 quote_resp.setField(fix.Product(int(product)))#460 quote_resp.setField(fix.Side(side))#54 quote_resp.setField(fix.StringField(167,'FXSPOT')) print(datetime.datetime.utcnow().strftime('%Y%m%d-%H:%M:%S')) quote_resp.setField(fix.StringField(60,datetime.datetime.utcnow().strftime('%Y%m%d-%H:%M:%S')))#60 # quote_resp.setField(fix.TransactTime(1))#60 quote_resp.setField(fix.SettlType('0'))#63 settl_date = datetime.datetime.utcnow()+BDay(n=2) quote_resp.setField(fix.SettlDate(settl_date.strftime('%Y%m%d')))#64 if quote_resp_type == 1: # quote_resp.setField(fix.Price(float(price))) quote_resp.setField(fix.OfferPx(float(price))) quote_resp.setField(fix.OfferSpotRate(float(price))) quote_resp.setField(fix.StringField(15, str(currency))) # Currency # quote_resp.setField(fix.BidPx(float(price))) quote_resp.setField(fix.QuoteID(quote_id)) # 117 quote_resp.setField(fix.OrderQty(quantity)) #38 quote_resp.setField(fix.ClOrdID(quote_resp.getField(693)+self.genOrderID())) # 11 group_453 = fix50sp2.QuoteRequest().NoRelatedSym().NoPartyIDs() group_453.setField(fix.StringField(448,'7613723'))#PartyID group_453.setField(fix.StringField(447,'D'))#PartyIDSource group_453.setField(fix.PartyRole(11))#452 - PartyRole quote_resp.addGroup(group_453) group_453.setField(fix.StringField(448,dealer_id))#PartyID group_453.setField(fix.StringField(447,'D'))#PartyIDSource group_453.setField(fix.PartyRole(1))#452 - PartyRole. quote_resp.addGroup(group_453) quote_resp.setField(fix.StringField(1300,'XOFF'))#market segment id print(f'SENDING QUOTE RESPONSE MESSAGE:\n ') # print(f'SENDING QUOTE RESPONSE MESSAGE:\n {quote_resp.toString()}') fix.Session.sendToTarget(quote_resp, self.sessionID)
def queryEnterOrder(self): print("\nTradeCaptureReport (AE)\n") trade = fix.Message() trade.getHeader().setField(fix.BeginString(fix.BeginString_FIX44)) trade.getHeader().setField(fix.MsgType(fix.MsgType_TradeCaptureReport)) trade.setField(fix.TradeReportTransType( fix.TradeReportTransType_NEW)) # 487 trade.setField(fix.TradeReportID(self.genTradeReportID())) # 571 trade.setField(fix.TrdSubType(4)) # 829 trade.setField(fix.SecondaryTrdType(2)) # 855 trade.setField(fix.Symbol("MYSYMBOL")) # 55 trade.setField(fix.LastQty(22)) # 32 trade.setField(fix.LastPx(21.12)) # 31 trade.setField(fix.TradeDate( (datetime.now().strftime("%Y%m%d")))) # 75 trade.setField( fix.TransactTime( (datetime.now().strftime("%Y%m%d-%H:%M:%S.%f"))[:-3])) # 60 trade.setField(fix.PreviouslyReported(False)) # 570 group = fix44.TradeCaptureReport().NoSides() group.setField(fix.Side(fix.Side_SELL)) # 54 group.setField(fix.OrderID(self.genOrderID())) # 37 group.setField(fix.NoPartyIDs(1)) # 453 group.setField( fix.PartyIDSource( fix.PartyIDSource_PROPRIETARY_CUSTOM_CODE)) # 447 group.setField(fix.PartyID("CLEARING")) # 448 group.setField(fix.PartyRole(fix.PartyRole_CLEARING_ACCOUNT)) # 452 trade.addGroup(group) group.setField(fix.Side(fix.Side_BUY)) # 54 group.setField(fix.OrderID(self.genOrderID())) # 37 group.setField(fix.NoPartyIDs(1)) # 453 group.setField( fix.PartyIDSource( fix.PartyIDSource_PROPRIETARY_CUSTOM_CODE)) # 447 group.setField(fix.PartyID("CLEARING")) # 448 group.setField(fix.PartyRole(fix.PartyRole_CLEARING_ACCOUNT)) # 452 trade.addGroup(group) fix.Session.sendToTarget(trade, self.sessionID)
def quote_request(self,symbol,currency,quantity,side,order_type,price=None): #HEADER trade = fix50sp2.QuoteRequest() trade.getHeader().setField(fix.StringField(8,'FIXT.1.1')) #BeginMessage trade.getHeader().setField(fix.StringField(35,'R'))#MessageType trade.getHeader().setField(fix.StringField(1128,'9')) #ApplVerID - FIX50SP2 trade.getHeader().setField(fix.StringField(49,'ORP_RESZ_B')) trade.getHeader().setField(fix.StringField(56,'BLPORPBETA')) trade.getHeader().setField(fix.StringField(128,'DOR')) trade.getHeader().setField(fix.SendingTime(1))#52 trade.getHeader().setField(fix.StringField(1156,'208'))#ApplExtID trade.getHeader().setField(fix.StringField(1129,'1.5'))#CstmApplVerID #BODY trade.setField(fix.QuoteReqID(datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S') + symbol + 'RFQ' + str(side))) # 131 group_146 = fix50sp2.QuoteRequest().NoRelatedSym() # group_146 = fix.Group(146,1) if '/' not in symbol: group_146.setField(fix.StringField(55,str(symbol[:3]+'/'+symbol[3:]))) else: group_146.setField(fix.StringField(55, str(symbol))) group_146.setField(fix.StringField(167,'FXSPOT')) group_146.setField(fix.IntField(460,4)) group_146.setField(fix.SettlType('0'))#SettlType # group_146.setField(fix.StringField(63,'0'))#SettlType settl_date = datetime.datetime.utcnow()+BDay(n=2) group_146.setField(fix.SettlDate(settl_date.strftime('%Y%m%d')))#SettlDate group_146.setField(fix.OrderQty(quantity))#38 - Qty group_146.setField(fix.StringField(15,str(currency)))#Currency group_146.setField(fix.StringField(54,str(side))) # trade.setField(fix.NoPartyIDs(4))#453 - NumberOfParties group_453 = fix50sp2.QuoteRequest().NoRelatedSym().NoPartyIDs() # group_453 = fix.Group(453,1) group_453.setField(fix.StringField(448,'7613723'))#PartyID group_453.setField(fix.StringField(447,'D'))#PartyIDSource group_453.setField(fix.PartyRole(11))#452 - PartyRole group_146.addGroup(group_453) group_453.setField(fix.StringField(448,'BGD1'))#PartyID group_453.setField(fix.StringField(447,'D'))#PartyIDSource group_453.setField(fix.PartyRole(1))#452 - PartyRole. group_146.addGroup(group_453) group_453.setField(fix.StringField(448,'DOR1'))#PartyID group_453.setField(fix.StringField(447,'D'))#PartyIDSource group_453.setField(fix.PartyRole(1))#452 - PartyRole. group_146.addGroup(group_453) group_453.setField(fix.StringField(448,'DOR2'))#PartyID group_453.setField(fix.StringField(447,'D'))#PartyIDSource group_453.setField(fix.PartyRole(1))#452 - PartyRole. group_146.addGroup(group_453) trade.addGroup(group_146) trade.setField(fix.StringField(1300,'XOFF'))#market segment id # trade.setField(fix.StringField(21,'z'))#HandlInst if order_type == '2': # limit trade.setField(fix.Price(float(price))) # if market, this tag should be absent else: price = None print(f'CREATING THE FOLLOWING ORDER:\n ') # print(f'CREATING THE FOLLOWING ORDER:\n {trade.toString()}') fix.Session.sendToTarget(trade, self.sessionID)
def quote_request(self,symbol,currency,quantity,side,order_type,dealers_dict): ''' send QuoteRequest message to Liquidity Providers build the message according to ORP_v1.5_QuickFIX ''' #HEADER trade = fix50sp2.QuoteRequest() trade.getHeader().setField(fix.StringField(8,'FIXT.1.1')) #BeginMessage trade.getHeader().setField(fix.StringField(35,'R'))#MessageType trade.getHeader().setField(fix.StringField(1128,'9')) #ApplVerID - FIX50SP2 trade.getHeader().setField(fix.StringField(49,'ORP_RESZ_B')) trade.getHeader().setField(fix.StringField(56,'BLPORPBETA')) trade.getHeader().setField(fix.StringField(128,'DOR')) trade.getHeader().setField(fix.SendingTime(1))#52 trade.getHeader().setField(fix.StringField(1156,'208'))#ApplExtID trade.getHeader().setField(fix.StringField(1129,'1.5'))#CstmApplVerID #BODY #QuoteReqID (131) --> RFQ+datetime+symbol+side quote_request_id = 'RFQ' + datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S') + symbol + str(side) trade.setField(fix.QuoteReqID(quote_request_id)) # 131 group_146 = fix50sp2.QuoteRequest().NoRelatedSym() if '/' not in symbol: group_146.setField(fix.StringField(55,str(symbol[:3]+'/'+symbol[3:6]))) else: group_146.setField(fix.StringField(55, str(symbol))) group_146.setField(fix.StringField(167,'FXSPOT')) group_146.setField(fix.IntField(460,4)) group_146.setField(fix.SettlType('0'))#SettlType # settl_date = datetime.datetime.utcnow()+BDay(n=2) if ((datetime.datetime.utcnow() - datetime.timedelta(hours = 4)).hour < 17) or ((datetime.datetime.utcnow() - datetime.timedelta(hours = 4)).weekday() == 6): settl_date = datetime.datetime.utcnow()+BDay(n=2) else: settl_date = datetime.datetime.utcnow() + BDay(n=3) while (settl_date.strftime('%Y%m%d') in HOLIDAYS_DICT[symbol[:3]]) or (settl_date.strftime('%Y%m%d') in HOLIDAYS_DICT[symbol[-3:]]): settl_date += BDay(n=1) group_146.setField(fix.SettlDate(settl_date.strftime('%Y%m%d')))#SettlDate group_146.setField(fix.OrderQty(quantity))#38 - Qty group_146.setField(fix.StringField(15,str(currency)))#Currency #if side == 0, get two way quotes (omit tag 54) if side != 0: group_146.setField(fix.StringField(54,str(side))) group_453 = fix50sp2.QuoteRequest().NoRelatedSym().NoPartyIDs() for dealer, party_role in dealers_dict.items(): group_453.setField(fix.StringField(448,dealer))#PartyID group_453.setField(fix.StringField(447,'D'))#PartyIDSource group_453.setField(fix.PartyRole(party_role))#452 - PartyRole. group_146.addGroup(group_453) trade.addGroup(group_146) trade.setField(fix.StringField(1300,'XOFF'))#market segment id # trade.setField(fix.StringField(21,'z'))#HandlInst if order_type == '2': # limit trade.setField(fix.Price(float(self.limit_price))) # if market, this tag should be absent print(f'CREATING THE FOLLOWING ORDER:\n {trade.toString()}') fix.Session.sendToTarget(trade, self.sessionID)