Skip to content
Snippets Groups Projects
Commit 0e0c2c3a authored by yunfanh2's avatar yunfanh2
Browse files

random fix msg generator (simple version without stock name and sides)

parent c266114b
No related branches found
No related tags found
No related merge requests found
import random
import simplefix
import time
from datetime import datetime
# generate a random FIX message with random values for some fields
def generate_random_FIX_message():
msg = simplefix.FixMessage()
msg.append_string('8=FIX.4.2') # Set the FIX version to 4.2
sender_id = 'TRADER' + str(random.randint(1000, 9999))
msg.append_pair(49, sender_id, header=True)
msg.append_pair(56, 'EXCHANGE', header=True) # TargetCompID(56)
msg_seq_num = random.randint(1, 1000) # Set the message sequence number
msg.append_pair(34, msg_seq_num, header=True) # MsgSeqNum(34)
msg.append_pair(35, 'D') # 35: Set message type
# set sending time
msg.append_tz_timestamp(52, precision=6, header=True) # 52: time
client_order_id = 'ORD' + str(random.randint(10000000, 99999999))
msg.append_pair(11, client_order_id)
encoded_msg = msg.encode()
return encoded_msg
if __name__ == '__main__':
# Generate 5 random FIX messages and print them
num_of_msg = 10
for _ in range(num_of_msg):
random_fix_msg = generate_random_FIX_message()
print(random_fix_msg)
time.sleep(1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment