def market_history( self, bucket_seconds=60 * 5, start_age=1 * 60 * 60, 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}, """ return self.steemd.get_market_history( bucket_seconds, transactions.fmt_time_from_now(-start_age - end_age), transactions.fmt_time_from_now(-end_age), )
def trade_history(self, time=1 * 60 * 60, limit=100): """ Returns the trade history for the internal market :param int time: Show the last x seconds of trades (default 1h) :param int limit: amount of trades to show (<100) (default: 100) """ assert limit <= 100, "'limit' has to be smaller than 100" return self.steemd.get_trade_history( transactions.fmt_time_from_now(-time), transactions.fmt_time_from_now(), limit, )
def trade_history(self, time=1 * 60 * 60, limit=100): """ Returns the trade history for the internal market :param int time: Show the last x seconds of trades (default 1h) :param int limit: amount of trades to show (<100) (default: 100) """ assert limit <= 100, "'limit' has to be smaller than 100" return self.steemd.get_trade_history( transactions.fmt_time_from_now(-time), transactions.fmt_time_from_now(), limit, )
def buy(self, amount, quote_symbol, rate, expiration=7 * 24 * 60 * 60, killfill=False, account=None, order_id=None): """ Places a buy order in a given market (buy ``quote``, sell ``base`` in market ``quote_base``). If successful, the method will return the order creating (signed) transaction. :param number amount: Amount of ``quote`` to buy :param str quote_symbol: STEEM, or SBD :param float price: price denoted in ``base``/``quote`` :param number expiration: (optional) expiration time of the order in seconds (defaults to 7 days) :param bool killfill: flag that indicates if the order shall be killed if it is not filled (defaults to False) :param str account: (optional) the source account for the transfer if not ``default_account`` :param int order_id: (optional) a 32bit orderid for tracking of the created order (random by default) Prices/Rates are denoted in 'base', i.e. the STEEM:SBD market is priced in SBD per STEEM. """ if not account: if "default_account" in config: account = config["default_account"] if not account: raise ValueError("You need to provide an account") # We buy quote and pay with base quote, base = self._get_assets(quote=quote_symbol) op = operations.LimitOrderCreate( **{ "owner": account, "orderid": order_id or random.getrandbits(32), "amount_to_sell": '{:.{prec}f} {asset}'.format(amount * rate, prec=base["precision"], asset=base["symbol"]), "min_to_receive": '{:.{prec}f} {asset}'.format( amount, prec=quote["precision"], asset=quote["symbol"]), "fill_or_kill": killfill, "expiration": transactions.fmt_time_from_now(expiration) }) return self.steemd.commit.finalizeOp(op, account, "active")
def sell(self, amount, quote_symbol, rate, expiration=7 * 24 * 60 * 60, killfill=False, account=None, orderid=None): """ Places a sell order in a given market (sell ``quote``, buy ``base`` in market ``quote_base``). If successful, the method will return the order creating (signed) transaction. :param number amount: Amount of ``quote`` to sell :param str quote_symbol: STEEM, or SBD :param float price: price denoted in ``base``/``quote`` :param number expiration: (optional) expiration time of the order in seconds (defaults to 7 days) :param bool killfill: flag that indicates if the order shall be killed if it is not filled (defaults to False) :param str account: (optional) the source account for the transfer if not ``default_account`` :param int orderid: (optional) a 32bit orderid for tracking of the created order (random by default) Prices/Rates are denoted in 'base', i.e. the STEEM:SBD market is priced in SBD per STEEM. """ if not account: if "default_account" in config: account = config["default_account"] if not account: raise ValueError("You need to provide an account") # We buy quote and pay with base quote, base = self._get_assets(quote=quote_symbol) op = operations.LimitOrderCreate( **{ "owner": account, "orderid": orderid or random.getrandbits(32), "amount_to_sell": '{:.{prec}f} {asset}'.format( amount, prec=quote["precision"], asset=quote["symbol"]), "min_to_receive": '{:.{prec}f} {asset}'.format( amount * rate, prec=base["precision"], asset=base["symbol"]), "fill_or_kill": killfill, "expiration": transactions.fmt_time_from_now(expiration) }) return self.steemd.commit.finalizeOp(op, account, "active")
def constructTx(self): if isinstance(self.op, list): ops = [Operation(o) for o in self.op] else: ops = [Operation(self.op)] expiration = fmt_time_from_now(self.expiration) ref_block_num, ref_block_prefix = get_block_params(self.steemd) tx = SignedTransaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) super(TransactionBuilder, self).__init__(tx.json())
def market_history( self, bucket_seconds=60 * 5, start_age=1 * 60 * 60, 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}, """ return self.steemd.get_market_history( bucket_seconds, transactions.fmt_time_from_now(-start_age - end_age), transactions.fmt_time_from_now(-end_age), )
def constructTx(self): if isinstance(self.op, list): ops = [Operation(o) for o in self.op] else: ops = [Operation(self.op)] expiration = fmt_time_from_now(self.expiration) ref_block_num, ref_block_prefix = get_block_params(self.steemd) tx = SignedTransaction( ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) super(TransactionBuilder, self).__init__(tx.json())