smarkets.streaming_api package

smarkets.streaming_api.client module

smarkets.streaming_api.exceptions module

Core Smarkets API exceptions

exception smarkets.streaming_api.exceptions.ConnectionError

Bases: smarkets.errors.Error

TCP connection-related error

exception smarkets.streaming_api.exceptions.DecodeError

Bases: smarkets.errors.Error

Header decoding error

exception smarkets.streaming_api.exceptions.DownloadError

Bases: smarkets.errors.Error

Raised when a URL could not be fetched

exception smarkets.streaming_api.exceptions.InvalidCallbackError

Bases: smarkets.errors.Error

Invalid callback was specified

exception smarkets.streaming_api.exceptions.InvalidUrlError

Bases: smarkets.errors.Error

Raised when a URL is invalid

exception smarkets.streaming_api.exceptions.ParseError

Bases: smarkets.errors.Error

Error parsing a message or frame

exception smarkets.streaming_api.exceptions.SocketDisconnected

Bases: smarkets.errors.Error

Socket was disconnected while reading

smarkets.streaming_api.session module

Smarkets TCP-based session management

class smarkets.streaming_api.session.Session(settings, inseq=1, outseq=1, account_sequence=None)

Bases: object

Manages TCP communication via Smarkets streaming API

connect()

Connects to the API and logs in if not already connected

connected

Returns True if the socket is currently connected

disconnect()

Disconnects from the API

flush()

Flush payloads to the socket

logout()

Disconnects from the API

next_frame()

Get the next payload and increment inseq.

Warning

Payload returned by next_frame has to be consumed before next call to next_frame happens.

Returns:A payload or None if no payloads in buffer.
Return type:smarkets.streaming_api.session.Frame or None
raw_socket

Get raw socket used for communication with remote endpoint. :rtype: socket.socket

send()

Serialise, sequence, add header, and send payload

class smarkets.streaming_api.session.SessionSettings(username=None, password=None, token=None, host='stream.smarkets.com', port=3801, ssl=True, socket_timeout=30, ssl_kwargs=None, tcp_nodelay=True)

Bases: object

Encapsulate settings necessary to create a new session

class smarkets.streaming_api.session.SessionSocket(settings)

Bases: object

Wraps a socket with basic framing/deframing

connect()

Create a TCP socket connection.

Returns True if the socket needed connecting, False if not

connected

Returns True if the socket is currently connected

disconnect()

Close the TCP socket.

recv()

Read stuff from underlying socket.

Return type:byte string
send(byte_array)
Returns:Number of sent bytes
Return type:int