-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy path__init__.py
More file actions
97 lines (80 loc) · 2.74 KB
/
__init__.py
File metadata and controls
97 lines (80 loc) · 2.74 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Copyright (C) 2017 PyWaves Developers
#
# This file is part of PyWaves.
#
# It is subject to the license terms in the LICENSE file found in the top-level
# directory of this distribution.
#
# No part of python-bitcoinlib, including this file, may be copied, modified,
# propagated, or distributed except according to the terms contained in the
# LICENSE file.
from __future__ import absolute_import, division, print_function, unicode_literals
DEFAULT_TX_FEE = 100000
DEFAULT_ASSET_FEE = 100000000
DEFAULT_MATCHER_FEE = 1000000
DEFAULT_LEASE_FEE = 100000
import requests
from .address import *
from .asset import *
from .order import *
NODE = 'https://nodes.wavesnodes.com'
CHAIN = 'mainnet'
CHAIN_ID = 'W'
PYWAVES_DIR = os.path.expanduser("~") + "/.pywaves"
MATCHER = 'http://dev.pywaves.org:6886'
MATCHER_PUBLICKEY = ''
if not os.path.exists(PYWAVES_DIR):
os.makedirs(PYWAVES_DIR)
logging.basicConfig(filename=('%s/pywaves.log' % PYWAVES_DIR),
format='%(asctime)-15s [%(levelname)s] %(message)s',
level=logging.INFO)
logging.getLogger("requests").setLevel(logging.WARNING)
console = logging.StreamHandler()
console.setLevel(logging.ERROR)
formatter = logging.Formatter('[%(levelname)s] %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
def setNode(node = NODE, chain = CHAIN):
global NODE, CHAIN, CHAIN_ID
NODE = node
if chain.lower()=='mainnet' or chain.lower()=='w':
CHAIN = 'mainnet'
CHAIN_ID = 'W'
else:
CHAIN = 'testnet'
CHAIN_ID = 'T'
logging.info('Connecting to %s node %s' % (CHAIN, NODE))
def setMatcher(node = MATCHER):
global MATCHER, MATCHER_PUBLICKEY
try:
MATCHER_PUBLICKEY = wrapper('/matcher', host = node)
MATCHER = node
logging.info('Setting matcher %s %s' % (MATCHER, MATCHER_PUBLICKEY))
except:
MATCHER_PUBLICKEY = ''
def wrapper(api, postData='', host=''):
if not host:
host = NODE
if postData:
req = requests.post('%s%s' % (host, api), data=postData, headers={'content-type': 'application/json'}).json()
else:
req = requests.get('%s%s' % (host, api)).json()
return req
def height():
return wrapper('/blocks/height')['height']
def lastblock():
return wrapper('/blocks/last')
def block(n):
return wrapper('/blocks/at/%d' % n)
def tx(id):
return wrapper('/transactions/info/%s' % id)
def getOrderBook(assetPair):
req = wrapper('/matcher/orderBook?asset1=%s&asset2=%s' % (assetPair.asset1, assetPair.asset2), '', host = 'http://%s:%s' % (pywaves.MATCHER_HOST, pywaves.MATCHER_PORT))
try:
bids = req['bids']
asks = req['asks']
except:
bids = ''
asks = ''
return bids, asks
setNode()