forked from JohnnyZhao/peatio-client-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.py
81 lines (62 loc) · 2.15 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import time
import urllib2
from lib.client import Client, get_api_path
client = Client(access_key='your access key', secret_key='your secret key')
#demo of GET APIs
#get member info
print client.get(get_api_path('members'))
#get markets
markets = client.get(get_api_path('markets'))
print "markets:", markets
#get tickers of each market
#market should be specified in url
print
print "tickers in markets"
for market in markets:
print client.get(get_api_path('tickers') % market['id'])
#get orders of each market
#market should be specified in params
print
print "orders in markets"
for market in markets:
print client.get(get_api_path('orders'), {'market': market['id']})
#get order book
print client.get(get_api_path('order_book'), params={'market': 'btccny'})
#get tardes
print client.get(get_api_path('trades'), params={'market': 'btccny'})
#get my trades
print client.get(get_api_path('my_trades'), params={'market': 'btccny'})
#get k line
print client.get(get_api_path('k'), params={'market': 'btccny'})
#demo of POST APIs
#DANGROUS, you better use test account to debug POST APIs
"""
markets = client.get(get_api_path('markets'))
print markets
#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 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)
print res
#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)
print res
"""