Skip to content

Commit f3d78c2

Browse files
author
Kai Su
committed
modified: tigeropen/quote/response/quote_depth_entry_response.py
1 parent 6f525bf commit f3d78c2

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed
Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
11
# -*- coding: utf-8 -*-
2-
import pandas as pd
32
from tigeropen.common.response import TigerResponse
43
from tigeropen.common.util.string_utils import get_string
54

65

76
class DepthEntryResponse(TigerResponse):
87
def __init__(self):
98
super(DepthEntryResponse, self).__init__()
10-
self.depth_entry = []
9+
self.depth_entry = dict()
1110
self._is_success = None
1211

1312
def parse_response_content(self, response_content):
1413
"""
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+
}
2940
"""
3041
response = super(DepthEntryResponse, self).parse_response_content(response_content)
3142
if 'is_success' in response:
3243
self._is_success = response['is_success']
3344

3445
if self.data and isinstance(self.data, list):
35-
result = list()
3646
for item in self.data:
3747
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
4449
return self.depth_entry
4550

4651

0 commit comments

Comments
 (0)