Add a quote-from-json-file streamer for testing
parent
6781a23850
commit
b8a3fb67a1
|
@ -0,0 +1,31 @@
|
|||
"""
|
||||
Mock a broker module.
|
||||
"""
|
||||
from itertools import cycle
|
||||
import json
|
||||
from os import path
|
||||
import trio
|
||||
from async_generator import asynccontextmanager
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def get_client() -> None:
|
||||
"""Shim client factory.
|
||||
"""
|
||||
yield None
|
||||
|
||||
|
||||
async def poll_tickers(
|
||||
client, tickers: [str], q: trio.Queue) -> None:
|
||||
"""Stream quotes from a local json store.
|
||||
"""
|
||||
with open(path.join(path.dirname(__file__), 'quotes.json'), 'r') as quotes_file:
|
||||
content = quotes_file.read()
|
||||
|
||||
pkts = content.split('--') # simulate 2 separate quote packets
|
||||
# import pdb; pdb.set_trace()
|
||||
payloads = [json.loads(pkt)['quotes'] for pkt in pkts]
|
||||
|
||||
for payload in cycle(payloads):
|
||||
q.put_nowait(payload)
|
||||
await trio.sleep(1/2.)
|
|
@ -0,0 +1,240 @@
|
|||
{
|
||||
"quotes": [
|
||||
{
|
||||
"VWAP": 7.383792,
|
||||
"askPrice": 7.56,
|
||||
"askSize": 2,
|
||||
"bidPrice": 6.1,
|
||||
"bidSize": 2,
|
||||
"delay": 0,
|
||||
"high52w": 9.68,
|
||||
"highPrice": 8,
|
||||
"isHalted": false,
|
||||
"lastTradePrice": 6.96,
|
||||
"lastTradePriceTrHrs": 6.97,
|
||||
"lastTradeSize": 2000,
|
||||
"lastTradeTick": "Down",
|
||||
"lastTradeTime": "2018-02-07T15:59:59.259000-05:00",
|
||||
"low52w": 1.03,
|
||||
"lowPrice": 6.88,
|
||||
"openPrice": 7.64,
|
||||
"symbol": "EMH.VN",
|
||||
"symbolId": 10164524,
|
||||
"tier": "",
|
||||
"volume": 5357805
|
||||
},
|
||||
{
|
||||
"VWAP": 29.445855,
|
||||
"askPrice": 55,
|
||||
"askSize": 2,
|
||||
"bidPrice": 27.63,
|
||||
"bidSize": 20,
|
||||
"delay": 0,
|
||||
"high52w": 44,
|
||||
"highPrice": 31.35,
|
||||
"isHalted": false,
|
||||
"lastTradePrice": 27.67,
|
||||
"lastTradePriceTrHrs": 27.62,
|
||||
"lastTradeSize": 100,
|
||||
"lastTradeTick": "Down",
|
||||
"lastTradeTime": "2018-02-07T16:16:17.723000-05:00",
|
||||
"low52w": 6.58,
|
||||
"lowPrice": 26.66,
|
||||
"openPrice": 30.43,
|
||||
"symbol": "WEED.TO",
|
||||
"symbolId": 16529510,
|
||||
"tier": "",
|
||||
"volume": 14762722
|
||||
},
|
||||
{
|
||||
"VWAP": 18.353787,
|
||||
"askPrice": 19,
|
||||
"askSize": 4,
|
||||
"bidPrice": 10,
|
||||
"bidSize": 1,
|
||||
"delay": 0,
|
||||
"high52w": 31.25,
|
||||
"highPrice": 18.99,
|
||||
"isHalted": false,
|
||||
"lastTradePrice": 17.9,
|
||||
"lastTradePriceTrHrs": 17.87,
|
||||
"lastTradeSize": 1600,
|
||||
"lastTradeTick": "Up",
|
||||
"lastTradeTime": "2018-02-07T16:00:00.201000-05:00",
|
||||
"low52w": 6.81,
|
||||
"lowPrice": 17.33,
|
||||
"openPrice": 18.71,
|
||||
"symbol": "LEAF.TO",
|
||||
"symbolId": 17821824,
|
||||
"tier": "",
|
||||
"volume": 1322510
|
||||
},
|
||||
{
|
||||
"VWAP": 19.492624,
|
||||
"askPrice": 25.18,
|
||||
"askSize": 1,
|
||||
"bidPrice": 10.31,
|
||||
"bidSize": 5,
|
||||
"delay": 0,
|
||||
"high52w": 25.56,
|
||||
"highPrice": 20.7,
|
||||
"isHalted": false,
|
||||
"lastTradePrice": 18.74,
|
||||
"lastTradePriceTrHrs": 18.74,
|
||||
"lastTradeSize": 100,
|
||||
"lastTradeTick": "Up",
|
||||
"lastTradeTime": "2018-02-07T15:59:49.451000-05:00",
|
||||
"low52w": 8.36,
|
||||
"lowPrice": 18.18,
|
||||
"openPrice": 19.97,
|
||||
"symbol": "HMMJ.TO",
|
||||
"symbolId": 18022628,
|
||||
"tier": "",
|
||||
"volume": 2427378
|
||||
},
|
||||
{
|
||||
"VWAP": 7.620155,
|
||||
"askPrice": 5.9,
|
||||
"askSize": 30,
|
||||
"bidPrice": 5.66,
|
||||
"bidSize": 30,
|
||||
"delay": 0,
|
||||
"high52w": 9.8,
|
||||
"highPrice": 8.05,
|
||||
"isHalted": false,
|
||||
"lastTradePrice": 7.53,
|
||||
"lastTradePriceTrHrs": 7.53,
|
||||
"lastTradeSize": 900,
|
||||
"lastTradeTick": "Equal",
|
||||
"lastTradeTime": "2018-02-07T15:59:55.899000-05:00",
|
||||
"low52w": 1.52,
|
||||
"lowPrice": 7.06,
|
||||
"openPrice": 7.69,
|
||||
"symbol": "VFF.TO",
|
||||
"symbolId": 40747,
|
||||
"tier": "",
|
||||
"volume": 828156
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
--
|
||||
{
|
||||
"quotes": [
|
||||
{
|
||||
"VWAP": 7.383792,
|
||||
"askPrice": 7.55,
|
||||
"askSize": 2,
|
||||
"bidPrice": 6.2,
|
||||
"bidSize": 2,
|
||||
"delay": 0,
|
||||
"high52w": 9.68,
|
||||
"highPrice": 8,
|
||||
"isHalted": false,
|
||||
"lastTradePrice": 6.97,
|
||||
"lastTradePriceTrHrs": 6.97,
|
||||
"lastTradeSize": 1000,
|
||||
"lastTradeTick": "Up",
|
||||
"lastTradeTime": "2018-02-07T15:59:59.259000-05:00",
|
||||
"low52w": 1.03,
|
||||
"lowPrice": 6.88,
|
||||
"openPrice": 7.64,
|
||||
"symbol": "EMH.VN",
|
||||
"symbolId": 10164524,
|
||||
"tier": "",
|
||||
"volume": 5357805
|
||||
},
|
||||
{
|
||||
"VWAP": 29.445855,
|
||||
"askPrice": 55,
|
||||
"askSize": 2,
|
||||
"bidPrice": 27.63,
|
||||
"bidSize": 20,
|
||||
"delay": 0,
|
||||
"high52w": 44,
|
||||
"highPrice": 31.35,
|
||||
"isHalted": false,
|
||||
"lastTradePrice": 28.25,
|
||||
"lastTradePriceTrHrs": 27.62,
|
||||
"lastTradeSize": 100,
|
||||
"lastTradeTick": "Up",
|
||||
"lastTradeTime": "2018-02-07T16:16:17.723000-05:00",
|
||||
"low52w": 6.58,
|
||||
"lowPrice": 26.66,
|
||||
"openPrice": 30.43,
|
||||
"symbol": "WEED.TO",
|
||||
"symbolId": 16529510,
|
||||
"tier": "",
|
||||
"volume": 14762722
|
||||
},
|
||||
{
|
||||
"VWAP": 18.353787,
|
||||
"askPrice": 19,
|
||||
"askSize": 4,
|
||||
"bidPrice": 10,
|
||||
"bidSize": 1,
|
||||
"delay": 0,
|
||||
"high52w": 31.25,
|
||||
"highPrice": 18.99,
|
||||
"isHalted": false,
|
||||
"lastTradePrice": 17.8,
|
||||
"lastTradePriceTrHrs": 17.87,
|
||||
"lastTradeSize": 100,
|
||||
"lastTradeTick": "Down",
|
||||
"lastTradeTime": "2018-02-07T16:00:00.201000-05:00",
|
||||
"low52w": 6.81,
|
||||
"lowPrice": 17.33,
|
||||
"openPrice": 18.71,
|
||||
"symbol": "LEAF.TO",
|
||||
"symbolId": 17821824,
|
||||
"tier": "",
|
||||
"volume": 1322510
|
||||
},
|
||||
{
|
||||
"VWAP": 19.492624,
|
||||
"askPrice": 25.18,
|
||||
"askSize": 1,
|
||||
"bidPrice": 10.31,
|
||||
"bidSize": 5,
|
||||
"delay": 0,
|
||||
"high52w": 25.56,
|
||||
"highPrice": 20.7,
|
||||
"isHalted": false,
|
||||
"lastTradePrice": 16.70,
|
||||
"lastTradePriceTrHrs": 18.74,
|
||||
"lastTradeSize": 100,
|
||||
"lastTradeTick": "Down",
|
||||
"lastTradeTime": "2018-02-07T15:59:49.451000-05:00",
|
||||
"low52w": 8.36,
|
||||
"lowPrice": 18.18,
|
||||
"openPrice": 19.97,
|
||||
"symbol": "HMMJ.TO",
|
||||
"symbolId": 18022628,
|
||||
"tier": "",
|
||||
"volume": 2427378
|
||||
},
|
||||
{
|
||||
"VWAP": 7.620155,
|
||||
"askPrice": 7.75,
|
||||
"askSize": 20,
|
||||
"bidPrice": 5.66,
|
||||
"bidSize": 30,
|
||||
"delay": 0,
|
||||
"high52w": 9.8,
|
||||
"highPrice": 8.05,
|
||||
"isHalted": false,
|
||||
"lastTradePrice": 7.53,
|
||||
"lastTradePriceTrHrs": 7.53,
|
||||
"lastTradeSize": 400,
|
||||
"lastTradeTick": "Equal",
|
||||
"lastTradeTime": "2018-02-07T15:59:55.899000-05:00",
|
||||
"low52w": 1.52,
|
||||
"lowPrice": 7.06,
|
||||
"openPrice": 7.69,
|
||||
"symbol": "VFF.TO",
|
||||
"symbolId": 40747,
|
||||
"tier": "",
|
||||
"volume": 828156
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue