当前位置: 首页 > 软件库 > Web3 > 开源货币/比特币 >

python-kucoin

授权协议 MIT License
开发语言 Python
所属分类 Web3、 开源货币/比特币
软件类型 开源软件
地区 不详
投 递 者 夏季萌
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Welcome to python-kucoin v2.1.1

This is an unofficial Python wrapper for the Kucoin exchanges REST and Websocket API v2.I am in no way affiliated with Kucoin, use at your own risk.

PyPi
https://pypi.python.org/pypi/python-kucoin
Source code
https://github.com/sammchardy/python-kucoin
Documentation
https://python-kucoin.readthedocs.io/en/latest/
Blog with examples
https://sammchardy.github.io

Features

  • Implementation of REST endpoints
  • Simple handling of authentication
  • Response exception handling
  • Implement websockets (note only python3.5+)

TODO

  • L2 and L3 Local Order Books

Quick Start

Register an account with Kucoin.

To test on the Sandbox register with Kucoin Sandbox.

Generate an API Keyor Generate an API Key in Sandbox and enable it.

pip install python-kucoin
from kucoin.client import Client

api_key = '<api_key>'
api_secret = '<api_secret>'
api_passphrase = '<api_passphrase>'

client = Client(api_key, api_secret, api_passphrase)

# or connect to Sandbox
# client = Client(api_key, api_secret, api_passphrase, sandbox=True)

# get currencies
currencies = client.get_currencies()

# get market depth
depth = client.get_order_book('KCS-BTC')

# get symbol klines
klines = client.get_kline_data('KCS-BTC')

# get list of markets
markets = client.get_markets()

# place a market buy order
order = client.create_market_order('NEO', Client.SIDE_BUY, size=20)

# get list of active orders
orders = client.get_active_orders('KCS-BTC')

Websockets

Note only for python3.5+

import asyncio

from kucoin.client import Client
from kucoin.asyncio import KucoinSocketManager

api_key = '<api_key>'
api_secret = '<api_secret>'
api_passphrase = '<api_passphrase>'


async def main():
    global loop

    # callback function that receives messages from the socket
    async def handle_evt(msg):
        if msg['topic'] == '/market/ticker:ETH-USDT':
            print(f'got ETH-USDT tick:{msg["data"]}')

        elif msg['topic'] == '/market/snapshot:BTC':
            print(f'got BTC market snapshot:{msg["data"]}')

        elif msg['topic'] == '/market/snapshot:KCS-BTC':
            print(f'got KCS-BTC symbol snapshot:{msg["data"]}')

        elif msg['topic'] == '/market/ticker:all':
            print(f'got all market snapshot:{msg["data"]}')

        elif msg['topic'] == '/account/balance':
            print(f'got account balance:{msg["data"]}')

        elif msg['topic'] == '/market/level2:KCS-BTC':
            print(f'got L2 msg:{msg["data"]}')

        elif msg['topic'] == '/market/match:BTC-USDT':
            print(f'got market match msg:{msg["data"]}')

        elif msg['topic'] == '/market/level3:BTC-USDT':
            if msg['subject'] == 'trade.l3received':
                if msg['data']['type'] == 'activated':
                    # must be logged into see these messages
                    print(f"L3 your order activated: {msg['data']}")
                else:
                    print(f"L3 order received:{msg['data']}")
            elif msg['subject'] == 'trade.l3open':
                print(f"L3 order open: {msg['data']}")
            elif msg['subject'] == 'trade.l3done':
                print(f"L3 order done: {msg['data']}")
            elif msg['subject'] == 'trade.l3match':
                print(f"L3 order matched: {msg['data']}")
            elif msg['subject'] == 'trade.l3change':
                print(f"L3 order changed: {msg['data']}")

    client = Client(api_key, api_secret, api_passphrase)

    ksm = await KucoinSocketManager.create(loop, client, handle_evt)

    # Note: try these one at a time, if all are on you will see a lot of output

    # ETH-USDT Market Ticker
    await ksm.subscribe('/market/ticker:ETH-USDT')
    # BTC Symbol Snapshots
    await ksm.subscribe('/market/snapshot:BTC')
    # KCS-BTC Market Snapshots
    await ksm.subscribe('/market/snapshot:KCS-BTC')
    # All tickers
    await ksm.subscribe('/market/ticker:all')
    # Level 2 Market Data
    await ksm.subscribe('/market/level2:KCS-BTC')
    # Market Execution Data
    await ksm.subscribe('/market/match:BTC-USDT')
    # Level 3 market data
    await ksm.subscribe('/market/level3:BTC-USDT')
    # Account balance - must be authenticated
    await ksm.subscribe('/account/balance')

    while True:
        print("sleeping to keep loop open")
        await asyncio.sleep(20, loop=loop)


