def wasp(): """Go down the list of Steem Engine tokens and transfer full balance to destination""" send_to = input("Enter destination: ") active_wif = getpass(prompt="Active key: ") steem = Steem(keys=[active_wif], nodes="https://api.steemit.com") w = Wallet(steem_instance=steem) t = Tokens() usr = w.getAccountFromPrivateKey(active_wif) sew = seWallet(account=usr, steem_instance=steem) tokens = sew.get_balances() for token in tokens: symbol = token["symbol"] info = t.get_token(symbol) p = info["precision"] b = float(token["balance"]) balance = float(f"{b:.{p}f}") if balance > 0: print(f"[ Transfering {balance} of {symbol} to {send_to} ]") # pprint(sew.transfer(send_to, balance, symbol, memo="waspsting.py transfer") sew.transfer(send_to, balance, symbol, memo="waspsting.py transfer") time.sleep(1) return None
def check_config(config, necessary_fields, stm): config_cnt = 0 token_config = {} token_list = Tokens() for conf in config: config_cnt += 1 # check if all fields are set all_fields_ok = True for field in necessary_fields: if field not in conf: logger.warn("Error in %d. config: %s missing" % (config_cnt, field)) all_fields_ok = False if not all_fields_ok: continue # Check if scot_account exists (exception will be raised when not) Account(conf["scot_account"], steem_instance=stm) # Check if scot_token exists if token_list.get_token(conf["scot_token"]) is None: logger.warn("Token %s does not exists" % conf["scot_token"]) continue scot_wallet = Wallet(conf["scot_account"], steem_instance=stm) scot_token = scot_wallet.get_token(conf["scot_token"]) logger.info("%s has %s token" % (conf["scot_account"], str(scot_token))) token_config[conf["scot_token"]] = conf if len(token_config) == 0: raise Exception("Broken config, shutdown bot...") logger.info("%d configs were found." % len(token_config)) return token_config
def __init__(self, api=None, steem_instance=None): if api is None: self.api = Api() else: self.api = api self.steem = steem_instance or shared_steem_instance() self.tokens = Tokens(api=self.api) self.ssc_id = "ssc-mainnet1" self.refresh()
def wasp(): """ Go down the list of Steem Engine tokens and transfer full balance to destination""" send_to = input('Enter destination: ') active_wif = input('Enter your Active Key: ') steem = Steem(keys=[active_wif], nodes='https://api.steemit.com') w = Wallet(steem_instance=steem) t = Tokens() usr = w.getAccountFromPrivateKey(active_wif) sew = seWallet(account=usr, steem_instance=steem) tokens = sew.get_balances() for token in tokens: symbol = token['symbol'] info = t.get_token(symbol) p = info['precision'] b = float(token['balance']) balance = float(f'{b:.{p}f}') if balance > 0: print(f'[ Transfering {balance} of {symbol} to {send_to} ]') #pprint(sew.transfer(send_to, balance, symbol, memo="waspsting.py transfer") sew.transfer(send_to, balance, symbol, memo="waspsting.py transfer") time.sleep(1) return None
import time import random import schedule import json from dhooks import Webhook import math from beem.nodelist import NodeList import json import six import requests import getpass beem_pass = "" # Password to unlock beem wallet api = Api() tokens = Tokens() token = Token("TMPS") stm = Steem() market = Market(steem_instance=stm) wallet = Wallet("tmps", steem_instance=stm) wallet2 = Wallet("market", steem_instance=stm) stm.wallet.unlock(pwd=beem_pass) blacklist = ["market", "tokens", "null", "tmps"] dragon_token = wallet.get_token("TMPS") wallet.refresh() upvote_account = "ufm.pay" adjusted_dragon = float(dragon_token["balance"]) * 0.95 balances = token.get_holder() info = token.get_info() max_post_age_days = 6 min_post_age = 5
def test_tokens(self): tokens = Tokens() self.assertTrue(tokens is not None) self.assertTrue(len(tokens) > 0)
class Market(list): """ Access the steem-engine market :param Steem steem_instance: Steem instance """ def __init__(self, api=None, steem_instance=None): if api is None: self.api = Api() else: self.api = api self.steem = steem_instance or shared_steem_instance() self.tokens = Tokens(api=self.api) self.ssc_id = "ssc-mainnet1" self.refresh() def refresh(self): super(Market, self).__init__(self.get_metrics()) def set_id(self, ssc_id): """Sets the ssc id (default is ssc-mainnet1)""" self.ssc_id = ssc_id def get_metrics(self): """Returns all token within the wallet as list""" metrics = self.api.find("market", "metrics", query={}) return metrics def get_buy_book(self, symbol, account=None, limit=100, offset=0): """Returns the buy book for a given symbol. When account is set, the order book from the given account is shown. """ if self.tokens.get_token(symbol) is None: raise TokenDoesNotExists("%s does not exists" % symbol) if account is None: buy_book = self.api.find("market", "buyBook", query={"symbol": symbol.upper()}, limit=limit, offset=offset) else: buy_book = self.api.find("market", "buyBook", query={"symbol": symbol.upper(), "account": account}, limit=limit, offset=offset) return buy_book def get_sell_book(self, symbol, account=None, limit=100, offset=0): """Returns the sell book for a given symbol. When account is set, the order book from the given account is shown. """ if self.tokens.get_token(symbol) is None: raise TokenDoesNotExists("%s does not exists" % symbol) if account is None: sell_book = self.api.find("market", "sellBook", query={"symbol": symbol.upper()}, limit=limit, offset=offset) else: sell_book = self.api.find("market", "sellBook", query={"symbol": symbol.upper(), "account": account}, limit=limit, offset=offset) return sell_book def get_trades_history(self, symbol, account=None, limit=30, offset=0): """Returns the trade history for a given symbol. When account is set, the trade history from the given account is shown. """ if self.tokens.get_token(symbol) is None: raise TokenDoesNotExists("%s does not exists" % symbol) if account is None: trades_history = self.api.find("market", "tradesHistory", query={"symbol": symbol.upper()}, limit=limit, offset=offset) else: trades_history = self.api.find("market", "tradesHistory", query={"symbol": symbol.upper(), "account": account}, limit=limit, offset=offset) return trades_history def withdraw(self, account, amount): """Widthdraw STEEMP to account as STEEM. :param str account: account name :param float amount: Amount to withdraw Withdraw example: .. code-block:: python from steemengine.market import Market from beem import Steem active_wif = "5xxxx" stm = Steem(keys=[active_wif]) market = Market(steem_instance=stm) market.withdraw("test", 1) """ wallet = Wallet(account, api=self.api, steem_instance=self.steem) token_in_wallet = wallet.get_token("STEEMP") if token_in_wallet is None: raise TokenNotInWallet("%s is not in wallet." % "STEEMP") if float(token_in_wallet["balance"]) < float(amount): raise InsufficientTokenAmount("Only %.3f in wallet" % float(token_in_wallet["balance"])) token = Token("STEEMP", api=self.api) quant_amount = token.quantize(amount) if quant_amount <= decimal.Decimal("0"): raise InvalidTokenAmount("Amount to transfer is below token precision of %d" % token["precision"]) contract_payload = {"quantity":str(quant_amount)} json_data = {"contractName":"steempegged","contractAction":"withdraw", "contractPayload":contract_payload} tx = self.steem.custom_json(self.ssc_id, json_data, required_auths=[account]) return tx def deposit(self, account, amount): """Deposit STEEM to market in exchange for STEEMP. :param str account: account name :param float amount: Amount to deposit Deposit example: .. code-block:: python from steemengine.market import Market from beem import Steem active_wif = "5xxxx" stm = Steem(keys=[active_wif]) market = Market(steem_instance=stm) market.deposit("test", 1) """ acc = Account(account, steem_instance=self.steem) steem_balance = acc.get_balance("available", "STEEM") if float(steem_balance) < float(amount): raise InsufficientTokenAmount("Only %.3f in wallet" % float(steem_balance)) json_data = '{"id":"' + self.ssc_id + '","json":{"contractName":"steempegged","contractAction":"buy","contractPayload":{}}}' tx = acc.transfer("steem-peg", amount, "STEEM", memo=json_data) return tx def buy(self, account, amount, symbol, price): """Buy token for given price. :param str account: account name :param float amount: Amount to withdraw :param str symbol: symbol :param float price: price Buy example: .. code-block:: python from steemengine.market import Market from beem import Steem active_wif = "5xxxx" stm = Steem(keys=[active_wif]) market = Market(steem_instance=stm) market.buy("test", 1, "ENG", 0.95) """ wallet = Wallet(account, api=self.api, steem_instance=self.steem) token_in_wallet = wallet.get_token("STEEMP") if token_in_wallet is None: raise TokenNotInWallet("%s is not in wallet." % "STEEMP") if float(token_in_wallet["balance"]) < float(amount) * float(price): raise InsufficientTokenAmount("Only %.3f in wallet" % float(token_in_wallet["balance"])) token = Token(symbol, api=self.api) quant_amount = token.quantize(amount) if quant_amount <= decimal.Decimal("0"): raise InvalidTokenAmount("Amount to transfer is below token precision of %d" % token["precision"]) contract_payload = {"symbol": symbol.upper(), "quantity":str(quant_amount), "price": str(price)} json_data = {"contractName":"market","contractAction":"buy", "contractPayload":contract_payload} tx = self.steem.custom_json(self.ssc_id, json_data, required_auths=[account]) return tx def sell(self, account, amount, symbol, price): """Sell token for given price. :param str account: account name :param float amount: Amount to withdraw :param str symbol: symbol :param float price: price Sell example: .. code-block:: python from steemengine.market import Market from beem import Steem active_wif = "5xxxx" stm = Steem(keys=[active_wif]) market = Market(steem_instance=stm) market.sell("test", 1, "ENG", 0.95) """ wallet = Wallet(account, api=self.api, steem_instance=self.steem) token_in_wallet = wallet.get_token(symbol) if token_in_wallet is None: raise TokenNotInWallet("%s is not in wallet." % symbol) if float(token_in_wallet["balance"]) < float(amount): raise InsufficientTokenAmount("Only %.3f in wallet" % float(token_in_wallet["balance"])) token = Token(symbol, api=self.api) quant_amount = token.quantize(amount) if quant_amount <= decimal.Decimal("0"): raise InvalidTokenAmount("Amount to transfer is below token precision of %d" % token["precision"]) contract_payload = {"symbol": symbol.upper(), "quantity":str(quant_amount), "price": str(price)} json_data = {"contractName":"market","contractAction":"sell", "contractPayload":contract_payload} tx = self.steem.custom_json(self.ssc_id, json_data, required_auths=[account]) return tx def cancel(self, account, order_type, order_id): """Cancel buy/sell order. :param str account: account name :param str order_type: sell or buy :param int order_id: order id Cancel example: .. code-block:: python from steemengine.market import Market from beem import Steem active_wif = "5xxxx" stm = Steem(keys=[active_wif]) market = Market(steem_instance=stm) market.sell("test", "sell", 12) """ contract_payload = {"type": order_type, "id": order_id} json_data = {"contractName":"market","contractAction":"cancel", "contractPayload":contract_payload} tx = self.steem.custom_json(self.ssc_id, json_data, required_auths=[account]) return tx
def info(objects): """ Show basic blockchain info General information about steem-engine, a block, an account, a token, and a transaction id """ stm = None api = Api() if not objects: latest_block = api.get_latest_block_info() tokens = Tokens() t = PrettyTable(["Key", "Value"]) t.align = "l" t.add_row(["latest block number", latest_block["blockNumber"]]) t.add_row(["latest steem block", latest_block["refSteemBlockNumber"]]) t.add_row(["latest timestamp", latest_block["timestamp"]]) t.add_row(["Number of created tokens", len(tokens)]) print(t.get_string()) for obj in objects: if re.match("^[0-9-]*$", obj): block_info = api.get_block_info(int(obj)) print("Block info: %d" % (int(obj))) trx_nr = 0 for trx in block_info["transactions"]: trx_nr += 1 t = PrettyTable(["Key", "Value"]) t.align = "l" t.add_row(["trx_nr", str(trx_nr)]) t.add_row(["action", trx["action"]]) t.add_row(["contract", trx["contract"]]) t.add_row( ["logs", json.dumps(json.loads(trx["logs"]), indent=4)]) t.add_row([ "payload", json.dumps(json.loads(trx["payload"]), indent=4) ]) t.add_row(["refSteemBlockNumber", trx["refSteemBlockNumber"]]) t.add_row(["timestamp", block_info["timestamp"]]) t.add_row(["sender", trx["sender"]]) t.add_row(["transactionId", trx["transactionId"]]) print(t.get_string()) elif re.match("^[A-Z0-9\-\._]{1,16}$", obj): print("Token: %s" % obj) tokens = Tokens() token = tokens.get_token(obj) if token is None: print("Could not found token %s" % obj) return t = PrettyTable(["Key", "Value"]) t.align = "l" metadata = json.loads(token["metadata"]) for key in token: if key == "metadata": if "url" in metadata: t.add_row(["metadata_url", metadata["url"]]) if "icon" in metadata: t.add_row(["metadata_icon", metadata["icon"]]) if "desc" in metadata: t.add_row(["metadata_desc", metadata["desc"]]) else: t.add_row([key, token[key]]) market_info = token.get_market_info() if market_info is not None: for key in market_info: if key in ["$loki", "symbol"]: continue t.add_row([key, market_info[key]]) print(t.get_string()) elif re.match("^[a-zA-Z0-9\-\._]{2,16}$", obj): print("Token Wallet: %s" % obj) if stm is None: nodelist = NodeList() nodelist.update_nodes() stm = Steem(node=nodelist.get_nodes()) wallet = Wallet(obj, steem_instance=stm) t = PrettyTable( ["id", "symbol", "balance", "stake", "pendingUnstake"]) t.align = "l" for token in wallet: if "stake" in token: stake = token["stake"] else: stake = "-" if "pendingUnstake" in token: pendingUnstake = token["pendingUnstake"] else: pendingUnstake = "-" t.add_row([ token["$loki"], token["symbol"], token["balance"], stake, pendingUnstake ]) print(t.get_string(sortby="id")) elif len(obj) == 40: print("Transaction Id: %s" % obj) trx = api.get_transaction_info(obj) if trx is None: print("trx_id: %s is not a valid steem-engine trx_id!" % obj) return payload = json.loads(trx["payload"]) logs = json.loads(trx["logs"]) t = PrettyTable(["Key", "Value"]) t.align = "l" t.add_row(["blockNumber", str(trx["blockNumber"])]) t.add_row(["action", trx["action"]]) t.add_row(["contract", trx["contract"]]) t.add_row(["logs", json.dumps(logs, indent=4)]) t.add_row(["payload", json.dumps(payload, indent=4)]) t.add_row(["refSteemBlockNumber", trx["refSteemBlockNumber"]]) t.add_row(["sender", trx["sender"]]) t.add_row(["transactionId", trx["transactionId"]]) print(t.get_string())