Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
PyWaves authored May 2, 2017
1 parent 323c04f commit 3e93f5c
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 8 deletions.
58 changes: 53 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,43 @@ __pywaves.Order(orderId, assetPair, address='')__ Creates a new Order object
####methods:
`status()` returns current order status
`cancel()` cancel the order
`ticker()` get ticker with 24h ohlcv data
`last()` get traded price
`open()` get 24h open price
`high()` get 24h high price
`low()` get 24h low price
`close()` get 24h close price (same as last())
`vwap()` get 24h vwap price
`volume()` get 24h volume
`priceVolume()` get 24h price volume
`trades(n)` get the last n trades
`trades(from, to)` get the trades in from/to interval
`candles(timeframe, n)` get the last n candles in the specified timeframe
`candles(timeframe, from, to)` get the candles in from/to interval in the specified timeframe


##Other functions
`pywaves.setNode(node, chain)` sets node URL ('http://ip-address:port') and chain (either 'mainnet' or 'testnet')
`pywaves.setNode(node, chain)` set node URL ('http://ip-address:port') and chain (either 'mainnet' or 'testnet')

`pywaves.setMatcher(node)` set matcher URL ('http://ip-address:port')

`pywaves.height()` returns blockchain height
`pywaves.setDatafeed(node)` set datafeed URL ('http://ip-address:port')

`pywaves.lastblock()` returns last block
`pywaves.height()` get blockchain height

`pywaves.block(n)` returns block at specified height
`pywaves.lastblock()` get last block

`pywaves.tx(id)` returns transaction details
`pywaves.block(n)` get block at specified height

`pywaves.tx(id)` get transaction details

`pywaves.symbols()` get list of symbol-asset mapping

`pywaves.markets()` get all traded markets with tickers and matchers info

`pywaves.matchers()` get list of matchers with traded markets

`pywaves.{SYMBOL_NAME}` get predefined asset for the specified symbol (pywaves.WAVES, pywaves.BTC, pywaves.USD,...)


### Default Fees
Expand Down Expand Up @@ -252,6 +274,32 @@ myAddress.cancelOrder(assetPair, myOrder)

```

####Getting Market Data from Waves Data Feed (WDF):
```python
import pywaves as pw

# set the asset pair
WAVES_BTC = pw.AssetPair(pw.WAVES, pw.BTC)

# get last price and volume
print("%s %s" % (WAVES_BTC.last(), WAVES_BTC.volume())

# get ticker
ticker = WAVES_BTC.ticker()
print(ticker['24h_open'])
print(ticker['24h_vwap'])

# get last 10 trades
trades = WAVES_BTC.trades(10)
for t in trades:
print("%s %s %s %s" % (t['buyer'], t['seller'], t['price'], t['amount']))

# get last 10 daily OHLCV candles
ohlcv = WAVES_BTC.candles(1440, 10)
for t in ohlcv:
print("%s %s %s %s %s" % (t['open'], t['high'], t['low'], t['close'], t['volume']))
```

####LPOS
```python
import pywaves as pw
Expand Down
24 changes: 22 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

DEFAULT_TX_FEE = 100000
DEFAULT_ASSET_FEE = 100000000
DEFAULT_MATCHER_FEE = 1000000
DEFAULT_MATCHER_FEE = 100000
DEFAULT_LEASE_FEE = 100000
VALID_TIMEFRAMES = (5, 15, 30, 60, 240, 1440)
MAX_WDF_REQUEST = 100

import requests

Expand All @@ -30,6 +32,8 @@
MATCHER = 'http://dev.pywaves.org:6886'
MATCHER_PUBLICKEY = ''

DATAFEED = 'http://marketdata.wavesplatform.com'

if not os.path.exists(PYWAVES_DIR):
os.makedirs(PYWAVES_DIR)

Expand Down Expand Up @@ -63,6 +67,11 @@ def setMatcher(node = MATCHER):
except:
MATCHER_PUBLICKEY = ''

def setDatafeed(wdf = DATAFEED):
global DATAFEED
DATAFEED = wdf
logging.info('Setting datafeed %s ' % (DATAFEED))

def wrapper(api, postData='', host=''):
if not host:
host = NODE
Expand Down Expand Up @@ -94,4 +103,15 @@ def getOrderBook(assetPair):
asks = ''
return bids, asks

setNode()
def symbols():
return wrapper('/api/symbols', host=DATAFEED)

def markets():
return wrapper('/api/markets', host = DATAFEED)

def matchers():
return wrapper('/api/matchers', host = DATAFEED)

setNode()
for s in symbols():
setattr(pywaves,s['symbol'],Asset(s['assetID']))
2 changes: 2 additions & 0 deletions address.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,5 @@ def leaseCancel(self, leaseId, txFee=pywaves.DEFAULT_LEASE_FEE):
if 'leaseId' in req:
return req['leaseId']



67 changes: 66 additions & 1 deletion asset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pywaves
import logging

class Asset(object):
def __init__(self, assetId):
Expand Down Expand Up @@ -68,6 +69,70 @@ def second(self):
else:
return self.asset1

def ticker(self):
a1 = 'WAVES' if self.asset1.assetId == '' else self.asset1.assetId
a2 = 'WAVES' if self.asset2.assetId == '' else self.asset2.assetId
return pywaves.wrapper('/api/ticker/%s/%s' % (a1, a2), host=pywaves.DATAFEED)

def last(self):
return str(self.ticker()['24h_close'])

def open(self):
return str(self.ticker()['24h_open'])

def high(self):
return str(self.ticker()['24h_high'])

def low(self):
return str(self.ticker()['24h_low'])

def close(self):
return self.last()

def vwap(self):
return str(self.ticker()['24h_vwap'])

def volume(self):
return str(self.ticker()['24h_volume'])

def priceVolume(self):
return str(self.ticker()['24h_priceVolume'])

def _getMarketData(self, method, params):
a1 = 'WAVES' if self.asset1.assetId == '' else self.asset1.assetId
a2 = 'WAVES' if self.asset2.assetId == '' else self.asset2.assetId
return pywaves.wrapper('%s/%s/%s/%s' % (method, a1, a2, params), host=pywaves.DATAFEED)

def trades(self, *args):
if len(args)==1:
limit = args[0]
if limit > 0 and limit <= pywaves.MAX_WDF_REQUEST:
return self._getMarketData('/api/trades/%s/%s/%d' % (a1, a2, limit))
else:
return logging.error('Invalid request. Limit must be >0 and <= 100')
elif len(args)==2:
fromTimestamp = args[0]
toTimestamp = args[1]
return self._getMarketData('/api/trades', '%d/%d' % (fromTimestamp, toTimestamp))

def candles(self, *args):
if len(args)==2:
timeframe = args[0]
limit = args[1]
if timeframe not in pywaves.VALID_TIMEFRAMES:
return logging.error('Invalid timeframe')
elif limit > 0 and limit <= pywaves.MAX_WDF_REQUEST:
return self._getMarketData('/api/candles', '%d/%d' % (timeframe, limit))
else:
return logging.error('Invalid request. Limit must be >0 and <= 100')
elif len(args)==3:
timeframe = args[0]
fromTimestamp = args[1]
toTimestamp = args[2]
if timeframe not in pywaves.VALID_TIMEFRAMES:
return logging.error('Invalid timeframe')
else:
return self._getMarketData('/api/candles', '%d/%d/%d' % (timeframe, fromTimestamp, toTimestamp))

__repr__ = __str__

WAVES = Asset('')

0 comments on commit 3e93f5c

Please sign in to comment.