Skip to content

Commit aaa373e

Browse files
author
Sam McHardy
authored
Merge pull request sammchardy#55 from Beskhue/buffer-depth-updates
Buffer depth update messages prior to snapshot
2 parents 8c411e6 + 24be774 commit aaa373e

5 files changed

Lines changed: 33 additions & 5 deletions

File tree

PYPIREADME.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
================================
2-
Welcome to python-binance v0.5.8
2+
Welcome to python-binance v0.5.9
33
================================
44

55
.. image:: https://img.shields.io/pypi/v/python-binance.svg

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
================================
2-
Welcome to python-binance v0.5.8
2+
Welcome to python-binance v0.5.9
33
================================
44

55
.. image:: https://img.shields.io/pypi/v/python-binance.svg

binance/depthcache.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@ def __init__(self, client, symbol, callback=None):
132132
self._client = client
133133
self._symbol = symbol
134134
self._callback = callback
135-
self._first_update_id = 0
135+
self._first_update_id = None
136+
self._depth_message_buffer = []
136137
self._bm = None
137138
self._depth_cache = DepthCache(self._symbol)
138139

139-
self._init_cache()
140140
self._start_socket()
141+
self._init_cache()
141142

142143
def _init_cache(self):
143144
res = self._client.get_order_book(symbol=self._symbol, limit=500)
@@ -149,6 +150,11 @@ def _init_cache(self):
149150
for ask in res['asks']:
150151
self._depth_cache.add_ask(ask)
151152

153+
for msg in self._depth_message_buffer:
154+
self._process_depth_message(msg)
155+
156+
del self._depth_message_buffer
157+
152158
def _start_socket(self):
153159
self._bm = BinanceSocketManager(self._client)
154160

@@ -162,6 +168,21 @@ def _depth_event(self, msg):
162168
:param msg:
163169
:return:
164170
171+
"""
172+
173+
if self._first_update_id is None:
174+
# Initial depth snapshot fetch not yet performed, buffer messages
175+
self._depth_message_buffer.append(msg)
176+
return
177+
178+
self._process_depth_message(msg)
179+
180+
def _process_depth_message(self, msg):
181+
"""Process a depth event message.
182+
183+
:param msg: Depth event message.
184+
:return:
185+
165186
"""
166187
# ignore any updates before the initial update id
167188
if msg['u'] <= self._first_update_id:

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
v0.5.9 - 2017-12-26
5+
^^^^^^^^^^^^^^^^^^^
6+
7+
**Fixed**
8+
9+
- fixed websocket reconnecting, was no distinction between manual close or network error
10+
411
v0.5.8 - 2017-12-25
512
^^^^^^^^^^^^^^^^^^^
613

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='python-binance',
6-
version='0.5.8',
6+
version='0.5.9',
77
packages=['binance'],
88
description='Binance REST API python implementation',
99
url='https://github.com/sammchardy/python-binance',

0 commit comments

Comments
 (0)