Metadata-Version: 2.0
Name: smk-python-sdk
Version: 0.5.3
Summary: Python client for Smarkets streaming API
Home-page: https://github.com/smarkets/smk_python_sdk
Author: Smarkets Limited
Author-email: support@smarkets.com
License: MIT
Download-URL: https://github.com/smarkets/smk_python_sdk/downloads/smk_python_sdk-0.5.3.tar.gz
Keywords: Smarkets,betting exchange
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Requires-Dist: protobuf
Requires-Dist: six

# smarkets

Python API client for Smarkets.

[![Build Status](https://travis-ci.org/smarkets/smk_python_sdk.png?branch=master)](https://travis-ci.org/smarkets/smk_python_sdk)

## Getting the code

* https://github.com/smarkets/smk_python_sdk/

## Requirements

* Python >= 2.6
* Google protocol buffers compiler and libraries

### For building the code, running tests and generating documentation

    $ pip install -r requirements-dev.txt

## Installation

To install:

    $ pip install smk_python_sdk

or if you want to build it yourself:

    $ python setup.py build install

## Getting Started

```python
import logging
logging.basicConfig(level=logging.DEBUG)
import smarkets
username = 'username'
password = 'password'
settings = smarkets.SessionSettings(username, password)
settings.host = 'api.smarkets.com'
settings.port = 3701
session = smarkets.Session(settings)
client = smarkets.Smarkets(session)
client.login()
client.ping()
client.flush()
client.read()
market_id = client.str_to_uuid128('fc024')
client.subscribe(market_id) # subscribe to a market
client.flush()
client.read()
order = smarkets.Order()
order.quantity = 400000 # £40 payout
order.price = 2500 # 25.00%
order.side = smarkets.Order.BUY
order.market = market_id
order.contract = client.str_to_uuid128('fcccc')
client.order(order)
client.flush()
client.read()
client.logout()
```

### Registering callbacks

```python
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)
```

## Connections

The `smarkets.sessions.SessionSocket` class wraps the vanilla Python
`socket.socket` class, providing the basic framing and padding
functionality. It opens a single TCP connection and keeps it open for
the duration of the session.


## Thread Safety

It is not safe to share `smarkets.clients.Smarkets` or
`smarkets.sessions.Session` objects between threads. Only a single
thread should call the `Smarkets.flush()` method (or others which
trigger a send) at a time. Similarly, a single thread should call
`Smarkets.read()` at a time. See the `ThreadingTestCase` in
`tests/threading_tests.py` for an example on appropriate
multi-threaded usage.


