Skip to content

Commit

Permalink
Merge branch 'master' into error-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiocastrica authored Oct 6, 2023
2 parents 97e84fe + 6c2f399 commit 68527b6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ dmypy.json
#IDE configs
.idea
.vscode/

# Cloudflare stuff
Cloudflare_CA.pem
2 changes: 1 addition & 1 deletion alpaca/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.0"
__version__ = "0.12.0"
6 changes: 4 additions & 2 deletions alpaca/common/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def _cast(self, msg_type: str, msg: Dict) -> Union[BaseModel, RawData]:
"""
result = msg
if not self._raw_data:
# convert msgpack timestamp to nanoseconds

if "t" in msg:
msg["t"] = msg["t"].seconds * int(1e9) + msg["t"].nanoseconds
msg["t"] = msg["t"].to_datetime()

if "S" not in msg:
return msg
Expand Down Expand Up @@ -443,6 +443,8 @@ def run(self) -> None:
except KeyboardInterrupt:
print("keyboard interrupt, bye")
pass
finally:
self.stop()

def stop(self) -> None:
"""Stops the websocket connection."""
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "alpaca-py"
version = "0.11.0"
version = "0.12.0"
description = "The Official Python SDK for Alpaca APIs"
authors = [
"Rahul Chowdhury <[email protected]>",
Expand All @@ -18,7 +18,7 @@ include = [ "alpaca/py.typed" ]
python = "^3.8.0"
requests = "^2.30.0"
pydantic = "^2.0.3"
pandas = "^2.0.0"
pandas = ">=1.5.3"
msgpack = "^1.0.3"
websockets = "^11.0.3"
sseclient-py = "^1.7.2"
Expand Down
26 changes: 12 additions & 14 deletions tests/data/test_websockets.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
import pytest
from msgpack.ext import Timestamp

from alpaca.common.websocket import BaseStream
from alpaca.data.enums import Exchange
from alpaca.data.models import Bar, Trade


@pytest.fixture
def ws_client():
client = BaseStream("endpoint", "key-id", "secret-key")
return client
def ws_client() -> BaseStream:
"""Socket client fixture with pydantic models as output."""
return BaseStream("endpoint", "key-id", "secret-key")


@pytest.fixture
def raw_ws_client():
raw_client = BaseStream("endpoint", "key-id", "secret-key", raw_data=True)
return raw_client
def raw_ws_client() -> BaseStream:
"""Socket client fixture with raw data output."""
return BaseStream("endpoint", "key-id", "secret-key", raw_data=True)


@pytest.fixture
def timestamp():
class MockTimestamp:
def __init__(self, _seconds, _nanoseconds):
self.seconds = _seconds
self.nanoseconds = _nanoseconds
def timestamp() -> Timestamp:
"""Msgpack mock timestamp."""
return Timestamp(seconds=10, nanoseconds=10)

return MockTimestamp(0, 0)


def test_cast(ws_client, raw_ws_client, timestamp):
def test_cast(ws_client: BaseStream, raw_ws_client: BaseStream, timestamp: Timestamp):
"""Test the value error in case there's a different timestamp type."""
# Bar
bar_msg_type = "b"
bar_msg_dict = {
Expand Down

0 comments on commit 68527b6

Please sign in to comment.