peerplays.market module¶
-
class
peerplays.market.
Market
(*args, **kwargs)¶ Bases:
peerplays.instance.BlockchainInstance
,peerplays.market.Market
This class allows to easily access Markets on the blockchain for trading, etc.
Parameters: - blockchain_instance (peerplays.peerplays.PeerPlays) – Peerplays instance
- base (peerplays.asset.Asset) – Base asset
- quote (peerplays.asset.Asset) – Quote asset
Returns: Blockchain Market
Return type: dictionary with overloaded methods
Instances of this class are dictionaries that come with additional methods (see below) that allow dealing with a market and it’s corresponding functions.
This class tries to identify two assets as provided in the parameters in one of the following forms:
base
andquote
are valid assets (according topeerplays.asset.Asset
)base:quote
separated with:
base/quote
separated with/
base-quote
separated with-
Note
Throughout this library, the
quote
symbol will be presented first (e.g.BTC:PPY
withBTC
being the quote), while thebase
only refers to a secondary asset for a trade. This means, if you callpeerplays.market.Market.sell()
orpeerplays.market.Market.buy()
, you will sell/buy only quote and obtain/pay only base.-
accountopenorders
(account=None)¶ Returns open Orders.
Parameters: account (bitshares.account.Account) – Account name or instance of Account to show orders for in this market
-
accounttrades
(account=None, limit=25)¶ Returns your trade history for a given market, specified by the “currencyPair” parameter. You may also specify “all” to get the orderbooks of all markets.
Parameters: - currencyPair (str) – Return results for a particular market only (default: “all”)
- limit (int) – Limit the amount of orders (default: 25)
Output Parameters:
- type: sell or buy
- rate: price for quote denoted in base per quote
- amount: amount of quote
- total: amount of base at asked price (amount/price)
Note
This call goes through the trade history and searches for your account, if there are no orders within
limit
trades, this call will return an empty array.
-
blockchain
¶
-
blockchain_instance_class
¶
-
buy
(price, amount, expiration=None, killfill=False, account=None, returnOrderId=False, **kwargs)¶ Places a buy order in a given market.
Parameters: - price (float) – price denoted in
base
/quote
- amount (number) – Amount of
quote
to buy - expiration (number) – (optional) expiration time of the order in seconds (defaults to 7 days)
- killfill (bool) – flag that indicates if the order shall be killed if it is not filled (defaults to False)
- account (string) – Account name that executes that order
- returnOrderId (string) – If set to “head” or “irreversible” the call will wait for the tx to appear in the head/irreversible block and add the key “orderid” to the tx output
Prices/Rates are denoted in ‘base’, i.e. the BTC_PPY market is priced in PPY per BTC.
Example: in the BTC_PPY market, a price of 400 means a BTC is worth 400 PPY
Note
All prices returned are in the reversed orientation as the market. I.e. in the BTC/PPY market, prices are PPY per BTC. That way you can multiply prices with 1.05 to get a +5%.
Warning
Since buy orders are placed as limit-sell orders for the base asset, you may end up obtaining more of the buy asset than you placed the order for. Example:
- You place and order to buy 10 BTC for 100 PPY/BTC
- This means that you actually place a sell order for 1000 PPY in order to obtain at least 10 PPY
- If an order on the market exists that sells BTC for cheaper, you will end up with more than 10 BTC
- price (float) – price denoted in
-
cancel
(orderNumber, account=None, **kwargs)¶ Cancels an order you have placed in a given market. Requires only the “orderNumber”. An order number takes the form
1.7.xxx
.Parameters: orderNumber (str) – The Order Object ide of the form 1.7.xxxx
-
chain
¶ Short form for blockchain (for the lazy)
-
clear
() → None. Remove all items from D.¶
-
copy
() → a shallow copy of D¶
-
core_base_market
()¶ This returns an instance of the market that has the core market of the base asset.
It means that base needs to be a market pegged asset and returns a market to it’s collateral asset.
-
core_quote_market
()¶ This returns an instance of the market that has the core market of the quote asset.
It means that quote needs to be a market pegged asset and returns a market to it’s collateral asset.
-
define_classes
()¶ Needs to define instance variables that provide classes
-
fromkeys
()¶ Create a new dictionary with keys from iterable and values set to value.
-
get
()¶ Return the value for key if key is in the dictionary, else default.
-
get_instance_class
()¶ Should return the Chain instance class, e.g. peerplays.PeerPlays
-
get_limit_orders
(limit=25)¶ Returns the list of limit orders for a given market.
Parameters: limit (int) – Limit the amount of orders (default: 25) Sample output:
[0.003679 BTC/PPY (1.9103 BTC|519.29602 PPY), 0.003676 BTC/PPY (299.9997 BTC|81606.16394 PPY), 0.003665 BTC/PPY (288.4618 BTC|78706.21881 PPY), 0.003665 BTC/PPY (3.5285 BTC|962.74409 PPY), 0.003665 BTC/PPY (72.5474 BTC|19794.41299 PPY), [0.003738 BTC/PPY (36.4715 BTC|9756.17339 PPY), 0.003738 BTC/PPY (18.6915 BTC|5000.00000 PPY), 0.003742 BTC/PPY (182.6881 BTC|48820.22081 PPY), 0.003772 BTC/PPY (4.5200 BTC|1198.14798 PPY), 0.003799 BTC/PPY (148.4975 BTC|39086.59741 PPY)]
Note
Each bid is an instance of class:bitshares.price.Order and thus carries the keys
base
,quote
andprice
. From those you can obtain the actual amounts for sale
-
get_string
(separator=':')¶ Return a formated string that identifies the market, e.g.
BTC:PPY
Parameters: separator (str) – The separator of the assets (defaults to :
)
-
classmethod
inject
(cls)¶
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
orderbook
(limit=25)¶ Returns the order book for a given market. You may also specify “all” to get the orderbooks of all markets.
Parameters: limit (int) – Limit the amount of orders (default: 25) Sample output:
{'bids': [0.003679 BTC/PPY (1.9103 BTC|519.29602 PPY), 0.003676 BTC/PPY (299.9997 BTC|81606.16394 PPY), 0.003665 BTC/PPY (288.4618 BTC|78706.21881 PPY), 0.003665 BTC/PPY (3.5285 BTC|962.74409 PPY), 0.003665 BTC/PPY (72.5474 BTC|19794.41299 PPY)], 'asks': [0.003738 BTC/PPY (36.4715 BTC|9756.17339 PPY), 0.003738 BTC/PPY (18.6915 BTC|5000.00000 PPY), 0.003742 BTC/PPY (182.6881 BTC|48820.22081 PPY), 0.003772 BTC/PPY (4.5200 BTC|1198.14798 PPY), 0.003799 BTC/PPY (148.4975 BTC|39086.59741 PPY)]}
Note
Each bid is an instance of class:peerplays.price.Order and thus carries the keys
base
,quote
andprice
. From those you can obtain the actual amounts for saleNote
This method does order consolidation and hides some details of individual orders!
-
peerplays
¶ Alias for the specific blockchain
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised
-
popitem
() → (k, v), remove and return some (key, value) pair as a¶ 2-tuple; but raise KeyError if D is empty.
-
sell
(price, amount, expiration=None, killfill=False, account=None, returnOrderId=False, **kwargs)¶ Places a sell order in a given market.
Parameters: - price (float) – price denoted in
base
/quote
- amount (number) – Amount of
quote
to sell - expiration (number) – (optional) expiration time of the order in seconds (defaults to 7 days)
- killfill (bool) – flag that indicates if the order shall be killed if it is not filled (defaults to False)
- account (string) – Account name that executes that order
- returnOrderId (string) – If set to “head” or “irreversible” the call will wait for the tx to appear in the head/irreversible block and add the key “orderid” to the tx output
Prices/Rates are denoted in ‘base’, i.e. the BTC_PPY market is priced in PPY per BTC.
Example: in the BTC_PPY market, a price of 300 means a BTC is worth 300 PPY
Note
All prices returned are in the reversed orientation as the market. I.e. in the BTC/PPY market, prices are PPY per BTC. That way you can multiply prices with 1.05 to get a +5%.
- price (float) – price denoted in
This method allows us to override default instance for all users of
SharedInstance.instance
.Parameters: instance (chaininstance) – Chain instance
This allows to set a config that will be used when calling
shared_blockchain_instance
and allows to define the configuration without requiring to actually create an instance
This method allows to set the current instance as default
-
setdefault
()¶ Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
This method will initialize
SharedInstance.instance
and return it. The purpose of this method is to have offer single default instance that can be reused by multiple classes.
-
ticker
()¶ Returns the ticker for all markets.
Output Parameters:
last
: Price of the order last filledlowestAsk
: Price of the lowest askhighestBid
: Price of the highest bidbaseVolume
: Volume of the base assetquoteVolume
: Volume of the quote assetpercentChange
: 24h change percentage (in %)settlement_price
: Settlement Price for borrow/settlementcore_exchange_rate
: Core exchange rate for payment of fee in non-PPY assetprice24h
: the price 24h ago
Sample Output:
{ { "quoteVolume": 48328.73333, "quoteSettlement_price": 332.3344827586207, "lowestAsk": 340.0, "baseVolume": 144.1862, "percentChange": -1.9607843231354893, "highestBid": 334.20000000000005, "latest": 333.33333330133934, } }
-
trades
(limit=25, start=None, stop=None)¶ Returns your trade history for a given market.
Parameters: - limit (int) – Limit the amount of orders (default: 25)
- start (datetime) – start time
- stop (datetime) – stop time
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-
values
() → an object providing a view on D's values¶
-
volume24h
()¶ Returns the 24-hour volume for all markets, plus totals for primary currencies.
Sample output:
{ "PPY": 41.12345, "BTC": 1.0 }