beem.market module

class beem.market.Market(base=None, quote=None, steem_instance=None)

Bases: dict

This class allows to easily access Markets on the blockchain for trading, etc.

Parameters:
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 and quote are valid assets (according to beem.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. STEEM:SBD with STEEM being the quote), while the base only refers to a secondary asset for a trade. This means, if you call beem.market.Market.sell() or beem.market.Market.buy(), you will sell/buy only quote and obtain/pay only base.

accountopenorders(account=None, raw_data=False)

Returns open Orders

Parameters:account (steem.account.Account) – Account name or instance of Account to show orders for in this market
buy(price, amount, expiration=None, killfill=False, account=None, orderid=None, returnOrderId=False)

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 USD_BTS market is priced in BTS per USD.

Example: in the USD_BTS market, a price of 300 means a USD is worth 300 BTS

Note

All prices returned are in the reversed orientation as the market. I.e. in the BTC/BTS market, prices are BTS 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 USD for 100 BTS/USD
  • This means that you actually place a sell order for 1000 BTS in order to obtain at least 10 USD
  • If an order on the market exists that sells USD for cheaper, you will end up with more than 10 USD
cancel(orderNumbers, account=None, **kwargs)

Cancels an order you have placed in a given market. Requires only the “orderNumbers”. An order number takes the form 1.7.xxx. :param str orderNumbers: The Order Object ide of the form 1.7.xxxx

get_string(separator=':')

Return a formated string that identifies the market, e.g. STEEM:SBD

Parameters:separator (str) – The separator of the assets (defaults to :)
market_history(bucket_seconds=300, start_age=3600, end_age=0)

Return the market history (filled orders). :param int bucket_seconds: Bucket size in seconds (see returnMarketHistoryBuckets()) :param int start_age: Age (in seconds) of the start of the window (default: 1h/3600) :param int end_age: Age (in seconds) of the end of the window (default: now/0) Example: .. code-block:: js

{‘close_sbd’: 2493387,
‘close_steem’: 7743431, ‘high_sbd’: 1943872, ‘high_steem’: 5999610, ‘id’: ‘7.1.5252’, ‘low_sbd’: 534928, ‘low_steem’: 1661266, ‘open’: ‘2016-07-08T11:25:00’, ‘open_sbd’: 534928, ‘open_steem’: 1661266, ‘sbd_volume’: 9714435, ‘seconds’: 300, ‘steem_volume’: 30088443},
market_history_buckets()
orderbook(limit=25, raw_data=False)

Returns the order book for SBD/STEEM market. :param int limit: Limit the amount of orders (default: 25) Sample output: .. code-block:: js

{‘bids’: [0.003679 USD/BTS (1.9103 USD|519.29602 BTS), 0.003676 USD/BTS (299.9997 USD|81606.16394 BTS), 0.003665 USD/BTS (288.4618 USD|78706.21881 BTS), 0.003665 USD/BTS (3.5285 USD|962.74409 BTS), 0.003665 USD/BTS (72.5474 USD|19794.41299 BTS)], ‘asks’: [0.003738 USD/BTS (36.4715 USD|9756.17339 BTS), 0.003738 USD/BTS (18.6915 USD|5000.00000 BTS), 0.003742 USD/BTS (182.6881 USD|48820.22081 BTS), 0.003772 USD/BTS (4.5200 USD|1198.14798 BTS), 0.003799 USD/BTS (148.4975 USD|39086.59741 BTS)]}

Note

Each bid is an instance of class:beem.price.Order and thus carries the keys base, quote and price. From those you can obtain the actual amounts for sale

recent_trades(limit=25, raw_data=False)

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 USD/BTS (1.9103 USD|519.29602 BTS),
0.003676 USD/BTS (299.9997 USD|81606.16394 BTS),
0.003665 USD/BTS (288.4618 USD|78706.21881 BTS),
0.003665 USD/BTS (3.5285 USD|962.74409 BTS),
0.003665 USD/BTS (72.5474 USD|19794.41299 BTS)],
'asks': [0.003738 USD/BTS (36.4715 USD|9756.17339 BTS),
0.003738 USD/BTS (18.6915 USD|5000.00000 BTS),
0.003742 USD/BTS (182.6881 USD|48820.22081 BTS),
0.003772 USD/BTS (4.5200 USD|1198.14798 BTS),
0.003799 USD/BTS (148.4975 USD|39086.59741 BTS)]}

Note

Each bid is an instance of class:steem.price.Order and thus carries the keys base, quote and price. From those you can obtain the actual amounts for sale

sell(price, amount, expiration=None, killfill=False, account=None, orderid=None, returnOrderId=False)

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 USD_BTS market is priced in BTS per USD.

Example: in the USD_BTS market, a price of 300 means a USD is worth 300 BTS

Note

All prices returned are in the reversed orientation as the market. I.e. in the BTC/BTS market, prices are BTS per BTC. That way you can multiply prices with 1.05 to get a +5%.

ticker(raw_data=False)

Returns the ticker for all markets.

Output Parameters:

  • latest: Price of the order last filled
  • lowest_ask: Price of the lowest ask
  • highest_bid: Price of the highest bid
  • sbd_volume: Volume of SBD
  • steem_volume: Volume of STEEM
  • percent_change: 24h change percentage (in %)

Note

Market is STEEM:SBD and prices are SBD per STEEM!

Sample Output:

{'highest_bid': 0.30100226633322913,
 'latest': 0.0,
 'lowest_ask': 0.3249636958897082,
 'percent_change': 0.0,
 'sbd_volume': 108329611.0,
 'steem_volume': 355094043.0}
trade_history(start=None, stop=None, intervall=None, limit=25, raw_data=False)

Returns the trade history for the internal market

This function allows to fetch a fixed number of trades at fixed intervall times to reduce the call duration time. E.g. it is possible to receive the trades from the last 7 days, by fetching 100 trades each 6 hours.

When intervall is set to None, all trades are recieved between start and stop. This can take a while.

Parameters:
  • start (datetime) – Start date
  • stop (datetime) – Stop date
  • intervall (timedelta) – Defines the intervall
  • limit (int) – Defines how many trades are fetched at each intervall point
  • raw_data (bool) – when True, the raw data are returned
trades(limit=100, start=None, stop=None, raw_data=False)

Returns your trade history for a given market.

Parameters:
  • limit (int) – Limit the amount of orders (default: 100)
  • start (datetime) – start time
  • stop (datetime) – stop time
volume24h(raw_data=False)

Returns the 24-hour volume for all markets, plus totals for primary currencies.

Sample output:

{
    "STEEM": 361666.63617,
    "SBD": 1087.0
}