Giter Club home page Giter Club logo

peatio-client-python's Introduction

peatio-client-python

A simple python client for Crypto Trade Site Peatio.com

Usage

Membership API

from lib.client import Client, get_api_path

client = Client(access_key='your access key', secret_key='your secret key')

#get members API url using get_api_path by key 'members'
#API mapping of get_api_path
{
    'my_trades'   : '/api/v2/trades/my.json'
    'members'     : '/api/v2/members/me.json'
    'orders'      : '/api/v2/orders.json'
    'delete_order': '/api/v2/order/delete.json'
    'order_book'  : '/api/v2/order_book.json'
    'clear'       : '/api/v2/orders/clear.json'
    'trades'      : '/api/v2/trades.json'
    'order'       : '/api/v2/order.json'
    'multi_orders': '/api/v2/orders/multi.json'
    'tickers'     : '/api/v2/tickers/{market}.json'
    'markets'     : '/api/v2/markets.json'
    'k'           : '/api/v2/k.json'
}

url = get_api_path('members')


#or you can give url a plain text, just like this:
url = "/api/v2/members/me.json"

#send request
res = client.get(url)

#if your access key and secret are correct, res should be a dictionary like this:
{
    u'email': u'zhaoyu.johnny@@gmail.com', 
    u'activated': True, 
    u'sn': u'PEAA*******', 
    u'name': u'JohnnyZhao',
    u'accounts': 
        [
            {u'currency': u'cny', 
             u'balance': u'1000', 
             u'locked': u'0.0'}, 
            {u'currency': u'btc', 
             u'balance': u'31', 
             u'locked': u'0.0'}, 
            {u'currency': u'pts', 
             u'balance': u'60', 
             u'locked': u'0.0'}, 
            {u'currency': u'dog', 
             u'balance': u'23952', 
             u'locked': u'11.0'}
        ], 
}

Markets API

#get markets
markets =  client.get(get_api_path('markets'))
print markets

#markets should be a list like this
[
    {u'id': u'btccny', u'name': u'BTC/CNY'}, 
    {u'id': u'ptscny', u'name': u'PTS/CNY'}, 
    {u'id': u'dogcny', u'name': u'DOG/CNY'}, 
    {u'id': u'dogbtc', u'name': u'DOG/BTC'}
]

Orders API

#get your orders in a specific market
orders = client.get(get_api_path('orders'), {'market': 'btccny'})
print orders

#orders will be an empty list or list like this
[
    {u'created_at': u'2014-07-05T14:56:25+08:00', 
     u'remaining_volume': u'11.0', 
     u'price': u'0.01', 
     u'side': u'sell', 
     u'volume': u'11.0', 
     u'state': u'wait', 
     u'avg_price': u'0.0', 
     u'executed_volume': u'0.0', 
     u'id': 299751, 
     u'market': u'dogcny'
    }
]

#create new order
#sell 10 dogecoins at price 0.01
params = {'market': 'dogcny', 'side': 'sell', 'volume': 10, 'price': 0.01}
res = client.post(get_api_path('orders'), params)
print res

#buy 10 dogecoins at price 0.001
params = {'market': 'dogcny', 'side': 'buy', 'volume': 10, 'price': 0.001}
res = client.post(get_api_path('orders'), params)
print res

#clear orders
#clear all orders in all markets
res = client.post(get_api_path('clear'))
print res

#delete a specific order by order_id
#first, let's create an sell order
#sell 10 dogecoins at price 0.01
params = {'market': 'dogcny', 'side': 'sell', 'volume': 12, 'price': 0.01}
res = client.post(get_api_path('orders'), params)
print res
order_id = res['id']

#delete this order
params = {"id": order_id}
res = client.post(get_api_path('delete_order'), params)

#create multi orders
params = {'market': 'dogcny', 'orders': [{'side': 'buy', 'volume': 12, 'price': 0.0002}, {'side': 'sell', 'volume': 11, 'price': 0.01}]}
res = client.post(get_api_path('multi_orders'), params)

More demos

for more usage demos, checkout demo.py file

Contribute

Pull requests are welcomed

peatio-client-python's People

Contributors

johnnyzhao avatar

Watchers

Ben Haim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.