Skip to content

Commit 97ef8eb

Browse files
author
方佳
committed
Merge branch 'main_merge_26083110' into 'main'
feat:Support the callback of the notice message See merge request webull/webull-openapi-python-sdk!42
2 parents 060dd89 + f66608f commit 97ef8eb

5 files changed

Lines changed: 42 additions & 5 deletions

File tree

‎webull/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.18'
1+
__version__ = '2.0.19'

‎webull/data/data_streaming_client.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
from webull.data.quotes.subscribe.event_snapshot_decoder import EventSnapshotDecoder
2121
from webull.data.quotes.subscribe.event_tick_decoder import EventTickDecoder
2222
from webull.data.quotes.subscribe.payload_type import PAYLOAD_TYPE_QUOTE, PAYLOAD_TYPE_SHAPSHOT, PAYLOAD_TYPE_TICK, \
23-
PAYLOAD_TYPE_EVENT_SHAPSHOT, PAYLOAD_TYPE_EVENT_DEPTH, PAYLOAD_TYPE_EVENT_TICK
23+
PAYLOAD_TYPE_EVENT_SHAPSHOT, PAYLOAD_TYPE_EVENT_DEPTH, PAYLOAD_TYPE_EVENT_TICK, PAYLOAD_TYPE_NOTICE
2424
from webull.data.quotes.subscribe.quote_decoder import QuoteDecoder
2525
from webull.data.quotes.subscribe.snapshot_decoder import SnapshotDecoder
2626
from webull.data.quotes.subscribe.tick_decoder import TickDecoder
27+
from webull.data.quotes.subscribe.notice_decoder import NoticeDecoder
2728

2829

2930
class DataStreamingClient(QuotesClient):
@@ -46,6 +47,7 @@ def __init__(self, app_key, app_secret, region_id, session_id, http_host=None,
4647
self.register_payload_decoder(PAYLOAD_TYPE_EVENT_DEPTH, EventDepthDecoder())
4748
self.register_payload_decoder(PAYLOAD_TYPE_EVENT_SHAPSHOT, EventSnapshotDecoder())
4849
self.register_payload_decoder(PAYLOAD_TYPE_EVENT_TICK, EventTickDecoder())
50+
self.register_payload_decoder(PAYLOAD_TYPE_NOTICE, NoticeDecoder())
4951

5052
@property
5153
def on_connect_success(self):

‎webull/data/internal/quotes_client.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _quotes_message(client, userdata, message):
8383
client._easy_log(
8484
LOG_DEBUG, 'decoded message topic: %s, payload: %s', decoded[0], decoded[1])
8585
_on_quotes_message = client._on_quotes_message
86-
no_callback_topic = ['echo','notice']
86+
no_callback_topic = ['echo']
8787
if _on_quotes_message and decoded[0] not in no_callback_topic:
8888
_on_quotes_message(client, decoded[0], decoded[1])
8989
else:
@@ -115,7 +115,7 @@ def _quotes_on_connect(client, userdata, flags, rc):
115115

116116
self._quotes_message = _quotes_message
117117
self._quotes_on_connect = _quotes_on_connect
118-
mqttc.Client.__init__(self, self._client_id, transport=transport, reconnect_on_failure=False)
118+
mqttc.Client.__init__(self, client_id=self._client_id, transport=transport, reconnect_on_failure=False)
119119
self.username_pw_set(self._app_key, uuid.uuid4().hex)
120120
if tls_enable:
121121
self.tls_set()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2022 Webull
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# coding=utf-8
16+
17+
import json
18+
19+
from webull.data.internal.quotes_payload_decoder import BaseQuotesPayloadDecoder
20+
21+
22+
class NoticeDecoder(BaseQuotesPayloadDecoder):
23+
"""Decoder for notice messages from the server.
24+
25+
Notice messages are JSON-encoded and include:
26+
- type '1001': status message with rtt, drop, sent fields
27+
- type '1002': permission preemption with content field
28+
"""
29+
30+
def __init__(self):
31+
super().__init__()
32+
33+
def parse(self, payload):
34+
return json.loads(payload.decode("utf-8"))

‎webull/data/quotes/subscribe/payload_type.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
PAYLOAD_TYPE_TICK = 'tick'
2020
PAYLOAD_TYPE_EVENT_DEPTH = 'event-quote'
2121
PAYLOAD_TYPE_EVENT_SHAPSHOT = 'event-snapshot'
22-
PAYLOAD_TYPE_EVENT_TICK = 'event-tick'
22+
PAYLOAD_TYPE_EVENT_TICK = 'event-tick'
23+
PAYLOAD_TYPE_NOTICE = 'notice'

0 commit comments

Comments
 (0)