@@ -26,7 +26,7 @@ def gen_subscribe_price(self):
26
26
'jsonrpc' : '2.0' ,
27
27
'method' : 'subscribe_price' ,
28
28
'params' : {
29
- 'symbol ' : self .symbol ,
29
+ 'account ' : self .account ,
30
30
'price_type' : 'price'
31
31
},
32
32
'id' : self .sidnum
@@ -38,7 +38,7 @@ def gen_subscribe_price_sched(self):
38
38
'jsonrpc' : '2.0' ,
39
39
'method' : 'subscribe_price_sched' ,
40
40
'params' : {
41
- 'symbol ' : self .symbol ,
41
+ 'account ' : self .account ,
42
42
'price_type' : 'price'
43
43
},
44
44
'id' : self .pidnum
@@ -50,7 +50,7 @@ def gen_update_price(self):
50
50
'jsonrpc' : '2.0' ,
51
51
'method' : 'update_price' ,
52
52
'params' :{
53
- 'symbol ' : self .symbol ,
53
+ 'account ' : self .account ,
54
54
'price_type' : 'price' ,
55
55
'status' : 'trading' ,
56
56
'price' : self .price ,
@@ -88,8 +88,9 @@ async def parse_notify( self, ws, msg ):
88
88
f',price={ self .price } , spread={ self .spread } , subscription={ subid } ' )
89
89
await ws .send ( self .gen_update_price () )
90
90
91
- async def subscribe ( self , ws , allids ):
91
+ async def subscribe ( self , acct , ws , allids ):
92
92
# submmit initial subscriptions
93
+ self .account = acct
93
94
allids [self .pidnum ] = self
94
95
allids [self .sidnum ] = self
95
96
await ws .send ( self .gen_subscribe_price () )
@@ -104,10 +105,21 @@ async def poll( uri ):
104
105
# submit subscriptions to pythd
105
106
allids = {}
106
107
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 );
111
123
112
124
# poll for updates from pythd
113
125
while True :
0 commit comments