Skip to content

Commit e8c58ba

Browse files
author
Wasin Waeosri
committed
Change logs:
Add comments to the code
1 parent cfdff89 commit e8c58ba

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

console_python/trcc_posting.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
primact_1_value = 116.50
4040

4141

42-
def process_message(ws, message_json):
42+
def process_message(ws, message_json): # Process all incoming messages.
4343
""" Parse at high level and output JSON of message """
4444
message_type = message_json['Type']
4545

@@ -49,7 +49,7 @@ def process_message(ws, message_json):
4949
if message_domain == "Login":
5050
process_login_response(ws, message_json)
5151
elif message_json['Key']['Name'] == subscribe_itemname:
52-
# send Off Stream Post
52+
""" send Off Stream Post """
5353
print("Sending Off-Stream Post to TREP Server")
5454
send_market_price_post(ws)
5555
elif message_type == "Ping":
@@ -59,40 +59,43 @@ def process_message(ws, message_json):
5959
print(json.dumps(pong_json, sort_keys=True,
6060
indent=2, separators=(',', ':')))
6161

62-
# If our TRI stream is now open, we can start sending posts.
62+
""" If our TRI stream is now open, we can start sending posts. """
6363
global next_post_time
6464
if ('ID' in message_json and message_json['ID'] == 1 and next_post_time == 0 and
6565
(not 'State' in message_json or message_json['State']['Stream'] == "Open" and message_json['State']['Data'] == "Ok")):
6666
next_post_time = time.time() + 3
6767
print('Here')
6868

6969

70+
# Process incoming Login Refresh Response message.
7071
def process_login_response(ws, message_json):
71-
""" Send item request """
72-
# send Off Stream Post
72+
""" Send Off-Stream Post """
7373
print("Sending Off-Stream Post to TREP Server")
7474
send_market_price_post(ws)
7575

7676

77+
# Create JSON Off-Stream Post message and sends it to ADS server.
7778
def send_market_price_post(ws):
7879
global post_id
7980
global bid_value
8081
global ask_value
8182
global primact_1_value
8283
""" Send a post message contains a market-price content to TRCC """
8384

84-
# Contribution fields
85+
""" Contribution fields """
8586
contribution_fields = {
8687
"BID": bid_value,
8788
"ASK": ask_value,
8889
"PRIMACT_1": primact_1_value
8990
}
9091

92+
""" OMM Post msg Key """
9193
mp_post_key = {
9294
"Name": post_item_name,
9395
"Service": service_name
9496
}
9597

98+
""" OMM Post Payload """
9699
contribution_payload_json = {
97100
"ID": 0,
98101
"Type": "Update",
@@ -101,6 +104,7 @@ def send_market_price_post(ws):
101104
"Key": {}
102105
}
103106

107+
""" OMM Off-Stream Post message """
104108
mp_post_json_offstream = {
105109
"Domain": "MarketPrice",
106110
"Ack": True,
@@ -123,12 +127,15 @@ def send_market_price_post(ws):
123127
print("SENT:")
124128
print(json.dumps(mp_post_json_offstream,
125129
sort_keys=True, indent=2, separators=(',', ':')))
130+
131+
""" increase post data value """
126132
post_id += 1
127133
bid_value += 1
128134
ask_value += 1
129135
primact_1_value += 1
130136

131137

138+
# Create JSON Login request message and sends it to ADS server.
132139
def send_login_request(ws):
133140
""" Generate a login request from command line data (or defaults) and send """
134141
login_json = {

0 commit comments

Comments
 (0)