Smarkets Python SDK - API客户端和实用库
项目描述
Smarkets Streaming API Python客户端。
兼容Python 2.7, 3.5和PyPy 1.9+。
文档: http://smarkets-python-sdk.readthedocs.org/en/latest/
使用源分发安装
当使用PyPI分发安装smk-python-sdk时,没有非Python依赖。安装smk-python-sdk时,所有Python依赖都会为您自动获取。
PyPI页面: https://pypi.python.org/pypi/smk_python_sdk
pip install smk-python-sdk
入门指南
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()
注册回调
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)
下订单
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()
取消订单
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()
线程安全
此包中包含的函数和类成员是线程安全的。实例成员不是线程安全的。
开发
GitHub仓库: https://github.com/smarkets/smk_python_sdk/
非Python依赖
piqi
Google协议缓冲区编译器和库
您可以通过执行以下命令安装Python依赖项:
pip install -r requirements.txt
要构建和安装,请调用
python setup.py clean build install
注意:构建包不会从setup.py中的相应位置获取最新的piqi文件。为了做到这一点,您必须先调用python setup.py clean,然后调用python setup.py build。
许可证
版权(C)Smarkets Limited <support@smarkets.com>
此模块是根据MIT许可证发布的: https://open-source.org.cn/licenses/mit-license.php(或查看LICENSE文件)
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
smk_python_sdk-9.4.4.tar.gz (80.6 kB 查看哈希值)
构建分发
smk_python_sdk-9.4.4-py3-none-any.whl (67.3 kB 查看哈希值)
关闭
smk_python_sdk-9.4.4.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | bf614afed67d37adfefedcb031fb0072870fd6f68cd84a305c68f26527f1bf77 |
|
MD5 | 6a74533a8b9f9f41ebc31af7eda5d92e |
|
BLAKE2b-256 | 24fd0489df8a7b0b4580f6aabe322fb6127f8e96fcba1fbf1354770a9dc4c31e |
关闭
smk_python_sdk-9.4.4-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 16017c4eed8cff4c6f68ff0fc8a62b15fbbcacc468f67dfda86539b5c417f68f |
|
MD5 | d1e420371f511f244a0efae917038223 |
|
BLAKE2b-256 | f01266d48fb33b2309be82144c7fff03973e5a9a74970918cfe0f1845229bbc2 |