{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Shioaji Quote Api with bqplot\n", "![shioaji-logo](https://sinotrade.github.io/images/shioaji_spot_light-01.png)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "import json\n", "import datetime as dt\n", "import numpy as np\n", "import pandas as pd\n", "import bqplot as bq\n", "import shioaji as sj\n", "from ipywidgets import HBox, VBox" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Init shioaji api and login" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "api = sj.Shioaji(simulation=False)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "with open('login.json', 'r') as f:\n", " kw_login = json.loads(f.read())\n", "api.login(**kw_login)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Init Charts dataset" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "today = dt.date.today()\n", "df_min = pd.DataFrame(index=pd.date_range(start=dt.datetime(*(today.year, today.month, today.day, 8, 45)),\n", " end=dt.datetime(*(today.year, today.month, today.day, 13, 45)),\n", " freq='1T'),\n", " columns=['open', 'high', 'low', 'close'], dtype=float,\n", " )" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "last_close = 10200\n", "\n", "tick_plot_length = 150\n", "x_tick_index = np.arange(tick_plot_length)\n", "y_price = np.zeros((tick_plot_length,)) + last_close\n", "y_vol = np.zeros((tick_plot_length,))\n", "updown_color = np.zeros((tick_plot_length,)) + 1 \n", "askbid_color_data = np.zeros((tick_plot_length,))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "new_index = 0\n", "new_deal_price = 1\n", "new_vol = 1\n", "new_updown_color = 1\n", "new_askbid_color_data = 1\n", "ask_price = 0\n", "bid_price = 0" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "ask_bid_period_length = 500\n", "ask_bid_static = np.zeros((6, ask_bid_period_length))\n", "large_ask_deal_volsum = 0\n", "small_ask_deal_volsum = 0\n", "large_bid_deal_volsum = 0\n", "small_bid_deal_volsum = 0\n", "ask_deal_count = 0\n", "bid_deal_count = 0" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "bid_color = '#ff0000'\n", "ask_color = '#03ba00'\n", "x_bar_data = np.zeros(10)\n", "y_bar_data = np.zeros(10, dtype=np.int64)\n", "color_bar_data = np.array(['#000000' for i in range(10)])\n", "y_bar_data_diff = np.zeros(10, dtype=np.int64)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "data_in = np.random.rand(2)\n", "data_inner = np.random.rand(2)\n", "data_outer = np.random.rand(4)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## define init charts function" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "def init_ohlc_chart():\n", " global ohlc_chart\n", " sc = bq.LinearScale()\n", " dt_scale = bq.DateScale()\n", " ax_x = bq.Axis(label='datetime', scale=dt_scale)\n", " ax_y = bq.Axis(label='price', scale=sc, orientation='vertical', tick_format='0.0f')\n", "\n", " # Construct the marks\n", " ohlc_chart = bq.OHLC(x=df_min.index, y=df_min.dropna().values,#df_tick_nosim_min.values[:10], \n", " marker='candle', scales={'x': dt_scale, 'y': sc}, format='ohlc',\n", " colors=['red', 'limegreen'], stroke='gray', \n", " opacities=[0.85 for _ in df_min.index],\n", " display_legend=True, labels=['TXFD9'])\n", "\n", " fig = bq.Figure(axes=[ax_x, ax_y], marks=[ohlc_chart])\n", " return fig" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "def init_tickchart():\n", " global line_chart, scatter_chart\n", " global x_tick_index, y_price, y_vol, updown_color, askbid_color_data\n", " x_sc = bq.LinearScale()\n", " y_sc = bq.LinearScale()\n", " sc_size = bq.LinearScale()\n", " color_line = bq.ColorScale(colors=['red', 'gray', 'green'])\n", " c_ord = bq.ColorScale(colors=['gray', 'HotPink', 'SeaGreen'])\n", "\n", " line_chart = bq.FlexLine(x=x_tick_index, y=y_price, color=updown_color,\n", " scales= {'x': x_sc, 'y': y_sc, 'color': color_line}, \n", " display_legend=True, labels=[\"TXFD9\"])\n", "\n", " def_tt = bq.Tooltip(fields=['x', 'y', 'size'], formats=['', '.0f', '.0f'], \n", " lables=['tick', 'price', 'vol'])\n", "\n", " scatter_chart = bq.Scatter(x=x_tick_index, y=y_price, size=y_vol, color=askbid_color_data, \n", " scales= {'x': x_sc, 'y': y_sc, 'size': sc_size, 'color': c_ord}, \n", " #colors=['dodgerblue',],\n", " tooltip=def_tt, lables=['tick', 'price', 'vol'],\n", " selected_style={'opacity': 1.0,}, #'fill': 'DarkOrange', 'stroke': 'Red'}, \n", " unselected_style={'opacity': 0.7})\n", "\n", " ax_x = bq.Axis(scale=x_sc)\n", " ax_y = bq.Axis(scale=y_sc, orientation='vertical', tick_format='0.0f')\n", " ax_color = bq.ColorAxis(label='updown', scale=color_line, tick_format='.0f')\n", "\n", " fig = bq.Figure(marks=[line_chart, scatter_chart], axes=[ax_x, ax_y, ax_color],\n", " #min_aspect_ratio=1, max_aspect_ratio=3,\n", " #fig_margin= {\"top\":0, \"bottom\":60, \"left\":60, \"right\":0},\n", " )\n", " return fig" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "def bidask_bar_chart():\n", " global x_bar_data, y_bar_data, color_bar_data, y_data_diff\n", " global bar_bidask, bar_bidask_diff\n", " x_ord = bq.OrdinalScale()\n", " y_sc = bq.LinearScale()\n", " stroke_color = '#000000'\n", " bar_bidask = bq.Bars(x=x_bar_data, y=y_bar_data,\n", " scales={'x': x_ord, 'y': y_sc}, \n", " stroke=stroke_color, color_mode='group',\n", " padding=0, colors=color_bar_data.tolist(),\n", " type='stacked', orientation='horizontal',\n", " opacities=[0.7 for _ in x_bar_data],\n", " )\n", " bar_bidask_diff = bq.Bars(x=x_bar_data, y=y_bar_data_diff,\n", " scales={'x': x_ord, 'y': y_sc}, \n", " stroke=stroke_color, color_mode='group',\n", " padding=0, colors=color_bar_data.tolist()[::-1],\n", " type='stacked', orientation='horizontal',\n", " opacities=[0.7 for _ in x_bar_data],\n", " )\n", " ax_x = bq.Axis(scale=x_ord, orientation='vertical')\n", " ax_y = bq.Axis(scale=y_sc, tick_format='0.0f')\n", "\n", " fig = bq.Figure(marks=[bar_bidask, bar_bidask_diff], axes=[ax_x, ax_y],\n", " #min_aspect_ratio=1, max_aspect_ratio=1,\n", " #fig_margin= {\"top\":0, \"bottom\":60, \"left\":10, \"right\":0},\n", " )\n", " return fig" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "def pies_chart():\n", " global data_in, data_inner, data_outer\n", " global pie_outer, pie_inner, pie_in\n", " outer_pie_redius = [180, 150]\n", " inner_pie_redius = [100, 70]\n", " in_pie_redius = [50, 10]\n", " pie_outer = bq.Pie(sizes=data_outer, display_labels='outside', apply_clip=False,\n", " radius=outer_pie_redius[0], inner_radius=outer_pie_redius[1], \n", " display_values=True, values_format='.0%', colors=['red', 'limegreen', 'red', 'limegreen'],\n", " labels=['大單委賣成交', '大單委買成交', '小單委賣成交', '小單委買成交'])\n", "\n", " pie_inner = bq.Pie(sizes=data_inner, display_labels='inside', apply_clip=False,\n", " radius=inner_pie_redius[0], inner_radius=inner_pie_redius[1], \n", " display_values=True, values_format='.0%', colors=['red', 'limegreen'],\n", " labels=['賣成筆', '買成筆'])\n", "\n", " pie_in = bq.Pie(sizes=data_in, display_labels='inside', #apply_clip=False,\n", " radius=in_pie_redius[0], inner_radius=in_pie_redius[1], \n", " display_values=True, values_format='.0%', colors=['limegreen', 'red'],\n", " labels=['賣成口', '買成口'])\n", "\n", " fig = bq.Figure(marks=[pie_outer, pie_inner, pie_in], animation_duration=1000,\n", " #min_aspect_ratio=1, max_aspect_ratio=1.5,\n", " #fig_margin= {\"top\":0, \"bottom\":60, \"left\":60, \"right\":0},\n", " )\n", " return fig" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## define processing data function" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "def proc_ohlc_data(quote_msg, new_deal_price):\n", " global df_min\n", " ts = pd.Timestamp(\"{Date} {Time}\" .format(**quote_msg)).replace(second=0, microsecond=0)\n", " df_min.loc[ts, 'open'] = new_deal_price if np.isnan(df_min.loc[ts, 'open']) else df_min.loc[ts, 'open'] \n", " df_min.loc[ts, 'high'] = new_deal_price if np.isnan(df_min.loc[ts, 'high']) or new_deal_price > df_min.loc[ts, 'high'] else df_min.loc[ts, 'high'] \n", " df_min.loc[ts, 'low'] = new_deal_price if np.isnan(df_min.loc[ts, 'low']) or new_deal_price < df_min.loc[ts, 'low'] else df_min.loc[ts, 'low']\n", " df_min.loc[ts, 'close'] = new_deal_price" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "def proc_ask_bid_bardata(topic, quote_msg):\n", " global x_bar_data, y_bar_data, color_bar_data, y_data_diff\n", " ask_price = quote_msg.get('AskPrice', [0])[0]\n", " bid_price = quote_msg.get('BidPrice', [0])[0]\n", "\n", " x_bar_data[:5] = quote_msg['BidPrice'][::-1]\n", " x_bar_data[5:] = quote_msg['AskPrice']\n", " y_bar_data[:5] = quote_msg['BidVolume'][::-1]\n", " y_bar_data[5:] = quote_msg['AskVolume']\n", " y_bar_data[5:] *= -1\n", " y_bar_data_diff[5:] = quote_msg[\"DiffAskVol\"]\n", " y_bar_data_diff[:5] = quote_msg['DiffBidVol'][::-1]\n", " color_bar_data[:5] = bid_color\n", " color_bar_data[5:] = ask_color" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "def proc_tick_chartdata(topic, quote_msg):\n", " global new_index, new_deal_price, new_vol, new_updown_color, new_askbid_color_data\n", " global x_tick_index, y_price, y_vol, updown_color, askbid_color_data\n", " new_index += 1\n", " new_deal_price = quote_msg.get('Close', [0,])[-1]\n", " new_vol = quote_msg.get('Volume', [0,])[-1]\n", " ask_volsum = quote_msg.get('TradeAskVolSum', 0)\n", " bid_volsum = quote_msg.get('TradeBidVolSum', 0)\n", " new_askbid_color_data = quote_msg.get('TickType', [0,])[-1]# 0: -, 1: ask, 2, bid\n", " if new_deal_price > y_price[-1]:\n", " new_updown_color = 0\n", " elif new_deal_price < y_price[-1]:\n", " new_updown_color = 2\n", " else:\n", " new_updown_color = 1\n", " \n", " x_tick_index[:-1] = x_tick_index[1:]\n", " x_tick_index[-1] = new_index\n", " y_price[:-1] = y_price[1:]\n", " y_price[-1] = new_deal_price\n", " y_vol[:-1] = y_vol[1:]\n", " y_vol[-1] = new_vol\n", " updown_color[:-1] = updown_color[1:]\n", " updown_color[-2] = new_updown_color\n", " askbid_color_data[:-1] = askbid_color_data[1:]\n", " askbid_color_data[-1] = new_askbid_color_data" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "def proc_ask_bid_staticdata(topic, quote_msg, vol_threshold):\n", " global ask_bid_static\n", " global small_bid_deal_volsum, ask_deal_count, bid_deal_count\n", " ask_volsum = quote_msg.get('TradeAskVolSum', 0)\n", " bid_volsum = quote_msg.get('TradeBidVolSum', 0)\n", " ask_bid_static[:, :-1] = ask_bid_static[:, 1:]\n", " if new_askbid_color_data == 1:\n", " ask_deal_count += 1\n", " ask_bid_static[4][-1] = 1\n", " ask_bid_static[5][-1] = 0\n", " if new_vol >= vol_threshold:\n", " ask_bid_static[0][-1] = new_vol\n", " else:\n", " ask_bid_static[1][-1] = new_vol\n", " elif new_askbid_color_data == 2:\n", " bid_deal_count += 1\n", " ask_bid_static[5][-1] = 1\n", " ask_bid_static[4][-1] = 0\n", " if new_vol >= vol_threshold:\n", " ask_bid_static[2][-1] = new_vol\n", " else:\n", " ask_bid_static[3][-1] = new_vol\n", " \n", " ask_bid_static_sum = ask_bid_static.sum(axis=1)\n", " data_outer = ask_bid_static_sum[:4]\n", " data_inner = ask_bid_static_sum[4:]\n", " data_in = np.array([ask_volsum, bid_volsum])" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## define update chart function" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "def update_ohlc_chart():\n", " global ohlc_chart\n", " with ohlc_chart.hold_sync():\n", " ohlc_chart.x = df_min.dropna().index\n", " ohlc_chart.y = df_min.dropna().values" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "def update_barchart(x_bar_data, y_bar_data, \n", " color_bar_data, y_bar_data_diff):\n", " global bar_bidask, bar_bidask_diff\n", " with bar_bidask.hold_sync() and bar_bidask_diff.hold_sync():\n", " bar_bidask.x = x_bar_data.copy()\n", " bar_bidask.y = y_bar_data.copy()\n", " bar_bidask.colors = color_bar_data.tolist()\n", " bar_bidask_diff.x = x_bar_data.copy()\n", " bar_bidask_diff.y = y_bar_data_diff.copy()\n", " bar_bidask_diff.colors = color_bar_data.tolist()[::-1]" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "def update_tickandpie_chart(update_freq):\n", " global line_chart, scatter_chart\n", " global pie_outer, pie_inner, pie_in\n", " \n", " if (new_index % update_freq) == 0 and new_index >= tick_plot_length:\n", " with line_chart.hold_sync() and scatter_chart.hold_sync():\n", " line_chart.x = x_tick_index.copy()\n", " line_chart.y = y_price.copy()\n", " line_chart.color = updown_color.copy()\n", " scatter_chart.x = x_tick_index.copy()\n", " scatter_chart.y = y_price.copy()\n", " scatter_chart.size = y_vol.copy() * 10\n", " scatter_chart.color = askbid_color_data.copy()\n", " with pie_outer.hold_sync() and pie_inner.hold_sync() and pie_in.hold_sync():\n", " pie_outer.sizes = data_outer / data_outer.sum()\n", " pie_inner.sizes = data_inner / data_inner.sum()\n", " pie_in.sizes = data_in / data_in.sum()" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## define on quote callback" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "@sj.on_quote\n", "def quote_callback(topic, quote_msg):\n", " global tick_plot_length\n", " global line_chart, scatter_chart\n", " global pie_outer, pie_inner, pie_in\n", " global x_tick_index, y_price, y_vol, updown_color, askbid_color_data\n", " global new_index, new_deal_price, new_vol, new_updown_color, new_askbid_color_data\n", " global ask_price, bid_price\n", " global large_ask_deal_volsum, small_ask_deal_volsum, large_bid_deal_volsum\n", " global small_bid_deal_volsum, ask_deal_count, bid_deal_count\n", " global ask_bid_static\n", " global bar_bidask, bar_bidask_diff\n", " global x_bar_data, y_bar_data, color_bar_data, y_data_diff\n", " global ohlc_chart, df_min\n", " vol_threshold = 10\n", " print(topic, quote_msg)\n", " if topic.startswith('Q') and 'TXFD9' in topic:\n", " proc_ask_bid_bardata(topic, quote_msg)\n", " update_barchart(x_bar_data, y_bar_data, \n", " color_bar_data, y_bar_data_diff)\n", " \n", " elif topic.startswith('L') and 'TXFD9' in topic:\n", " proc_tick_chartdata(topic, quote_msg)\n", " proc_ask_bid_staticdata(topic, quote_msg, vol_threshold)\n", " proc_ohlc_data(quote_msg, new_deal_price)\n", " update_ohlc_chart()\n", " update_tickandpie_chart(update_freq=1)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## define event callback" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "@sj.on_event\n", "def event_callback(resp_code, event_code, event):\n", " print(\"Respone Code: {} | Event Code: {} | Event: {}\".format(resp_code, event_code, event))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## set callback function" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "api.quote.set_callback(quote_callback)\n", "api.quote.set_event_callback(event_callback)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "pie_in.label_color = '#fff'\n", "pie_inner.label_color = '#fff'\n", "pie_outer.label_color = '#fff'" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Chart" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2deef03e26864984bf35462333257e58", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(Figure(axes=[Axis(label='datetime', scale=DateScale()), Axis(label='price', orie…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "VBox([HBox([init_ohlc_chart(), init_tickchart(),]),\n", " HBox([pies_chart(), bidask_bar_chart(), ])\n", " ])" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "![gif](https://raw.githubusercontent.com/Sinotrade/Sinotrade.github.io/master/images/quote_visualize.gif)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Subscribe Quote" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "TXFR1 = api.Contracts.Futures.TXF.TXF201904\n", "TSE2330 = api.Contracts.Stocks.TSE.TSE2330" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Respone Code: 200 | Event Code: 16 | Event: Subscribe or Unsubscribe ok\n", "Respone Code: 200 | Event Code: 16 | Event: Subscribe or Unsubscribe ok\n", "Respone Code: 200 | Event Code: 16 | Event: Subscribe or Unsubscribe ok\n", "Respone Code: 200 | Event Code: 16 | Event: Subscribe or Unsubscribe ok\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 356, 'AskVolume': [25, 44, 64, 75, 148], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 240, 'BidVolume': [12, 42, 59, 66, 61], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, -1, 0], 'DiffAskVolSum': -1, 'DiffBidVol': [0, 0, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:35.328000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 356, 'AskVolume': [25, 44, 64, 75, 148], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 239, 'BidVolume': [11, 42, 59, 66, 61], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [-1, 0, 0, 0, 0], 'DiffBidVolSum': -1, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:35.453000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 341, 'AskVolume': [25, 44, 64, 65, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 239, 'BidVolume': [11, 42, 59, 66, 61], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, -10, -5], 'DiffAskVolSum': -15, 'DiffBidVol': [0, 0, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:35.703000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 341, 'AskVolume': [25, 44, 64, 65, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 239, 'BidVolume': [11, 42, 59, 66, 61], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [0, 0, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:35.828000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 341, 'AskVolume': [25, 44, 64, 65, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 241, 'BidVolume': [12, 42, 59, 66, 62], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [1, 0, 0, 0, 1], 'DiffBidVolSum': 2, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:36.203000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 341, 'AskVolume': [25, 44, 64, 65, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 244, 'BidVolume': [15, 42, 59, 66, 62], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [3, 0, 0, 0, 0], 'DiffBidVolSum': 3, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:36.328000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 342, 'AskVolume': [25, 45, 64, 65, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 244, 'BidVolume': [14, 44, 58, 65, 63], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 1, 0, 0, 0], 'DiffAskVolSum': 1, 'DiffBidVol': [-1, 2, -1, -1, 1], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:36.453000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 342, 'AskVolume': [25, 45, 64, 65, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 247, 'BidVolume': [16, 43, 58, 66, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [2, -1, 0, 1, 1], 'DiffBidVolSum': 3, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:36.578000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 342, 'AskVolume': [25, 45, 64, 65, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 248, 'BidVolume': [17, 44, 58, 65, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [1, 1, 0, -1, 0], 'DiffBidVolSum': 1, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:36.703000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 342, 'AskVolume': [25, 45, 64, 65, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 247, 'BidVolume': [16, 44, 58, 65, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [-1, 0, 0, 0, 0], 'DiffBidVolSum': -1, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:36.828000'}\n", "MKT/idcdmzpcr01/TSE/2330 {'Close': [244.5], 'Time': '13:12:37.754742', 'VolSum': [15915], 'Volume': [1]}\n", "QUT/idcdmzpcr01/TSE/2330 {'AskPrice': [245.0, 245.5, 246.0, 246.5, 247.0], 'AskVolume': [1148, 377, 501, 182, 218], 'BidPrice': [244.5, 244.0, 243.5, 243.0, 242.5], 'BidVolume': [456, 373, 1529, 1670, 280], 'Date': '2019/03/29', 'Time': '13:12:37.754742'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 342, 'AskVolume': [25, 45, 64, 65, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 247, 'BidVolume': [16, 44, 58, 65, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [0, 0, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:37.953000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 339, 'AskVolume': [25, 45, 64, 62, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 247, 'BidVolume': [16, 44, 58, 65, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, -3, 0], 'DiffAskVolSum': -3, 'DiffBidVol': [0, 0, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:38.078000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 339, 'AskVolume': [25, 45, 64, 62, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 248, 'BidVolume': [16, 44, 59, 65, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [0, 0, 1, 0, 0], 'DiffBidVolSum': 1, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:38.203000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 340, 'AskVolume': [26, 45, 64, 62, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 247, 'BidVolume': [16, 44, 59, 64, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [1, 0, 0, 0, 0], 'DiffAskVolSum': 1, 'DiffBidVol': [0, 0, 0, -1, 0], 'DiffBidVolSum': -1, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:38.703000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 340, 'AskVolume': [26, 45, 64, 62, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 247, 'BidVolume': [16, 43, 60, 64, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [0, -1, 1, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:38.828000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 341, 'AskVolume': [26, 46, 64, 62, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 247, 'BidVolume': [16, 43, 60, 64, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 1, 0, 0, 0], 'DiffAskVolSum': 1, 'DiffBidVol': [0, 0, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:39.078000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 341, 'AskVolume': [26, 46, 64, 62, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 247, 'BidVolume': [16, 43, 60, 64, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [0, 0, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:39.328000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 341, 'AskVolume': [26, 46, 64, 62, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 245, 'BidVolume': [14, 43, 60, 64, 64], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [-2, 0, 0, 0, 0], 'DiffBidVolSum': -2, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:39.453000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 341, 'AskVolume': [26, 46, 64, 62, 143], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 242, 'BidVolume': [12, 42, 60, 65, 63], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [-2, -1, 0, 1, -1], 'DiffBidVolSum': -3, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:39.578000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 311, 'AskVolume': [26, 46, 64, 62, 113], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 242, 'BidVolume': [12, 42, 60, 65, 63], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, -30], 'DiffAskVolSum': -30, 'DiffBidVol': [0, 0, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:39.828000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 311, 'AskVolume': [26, 46, 64, 62, 113], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 248, 'BidVolume': [18, 42, 60, 65, 63], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [6, 0, 0, 0, 0], 'DiffBidVolSum': 6, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10620.7, 'Time': '13:12:40.078000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 308, 'AskVolume': [23, 46, 64, 62, 113], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 249, 'BidVolume': [19, 44, 59, 64, 63], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [-3, 0, 0, 0, 0], 'DiffAskVolSum': -3, 'DiffBidVol': [1, 2, -1, -1, 0], 'DiffBidVolSum': 1, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10615.63, 'Time': '13:12:40.203000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 309, 'AskVolume': [23, 47, 64, 62, 113], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 249, 'BidVolume': [19, 44, 59, 64, 63], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [0, 1, 0, 0, 0], 'DiffAskVolSum': 1, 'DiffBidVol': [0, 0, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10615.63, 'Time': '13:12:40.953000'}\n", "Q/TFE/TXFD9 {'AskPrice': [10580.0, 10581.0, 10582.0, 10583.0, 10584.0], 'AskVolSum': 310, 'AskVolume': [24, 47, 64, 62, 113], 'BidPrice': [10579.0, 10578.0, 10577.0, 10576.0, 10575.0], 'BidVolSum': 249, 'BidVolume': [19, 44, 59, 64, 63], 'Code': 'TXFD9', 'Date': '2019/03/29', 'DiffAskVol': [1, 0, 0, 0, 0], 'DiffAskVolSum': 1, 'DiffBidVol': [0, 0, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 10581.0, 'FirstDerivedAskVolume': 6, 'FirstDerivedBidPrice': 10577.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 10615.63, 'Time': '13:12:41.078000'}\n" ] } ], "source": [ "api.quote.subscribe(TXFR1)\n", "api.quote.subscribe(TXFR1, quote_type='bidask')\n", "api.quote.subscribe(TSE2330)\n", "api.quote.subscribe(TSE2330, quote_type='bidask')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.1" } }, "nbformat": 4, "nbformat_minor": 2 }