-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample.py
More file actions
44 lines (35 loc) · 1.27 KB
/
Copy pathsample.py
File metadata and controls
44 lines (35 loc) · 1.27 KB
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
from dateutil import parser
from jsonrpc import proxy
import pprint
from time import sleep
def deserializeStat(data):
"""convert dates back to python objects"""
if 'timestamp' in data:
data['timestamp'] = parser.parse(data['timestamp'])
if 'transactions' in data:
txs = data['transactions']
for tx in txs:
tx['date'] = parser.parse(tx['date'])
if 'dividends' in data:
divs = data['dividends']
for div in divs:
div['date'] = parser.parse(div['date'])
return data
def readonlyExample(mpexproxy,pp):
#just a STAT call
statres = mpexproxy.statjson()
pp.pprint(deserializeStat(statres))
def placeCancelExample(mpexproxy,pp):
#new order to buy 1 S.MPOE at 0.00023456 BTC
res = mpexproxy.neworder('B','S.MPOE',1,23456)
pp.pprint(res)
sleep(5)
statres = mpexproxy.stat()
#cancels first order in stat list (it might be different order than we just placed!)
res = mpexproxy.cancel(statres['orders'].keys()[0])
pp.pprint(res)
if __name__ == '__main__':
mpexproxy = proxy.JSONRPCProxy('http://localhost:8077', '/jsonrpc')
pp = pprint.PrettyPrinter(indent=2)
readonlyExample(mpexproxy,pp)
#placeCancelExample(mpexproxy,pp)