if __name__ == "__main__":

    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

For more check out the documentation.

Donate

If this library helped you out feel free to donate.

  • ETH: 0xD7a7fDdCfA687073d7cC93E9E51829a727f9fE70
  • NEO: AVJB4ZgN7VgSUtArCt94y7ZYT6d5NDfpBo
  • LTC: LPC5vw9ajR1YndE1hYVeo3kJ9LdHjcRCUZ
  • BTC: 1Dknp6L6oRZrHDECRedihPzx2sSfmvEBys

Other Exchanges

If you use Binance check out my python-binance library.

If you use Binance Chain check out my python-binance-chain library.

If you use Allcoin check out my python-allcoin library.

If you use IDEX check out my python-idex library.

If you use BigONE check out my python-bigone library.

  • scipy.signal ——信号处理,卷积,差值,傅里叶变换,滤波等。 一维信号卷积 import numpy as np import scipy a1 = np.array([1,2,3]) a2 = np.array([4,5,6]) scipy.signal.convolve(a1,a2) #array([4,13,28,27,18]) 这里进行了卷积运算,所谓卷积运算,就是先将第二个

 相关资料
  • 我有一个数据框我想选择列A的值在[2,3]中的行 为此,我编写了一个简单的for循环: 有没有任何内置函数可以代替使用for循环来实现这一点?

  • Python Python 诞生之初就被誉为最容易上手的编程语言。进入火热的 AI 人工智能时代后,它也逐渐取代 Java,成为编程界的头牌语言。 Python 是一门新手友好、功能强大、高效灵活的编程语言,学会之后无论是想进入数据分析、人工智能、网站开发这些领域,还是希望掌握第一门编程语言,都可以用 Python 来开启无限未来的无限可能! 语言排行榜 编程之旅 Python 适合谁来学习? 想

  • 一些相关名词 Python 是一门简单的高级动态语言,首次发布于 1991 年。它语法简单,使用缩进来定义代码块。 Python 支持命令式程序设计、面向对象、函数式编程、面向方面的程序设计、泛型等多种编程范式, 是一门优秀的多范式语言。 名词解释 技术名词 名词 解释 Python 通常指 Python 语言本身,并不包括可执行程序,但是在口语中常常与 Python 解释器混用。 CPython

  • 为了在python中运用mongols,我提供了一个pymongols。它包括http_server和web_server。 仓库在pymongols 依赖 mongols python2,3 devel 安装 很简单,cd pymongols && make clean && make && sudo make install 修改Makefile中的PYVERSION变量即可轻松适配开发者版本

  • Python (发音:[ 'paiθ(ə)n; (US) 'paiθɔn ]n.蟒蛇,巨蛇 ),是一种面向对象的解释性的计算机程序设计语言,也是一种功能强大而完善的通用型语言,已经具有十多年的发展历史,成熟且稳定。Python 具有脚本语言中最丰富和强大的类库,足以支持绝大多数日常应用。 Python 语言的特点: 简单————Python是一种代表简单主义思想的语言。阅读一个良好的Python程

  • 用Python编写的代码看起来与用其他传统编程语言(如C或Pascal)编写的代码非常相似。 还有人说,Python的语法是从C语言中大量借用的。这包括许多类似于C语言的Python关键字。 Python包括条件语句和循环语句,可用于准确提取数据以进行取证。 对于流控制,它提供if/else , while和循环遍历任何“可迭代”对象的高级for语句。 if a < b: max = b