Skip to content

Commit c2b4b85

Browse files
committed
fix authenticated order book and add test
1 parent 7e992ca commit c2b4b85

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

gdax/orderbook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async def _subscribe(self):
131131
message['key'] = self.api_key
132132
message['passphrase'] = self.passphrase
133133

134-
return await self._send(type='subscribe', product_ids=self.product_ids)
134+
return await self._send(**message)
135135

136136
async def handle_message(self):
137137
try:

tests/test_orderbook.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import pytest
2-
import gdax
3-
import gdax.orderbook
41
import json
5-
import asyncio
6-
from asynctest import MagicMock, patch, CoroutineMock, call
72
import uuid
3+
import base64
84
from decimal import Decimal
95

6+
import asyncio
7+
import pytest
8+
from asynctest import MagicMock, patch, CoroutineMock, call
9+
10+
import gdax
11+
import gdax.orderbook
12+
1013

1114
class AsyncContextManagerMock(MagicMock):
1215
async def __aenter__(self):
@@ -204,3 +207,27 @@ async def test_heartbeat(self, mock_book, mock_connect):
204207
heartbeat_msg = {'type': 'heartbeat', 'on': True}
205208
calls = [call(subscribe_msg), call(heartbeat_msg)]
206209
mock_connect.return_value.aenter.send_json.assert_has_calls(calls)
210+
211+
@patch('gdax.trader.Trader.get_product_order_book')
212+
async def test_authentication(self, mock_book, mock_connect, mocker):
213+
mock_connect.return_value.aenter.send_json = CoroutineMock()
214+
mock_book.return_value = {'bids': [], 'asks': [], 'sequence': 1}
215+
timestamp = '1493343391.076892'
216+
mocker.patch('time.time', return_value=timestamp)
217+
product_ids = ['ETH-USD']
218+
async with gdax.orderbook.OrderBook(
219+
product_ids,
220+
api_key='a',
221+
api_secret=base64.b64encode(b'a' * 64),
222+
passphrase='b',
223+
) as orderbook:
224+
msg = {
225+
'type': 'subscribe',
226+
'product_ids': product_ids,
227+
'signature': '5qne58tAXSW3OJlU/GoC+/mTLF1xgT8vucjJWFZzhsU=',
228+
'timestamp': timestamp,
229+
'key': 'a',
230+
'passphrase': 'b',
231+
}
232+
assert orderbook._authenticated
233+
mock_connect.return_value.aenter.send_json.assert_called_with(msg)

0 commit comments

Comments
 (0)