示例#1
0
    def __init__(self, bitshares_instance, config):
        self.bitshares_instance = bitshares_instance
        set_shared_bitshares_instance(bitshares_instance)
        self.config = config
        self.worker_manager = None

        # Configure logging
        data_dir = user_data_dir(APP_NAME, AUTHOR)
        filename = os.path.join(data_dir, 'dexbot.log')
        formatter = logging.Formatter(
            '%(asctime)s - %(worker_name)s using account %(account)s on %(market)s - %(levelname)s - %(message)s'
        )
        logger = logging.getLogger("dexbot.per_worker")
        fh = logging.FileHandler(filename)
        fh.setFormatter(formatter)
        logger.addHandler(fh)
        logger.setLevel(logging.INFO)
        self.pyqt_handler = PyQtHandler()
        self.pyqt_handler.setLevel(logging.INFO)
        logger.addHandler(self.pyqt_handler)
        logger.info("DEXBot {} on python {} {}".format(VERSION,
                                                       sys.version[:6],
                                                       sys.platform),
                    extra={
                        'worker_name': 'NONE',
                        'account': 'NONE',
                        'market': 'NONE'
                    })

        # Configure orders logging
        initialize_orders_log()
示例#2
0
 def test_default_connection(self):
     b1 = BitShares("wss://eu.nodes.bitshares.ws", nobroadcast=True)
     set_shared_bitshares_instance(b1)
     test = Asset("1.3.0", blockchain_instance=b1)
     # Needed to clear cache
     test.refresh()
     """
示例#3
0
    def set_bitshares_instance(self, bitshares_instance):
        """ Set bitshares instance

            :param bitshares_instance: A bitshares instance
        """
        self.bitshares_instance = bitshares_instance
        set_shared_bitshares_instance(bitshares_instance)
示例#4
0
文件: ui.py 项目: timelf123/DEXBot
 def new_func(ctx, *args, **kwargs):
     ctx.bitshares = BitShares(
         ctx.config["node"],
         **ctx.obj
     )
     set_shared_bitshares_instance(ctx.bitshares)
     return ctx.invoke(f, *args, **kwargs)
示例#5
0
    def __init__(self, bitshares_instance):
        self.bitshares_instance = bitshares_instance
        set_shared_bitshares_instance(bitshares_instance)
        self.worker_manager = None

        # Configure logging
        formatter = logging.Formatter(
            '%(asctime)s - %(worker_name)s using account %(account)s on %(market)s - %(levelname)s - %(message)s'
        )
        logger = logging.getLogger("dexbot.per_worker")
        fh = logging.FileHandler('dexbot.log')
        fh.setFormatter(formatter)
        logger.addHandler(fh)
        logger.setLevel(logging.INFO)
        self.pyqt_handler = PyQtHandler()
        self.pyqt_handler.setLevel(logging.INFO)
        logger.addHandler(self.pyqt_handler)
        logger.info("DEXBot {} on python {} {}".format(VERSION,
                                                       sys.version[:6],
                                                       sys.platform),
                    extra={
                        'worker_name': 'NONE',
                        'account': 'NONE',
                        'market': 'NONE'
                    })
 def new_func(ctx, *args, **kwargs):
     newoptions = ctx.obj
     newoptions.update(kwargsChain)
     ctx.bitshares = BitShares(**newoptions)
     ctx.blockchain = ctx.bitshares
     set_shared_bitshares_instance(ctx.bitshares)
     return ctx.invoke(f, *args, **kwargs)
示例#7
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            nobroadcast=True,
        )
        set_shared_bitshares_instance(self.bts)
示例#8
0
    def enable(self):
        if not self.enabled:
            from bitshares.instance import set_shared_bitshares_instance

            broken = BrokenBitsharesInstance()
            set_shared_bitshares_instance(broken)
            self.enabled = True
示例#9
0
 def __init__(self, *args, **kwargs):
     super(Testcases, self).__init__(*args, **kwargs)
     bitshares = BitShares(
         "wss://node.bitshares.eu",
         nobroadcast=True,
     )
     set_shared_bitshares_instance(bitshares)
示例#10
0
文件: ui.py 项目: xeroc/stakemachine
 def new_func(ctx, *args, **kwargs):
     ctx.bitshares = BitShares(
         ctx.config["node"],
         **ctx.obj
     )
     set_shared_bitshares_instance(ctx.bitshares)
     return ctx.invoke(f, *args, **kwargs)
示例#11
0
文件: ui.py 项目: emmanuelapp/dexbot
 def new_func(ctx, *args, **kwargs):
     ctx.bitshares = BitShares(ctx.config["node"],
                               num_retries=-1,
                               expiration=60,
                               **ctx.obj)
     set_shared_bitshares_instance(ctx.bitshares)
     return ctx.invoke(f, *args, **kwargs)
示例#12
0
def setup_bitshares_market(bts_symbol):
    bitshares_instance = BitShares(
        "wss://losangeles.us.api.bitshares.org/ws",
        nobroadcast=True  # <<--- set this to False when you want to fire!
    )
    set_shared_bitshares_instance(bitshares_instance)
    bts_market = Market(bts_symbol, bitshares_instance=bitshares_instance)
    return bts_market
示例#13
0
 def new_func(ctx, *args, **kwargs):
     ctx.bitshares = BitShares(
         ctx.config["node"],
         bundle=True,   # We bundle many feeds into a single tx
         **ctx.obj
     )
     set_shared_bitshares_instance(ctx.bitshares)
     return ctx.invoke(f, *args, **kwargs)
示例#14
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares("wss://node.testnet.bitshares.eu",
                             nobroadcast=True,
                             keys={"active": wif})
        set_shared_bitshares_instance(self.bts)
        self.bts.set_default_account("init0")
示例#15
0
文件: ui.py 项目: tryiou/DEXBot
 def new_func(ctx, *args, **kwargs):
     nodelist = sort_nodes(ctx)
     ctx.bitshares = BitShares(nodelist,
                               num_retries=-1,
                               expiration=60,
                               **ctx.obj)
     set_shared_bitshares_instance(ctx.bitshares)
     return ctx.invoke(f, *args, **kwargs)
示例#16
0
    def new_bitshares_instance(self, node, retries=-1, expiration=60):
        """ Create bitshares instance

            :param retries: Number of retries to connect, -1 default to infinity
            :param expiration: Delay in seconds until transactions are supposed to expire
            :param list node: Node or a list of nodes
        """
        self.bitshares_instance = BitShares(node, num_retries=retries, expiration=expiration)
        set_shared_bitshares_instance(self.bitshares_instance)
示例#17
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(url, nobroadcast=True)
        set_shared_bitshares_instance(self.bts)
        self.asset = Asset("1.3.0")
        self.symbol = self.asset["symbol"]
        self.precision = self.asset["precision"]
        self.asset2 = Asset("1.3.1")
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            "wss://node.testnet.bitshares.eu",
            nobroadcast=True,
        )
        self.bts.set_default_account("init0")
        set_shared_bitshares_instance(self.bts)
        self.chain = Blockchain(mode="head")
示例#19
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            nobroadcast=True,
            # We want to bundle many operations into a single transaction
            bundle=True,
            # Overwrite wallet to use this list of wifs only
            wif=[wif])
        self.bts.set_default_account("init0")
        set_shared_bitshares_instance(self.bts)
示例#20
0
def bitshares_instance(bitshares_testnet, private_keys):
    """Initialize BitShares instance connected to a local testnet."""
    bitshares = BitShares(
        node="ws://127.0.0.1:{}".format(bitshares_testnet.service_port),
        keys=private_keys,
        num_retries=-1,
    )
    # Shared instance allows to avoid any bugs when bitshares_instance is not passed
    # explicitly when instantiating objects. Todo: remove this
    set_shared_bitshares_instance(bitshares)

    return bitshares
示例#21
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            "wss://node.testnet.bitshares.eu",
            nobroadcast=True,
            keys={"active": wif},
        )
        # from getpass import getpass
        # self.bts.wallet.unlock(getpass())
        set_shared_bitshares_instance(self.bts)
        self.bts.set_default_account("init0")
示例#22
0
def _ensure_blockchain_connection():
    """
    Checks if the SharedInstance.instance is the configured instance and if not
    initializes and sets it
    """
    if not Configured_Instance.configured_instance:
        Configured_Instance.configured_instance = _get_configured_instance()

    if SharedInstance.instance != Configured_Instance.configured_instance:
        set_shared_bitshares_instance(Configured_Instance.configured_instance)

    return Configured_Instance.configured_instance
示例#23
0
    def __init__(self, bitshares_instance):
        self.bitshares_instance = bitshares_instance
        set_shared_bitshares_instance(bitshares_instance)
        self.worker_manager = None

        # Configure logging
        formatter = logging.Formatter(
            '%(asctime)s - %(worker_name)s using account %(account)s on %(market)s - %(levelname)s - %(message)s')
        logger = logging.getLogger("dexbot.per_worker")
        fh = logging.FileHandler('dexbot.log')
        fh.setFormatter(formatter)
        logger.addHandler(fh)
        logger.setLevel(logging.INFO)
示例#24
0
def bitshares_instance(bitshares_testnet):
    """ Initialize BitShares instance connected to a local testnet
    """
    bitshares = BitShares(
        node='ws://127.0.0.1:{}'.format(bitshares_testnet.service_port), keys=PRIVATE_KEYS, num_retries=10
    )
    # Shared instance allows to avoid any bugs when bitshares_instance is not passed explicitly when instantiating
    # objects
    set_shared_bitshares_instance(bitshares)
    # Todo: show chain params when connectiong to unknown network
    # https://github.com/bitshares/python-bitshares/issues/221

    return bitshares
示例#25
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(nobroadcast=True, wif=[wif])
        set_shared_bitshares_instance(self.bts)
        self.bts.set_default_account("init0")

        cache = ObjectCache(default_expiration=5, no_overwrite=True)
        init0 = {
            'active': {
                'account_auths': [],
                'address_auths': [],
                'key_auths': [[str(PrivateKey(wif).pubkey), 1]],
                'weight_threshold': 1
            },
            'active_special_authority': [0, {}],
            'blacklisted_accounts': [],
            'blacklisting_accounts': [],
            'cashback_vb': '1.13.102',
            'id': '1.2.90742',
            'lifetime_referrer': '1.2.90742',
            'lifetime_referrer_fee_percentage': 8000,
            'membership_expiration_date': '1969-12-31T23:59:59',
            'name': 'init0',
            'network_fee_percentage': 2000,
            'options': {
                'extensions': [],
                'memo_key': str(PrivateKey(wif).pubkey),
                'num_committee': 0,
                'num_witness': 0,
                'votes': [],
                'voting_account': '1.2.5'
            },
            'owner': {
                'account_auths': [],
                'address_auths': [],
                'key_auths': [[str(PrivateKey(wif).pubkey), 1]],
                'weight_threshold': 1
            },
            'owner_special_authority': [0, {}],
            'referrer': '1.2.90742',
            'referrer_rewards_percentage': 0,
            'registrar': '1.2.90742',
            'statistics': '2.6.90742',
            'top_n_control_flags': 0,
            'whitelisted_accounts': [],
            'whitelisting_accounts': []
        }
        cache[init0["id"]] = init0
        cache[init0["name"]] = init0
        BlockchainObject._cache = cache
示例#26
0
    def test_default_connection(self):
        b1 = BitShares("wss://node.testnet.bitshares.eu", nobroadcast=True)
        set_shared_bitshares_instance(b1)
        test = Asset("1.3.0", blockchain_instance=b1)
        # Needed to clear cache
        test.refresh()

        b2 = BitShares("wss://node.bitshares.eu", nobroadcast=True)
        set_shared_bitshares_instance(b2)
        bts = Asset("1.3.0", blockchain_instance=b2)
        # Needed to clear cache
        bts.refresh()

        self.assertEqual(test["symbol"], "TEST")
        self.assertEqual(bts["symbol"], "X4T")
示例#27
0
def setup_bitshares_market(bts_symbol):
    bitshares_instance = BitShares(
        "wss://siliconvalley.us.api.bitshares.org/ws",
        "wss://bitshares.openledger.info/ws",
        nobroadcast=True  # <<--- set this to False when you want to fire!
    )
    bts_config_file = "safe/bitshares.ini"
    bts_passwd, acct= get_bts_config(bts_config_file)
    bitshares_instance.wallet.unlock(bts_passwd)

    set_shared_bitshares_instance(bitshares_instance)
    bts_market = Market(
        bts_symbol,
        bitshares_instance=bitshares_instance
    )
    return bts_market
示例#28
0
    def test_default_connection(self):
        b1 = BitShares(
            "wss://node.testnet.bitshares.eu",
            nobroadcast=True,
        )
        set_shared_bitshares_instance(b1)
        test = Asset("1.3.0")

        b2 = BitShares(
            "wss://node.bitshares.eu",
            nobroadcast=True,
        )
        set_shared_bitshares_instance(b2)

        bts = Asset("1.3.0")

        self.assertEqual(test["symbol"], "TEST")
        self.assertEqual(bts["symbol"], "BTS")
示例#29
0
文件: ui.py 项目: bue-twitter/DEXBot
    def new_func(ctx, *args, **kwargs):
        nodelist = ctx.config["node"]
        timeout = int(ctx.obj.get("sortnodes"))

        host_ip = '8.8.8.8'
        if ping(host_ip, 3) is False:
            click.echo("internet NOT available! Please check your connection!")
            log.critical("Internet not available, exiting")
            sys.exit(78)

        if timeout > 0:
            click.echo(
                "Checking for nearest nodes with timeout < {} sec....".format(
                    timeout))
            nodelist = get_sorted_nodelist(ctx.config["node"], timeout)
            click.echo("Nearest nodes ->  " + str(nodelist))

        ctx.bitshares = BitShares(nodelist,
                                  num_retries=-1,
                                  expiration=60,
                                  **ctx.obj)
        set_shared_bitshares_instance(ctx.bitshares)
        return ctx.invoke(f, *args, **kwargs)
示例#30
0
from datetime import datetime

from bitshares import BitShares
from bitshares.instance import set_shared_bitshares_instance

# класс с расчетом цен на бирже BitShares
from btsParser.Parser import Parser
# класс для работы с VIZ (от Протея)
from tvizbase.api import Api

with open(os.path.dirname(__file__) + '/settings.json', 'r') as sett_file:
    settings = json.load(sett_file)
decimal.getcontext().rounding = 'ROUND_HALF_UP'
# подключение к ноде node в сети Bitshares
BTS = BitShares(node=settings['bitshares_node'])
set_shared_bitshares_instance(BTS)
# подключение к сети VIZ
viz = Api()
# инициализация класса
parser = Parser(settings)
# получение данных о глубине стаканов
parser.get_market_depth()
# получение данных об истории сделок
#parser.get_history_depth()
# публикация данных в блокчейне VIZ
viz.custom(
    'vizplus_bitshares_info',  # ID custom'а 
    [
        'vizplus_bitshares_info',  # название типа данных, может отличаться от ID
        {
            'time_utc':
示例#31
0
 def new_func(ctx, *args, **kwargs):
     ctx.bitshares = BitShares(**ctx.obj)
     ctx.blockchain = ctx.bitshares
     set_shared_bitshares_instance(ctx.bitshares)
     return ctx.invoke(f, *args, **kwargs)