|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -import pandas as pd |
3 | 2 | from tigeropen.common.response import TigerResponse |
4 | 3 | from tigeropen.common.util.string_utils import get_string |
5 | 4 |
|
6 | 5 |
|
7 | 6 | class DepthEntryResponse(TigerResponse): |
8 | 7 | def __init__(self): |
9 | 8 | super(DepthEntryResponse, self).__init__() |
10 | | - self.depth_entry = [] |
| 9 | + self.depth_entry = dict() |
11 | 10 | self._is_success = None |
12 | 11 |
|
13 | 12 | def parse_response_content(self, response_content): |
14 | 13 | """ |
15 | | - :return: pandas.DataFrame |
16 | | - symbol ask_price ask_volume ask_count bid_price bid_volume bid_count |
17 | | - SYMBOL1 卖1价 卖1股数 卖1订单数 买1价 买1股数 买1订单数 |
18 | | - SYMBOL1 卖2价 卖2股数 卖2订单数 买2价 买2股数 买2订单数 |
19 | | - . |
20 | | - . |
21 | | - SYMBOL1 卖10价 卖10股数 卖10订单数 买10价 买10股数 买10订单数 |
22 | | -
|
23 | | -
|
24 | | - SYMBOL2 卖1价 卖1股数 卖1订单数 买1价 买1股数 买1订单数 |
25 | | - SYMBOL2 卖2价 卖2股数 卖2订单数 买2价 买2股数 买2订单数 |
26 | | - . |
27 | | - . |
28 | | - SYMBOL2 卖10价 卖10股数 卖10订单数 买10价 买10股数 买10订单数 |
| 14 | + :return: |
| 15 | + { '02833': { 'asks': [ |
| 16 | + { 'count': 1, 'price': 27, 'volume': 3100 }, |
| 17 | + { 'count': 0, 'price': 27.05, 'volume': 0 }, |
| 18 | + . |
| 19 | + . |
| 20 | + { 'count': 1, 'price': 27.45, 'volume': 300 }], |
| 21 | + 'bids': [ |
| 22 | + { 'count': 1, 'price': 26.85, 'volume': 1000 }, |
| 23 | + { 'count': 0, 'price': 26.8, 'volume': 0 }, |
| 24 | + . |
| 25 | + . |
| 26 | + { 'count': 0, 'price': 26.4, 'volume': 0 } ], |
| 27 | + 'symbol': '02833' }, |
| 28 | + '02828': { 'asks': [ |
| 29 | + { 'count': 3, 'price': 103.3, 'volume': 172200 }, |
| 30 | + . |
| 31 | + . |
| 32 | + { 'count': 2, 'price': 104.2, 'volume': 5200 } ], |
| 33 | + 'bids': [ |
| 34 | + { 'count': 3, 'price': 103.2, 'volume': 166200 }, |
| 35 | + . |
| 36 | + . |
| 37 | + { 'count': 1, 'price': 102.3, 'volume': 88800 } ], |
| 38 | + 'symbol': '02828' } |
| 39 | + } |
29 | 40 | """ |
30 | 41 | response = super(DepthEntryResponse, self).parse_response_content(response_content) |
31 | 42 | if 'is_success' in response: |
32 | 43 | self._is_success = response['is_success'] |
33 | 44 |
|
34 | 45 | if self.data and isinstance(self.data, list): |
35 | | - result = list() |
36 | 46 | for item in self.data: |
37 | 47 | symbol = get_string(item.get('symbol')) |
38 | | - asks = pd.DataFrame(item.get('asks', []))[['count', 'volume', 'price']].add_prefix('ask_') |
39 | | - bids = pd.DataFrame(item.get('bids', []))[['price', 'volume', 'count']].add_prefix('bid_') |
40 | | - merged_data = pd.concat([asks, bids], axis=1) |
41 | | - merged_data.insert(loc=0, column='symbol', value=symbol) |
42 | | - result.append(merged_data) |
43 | | - self.depth_entry = pd.concat(result) |
| 48 | + self.depth_entry[symbol] = item |
44 | 49 | return self.depth_entry |
45 | 50 |
|
46 | 51 |
|
0 commit comments