This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Smarkets Python SDK - API clients and utility library

Project Description

Smarkets Streaming API Python client.

Compatible with Python 2.7, 3.5 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 (
    SessionSettings, Session, StreamingAPIClient,
)

username = 'username'
password = 'password'

settings = SessionSettings(username, password)
settings.host = 'stream.smarkets.com'

session = Session(settings)

client = StreamingAPIClient(session)

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

client.logout()

Registering callbacks

def login_response(message):
    print('eto.login_response', msg)

def global_callback(name, message):
    print(name, message.protobuf)

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

Placing orders

from smarkets.streaming_api.api import SIDE_BID
from smarkets.streaming_api.seto import OrderCreate

def order_accepted(message):
    reference = message.order_accepted.reference
    order_id = message.order_accepted.order_id
    print(
        'ORDER_ACCEPTED: reference {} corresponding to order_id {}'.format(
            reference, order_id,
        )
    )

def order_rejected(message):
    reference = message.order_rejected.reference
    reason = message.order_rejected.reason
    print('ORDER_REJECTED with reference {} with reason {}'.format(reference, reason))

client.add_handler('seto.order_accepted', order_accepted)
client.add_handler('seto.order_rejected', order_rejected)

market_id = 100000
contract_id = 200000

order = OrderCreate()
order.quantity = 400000 # £40 payout
order.price = 2500 # 25.00%
order.side = SIDE_BID
order.market_id = market_id
order.contract_id = contract_id

client.send(order)
client.flush()

Cancelling orders

from smarkets.streaming_api.seto import OrderCancel

order_id = ...  # received in seto.order_accepted message

def order_cancelled(message):
    order_id = message.order_cancelled.order_id
    reason = message.order_cancelled.reason
    print('ORDER_CANCELLED order_id {} with reason {}'.format(order_id, reason))

def order_cancel_rejected(message):
    order_id = message.order_cancel_rejected.order_id
    reason = message.order_cancel_rejected.reason
    print('ORDER_CANCEL_REJECTED: with order_id {} with reason {}'.format(order_id, reason))

client.add_handler('seto.order_cancelled', order_cancelled)
client.add_handler('seto.order_cancel_rejected', order_cancel_rejected)

cancel = OrderCancel()
cancel.order_id = order_id
client.send(cancel)
client.flush()

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.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) 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)

Release History

Release History

This version
History Node

9.2.0

History Node

9.1.3

History Node

9.1.2

History Node

9.1.1

History Node

9.1.0

History Node

8.0.2

History Node

8.0.1

History Node

8.0.0

History Node

7.0.1

History Node

7.0.0

History Node

6.4.0

History Node

6.3.0

History Node

6.2.0

History Node

6.1.0

History Node

5.0.0

History Node

4.1.2

History Node

4.1.0

History Node

4.0.0

History Node

3.0.2

History Node

3.0.1

History Node

3.0.0

History Node

2.0.0

History Node

1.5.5

History Node

1.5.4

History Node

1.5.3

History Node

1.5.1

History Node

1.5.0

History Node

1.4.6

History Node

1.4.5

History Node

1.4.4

History Node

1.4.3

History Node

1.4.2

History Node

1.4.1

History Node

1.4.0

History Node

1.3.8

History Node

1.3.7

History Node

1.3.6

History Node

1.3.5

History Node

1.3.4

History Node

1.3.3

History Node

1.3.2

History Node

1.3.1

History Node

1.3.0

History Node

1.2.9

History Node

1.2.8

History Node

1.2.7

History Node

1.2.6

History Node

1.2.5

History Node

1.2.4

History Node

1.2.3

History Node

1.2.2

History Node

1.2.1

History Node

1.2.0

History Node

1.1.13

History Node

1.1.12

History Node

1.1.11

History Node

1.1.10

History Node

1.1.9

History Node

1.1.5

History Node

1.1.4

History Node

1.1.3

History Node

1.1.2

History Node

1.1.1

History Node

1.1.0

History Node

1.0.14

History Node

1.0.13

History Node

1.0.12

History Node

1.0.11

History Node

1.0.10

History Node

1.0.9

History Node

1.0.8

History Node

1.0.7

History Node

1.0.6

History Node

1.0.5

History Node

1.0.4

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0c1

History Node

0.6.7

History Node

0.6.6

History Node

0.6.5

History Node

0.6.4

History Node

0.6.3

History Node

0.6.2

History Node

0.6.0

History Node

0.6.0c2

History Node

0.6.0c1

History Node

0.5.3

History Node

0.5.2

History Node

0.5.1

History Node

0.5.0

History Node

0.4.15

History Node

0.4.14

History Node

0.4.13

History Node

0.4.12

History Node

0.4.11

History Node

0.4.10

History Node

0.4.9

History Node

0.4.8

History Node

0.3.3

History Node

0.3.2

History Node

0.3.1

History Node

0.2.1

History Node

0.2.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
smk_python_sdk-9.2.0.tar.gz (74.8 kB) Copy SHA256 Checksum SHA256 Source Mar 22, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting