Skip to content
Snippets Groups Projects
Commit 86a98cd4 authored by yunfanh2's avatar yunfanh2
Browse files

add random side, symbol, timeforce, price in fix msg

parent 0e0c2c3a
No related branches found
No related tags found
No related merge requests found
...@@ -12,29 +12,47 @@ def generate_random_FIX_message(): ...@@ -12,29 +12,47 @@ def generate_random_FIX_message():
sender_id = 'TRADER' + str(random.randint(1000, 9999)) sender_id = 'TRADER' + str(random.randint(1000, 9999))
msg.append_pair(49, sender_id, header=True) msg.append_pair(49, sender_id, header=True)
msg.append_pair(56, 'EXCHANGE', header=True) # TargetCompID(56) msg.append_pair(56, 'EXCHANGE', header=True) # TargetCompID(56)
msg_seq_num = random.randint(1, 1000) # Set the message sequence number 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(34, msg_seq_num, header=True) # MsgSeqNum(34)
msg.append_pair(35, 'D') # 35: Set message type msg.append_pair(35, 'D') # 35: Set message type
# set sending time # set sending time
msg.append_tz_timestamp(52, precision=6, header=True) # 52: time msg.append_tz_timestamp(52, precision=6, header=True) # 52: time
client_order_id = 'ORD' + str(random.randint(10000000, 99999999)) client_order_id = 'ORD' + str(random.randint(10000000, 99999999))
msg.append_pair(11, client_order_id) msg.append_pair(11, client_order_id)
# Symbol(55) - Set a random stock symbol
symbols = ['AAPL', 'GOOG', 'AMZN', 'FB', 'TSLA']
symbol = random.choice(symbols)
msg.append_pair(55, symbol)
side = random.choice([1, 2]) # set side (1 for Buy, 2 for sell)
msg.append_pair(54, side)
order_type = random.choice([1, 2]) # 1 for Market, 2 for Limit
msg.append_pair(40, order_type)
order_qty = random.randint(1, 1000)
msg.append_pair(38, order_qty)
time_in_force = random.choice([0, 1]) # (0 for Day, 1 for GTC)
msg.append_pair(59, time_in_force)
if order_type == 2:
price = round(random.uniform(1, 1000), 2) # Set a random price for limit orders
msg.append_pair(44, price)
encoded_msg = msg.encode() encoded_msg = msg.encode()
return encoded_msg return encoded_msg
if __name__ == '__main__': if __name__ == '__main__':
# Generate 5 random FIX messages and print them
num_of_msg = 10 num_of_msg = 10
for _ in range(num_of_msg): for _ in range(num_of_msg):
random_fix_msg = generate_random_FIX_message() random_fix_msg = generate_random_FIX_message()
print(random_fix_msg) print(random_fix_msg)
time.sleep(1) 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