Skip to main content

Smarkets Python SDK - API clients and utility library

Project description

Build status

Smarkets Python library (streaming API client, id generation, more to come).

Compatible with Python 2.7 and PyPy 1.9+.

Documentation: http://smarkets-python-sdk.readthedocs.org/en/latest/

Installing using source distribution

When you install smk-python-sdk using PyPI distribution there are no non-Python dependencies. All the Python dependencies will be fetched for you when you install smk-python-sdk.

PyPI page: https://pypi.python.org/pypi/smk_python_sdk

pip install smk-python-sdk

Getting Started

import logging
logging.basicConfig(level=logging.DEBUG)

from smarkets.streaming_api.api import (
    BUY, GOOD_TIL_CANCELLED, OrderCreate, SessionSettings, Session, StreamingAPIClient)

username = 'username'
password = 'password'

settings = SessionSettings(username, password)
settings.host = 'api.smarkets.com'
settings.port = 3701

session = Session(settings)

client = StreamingAPIClient(session)

client.login()
client.ping()
client.read()
client.flush()

market_id = client.str_to_uuid128('fc024')

order = OrderCreate()
order.quantity = 400000 # £40 payout
order.price = 2500 # 25.00%
order.side = BUY
order.market = market_id
order.contract = client.str_to_uuid128('fcccc')
order.time_in_force = GOOD_TIL_CANCELLED

client.send(order)
client.logout()

Registering callbacks

from google.protobuf import text_format

def login_response(msg):
    print("eto.login_response", text_format.MessageToString(msg))

def global_callback(name, msg):
    print(name, text_format.MessageToString(msg))

client.add_handler('eto.login_response', login_response)
client.add_global_handler(global_callback)

Thread Safety

Functions and class members contained in this package are thread safe. Instance members are not thread safe.

Development

GitHub repository: https://github.com/smarkets/smk_python_sdk/

Non-Python dependencies:

  • piqi

  • Google protocol buffers compiler and libraries

You can install Python dependencies by executing:

pip install -r requirements-dev-py2.txt

To build and install call:

python setup.py clean build install

Note: building the package does not fetch the most recent piqi files from their respective locations in setup.py. In order to do so, you must call python setup.py clean, and then python setup.py build.

License

Copyright (C) 2011-2013 Smarkets Limited <support@smarkets.com>

This module is released under the MIT License: http://www.opensource.org/licenses/mit-license.php (or see the LICENSE file)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smk_python_sdk-1.3.4.tar.gz (63.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smk_python_sdk-1.3.4-py27-none-any.whl (53.5 kB view details)

Uploaded Python 2.7

File details

Details for the file smk_python_sdk-1.3.4.tar.gz.

File metadata

File hashes

Hashes for smk_python_sdk-1.3.4.tar.gz
Algorithm Hash digest
SHA256 1a3d3063348075e38fccb283223c4ee7ab7f0e66b63de77d2259165e039e6484
MD5 60a97dffa352ca383b32a4ce1a8e1688
BLAKE2b-256 ce95cd4fa4e7c5033e7b20005421aaf5e5b09fc9364a6b5d9b86e110eb5738da

See more details on using hashes here.

File details

Details for the file smk_python_sdk-1.3.4-py27-none-any.whl.

File metadata

File hashes

Hashes for smk_python_sdk-1.3.4-py27-none-any.whl
Algorithm Hash digest
SHA256 74a5767d351c8e0e867cc42cbe55e03f9236180c34e5b1317d564de4fd9a5fce
MD5 c48868916e7523dffaea2ecb2ab869b1
BLAKE2b-256 122cb8a4f5da8478ab58e95ee5f2f9530c9cddfb1b84a178f5a2f7786086cedf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page