Skip to content

Commit f3ade8f

Browse files
repair test_publish.py websockets example to use subscription by account
1 parent 9ede809 commit f3ade8f

File tree

3 files changed

+21
-172
lines changed

3 files changed

+21
-172
lines changed

pctest/get_product_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async def get_symbol_list( uri ):
1212
# connect to pythd
1313
ws = await websockets.connect(uri)
1414

15-
# submit get_symbol_list request
15+
# submit get_product_list request
1616
req = { 'jsonrpc': '2.0', 'method': 'get_product_list', 'id': None }
1717
await ws.send( json.dumps( req ) )
1818

pctest/test_publish.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def gen_subscribe_price(self):
2626
'jsonrpc': '2.0',
2727
'method' : 'subscribe_price',
2828
'params' : {
29-
'symbol': self.symbol,
29+
'account': self.account,
3030
'price_type' : 'price'
3131
},
3232
'id': self.sidnum
@@ -38,7 +38,7 @@ def gen_subscribe_price_sched(self):
3838
'jsonrpc': '2.0',
3939
'method' : 'subscribe_price_sched',
4040
'params' : {
41-
'symbol': self.symbol,
41+
'account': self.account,
4242
'price_type' : 'price'
4343
},
4444
'id': self.pidnum
@@ -50,7 +50,7 @@ def gen_update_price(self):
5050
'jsonrpc': '2.0',
5151
'method': 'update_price',
5252
'params':{
53-
'symbol': self.symbol,
53+
'account': self.account,
5454
'price_type': 'price',
5555
'status': 'trading',
5656
'price': self.price,
@@ -88,8 +88,9 @@ async def parse_notify( self, ws, msg ):
8888
f',price={self.price}, spread={self.spread}, subscription={subid}')
8989
await ws.send( self.gen_update_price() )
9090

91-
async def subscribe( self, ws, allids ):
91+
async def subscribe( self, acct, ws, allids ):
9292
# submmit initial subscriptions
93+
self.account = acct
9394
allids[self.pidnum] = self
9495
allids[self.sidnum] = self
9596
await ws.send( self.gen_subscribe_price() )
@@ -104,10 +105,21 @@ async def poll( uri ):
104105
# submit subscriptions to pythd
105106
allids = {}
106107
allsub = {}
107-
sym1 = test_publish( 'US.EQ.SYMBOL1', 10000, 100 )
108-
sym2 = test_publish( 'US.EQ.SYMBOL2', 2000000, 20000 )
109-
await sym1.subscribe( ws, allids )
110-
await sym2.subscribe( ws, allids )
108+
allsym = {}
109+
sym1 = test_publish( 'SYMBOL1/USD', 10000, 100 )
110+
sym2 = test_publish( 'SYMBOL2/USD', 2000000, 20000 )
111+
allsym[sym1.symbol] = sym1
112+
allsym[sym2.symbol] = sym2
113+
114+
# lookup accounts by symbol and subscribe
115+
req = { 'jsonrpc': '2.0', 'method': 'get_product_list', 'id': None }
116+
await ws.send( json.dumps( req ) )
117+
msg = json.loads( await ws.recv() )
118+
for prod in msg['result']:
119+
sym = prod['attr_dict']['symbol']
120+
for px in prod['price']:
121+
if sym in allsym and px['price_type'] == 'price':
122+
await allsym[sym].subscribe( px['account'], ws, allids );
111123

112124
# poll for updates from pythd
113125
while True:

pctest/test_pyth.sh

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)