Exemplo n.º 1
0
def on_block(args, **kwargs):
    for username in conf.ACCOUNTS:
        add_new_section(username)
        ac = Account(username)
        history = ac.history(only_ops=['fill_order'])
        latest_order = config.get(username, 'last_order_id', fallback=None)
        first_order = None
        new_orders = []
        for op in history:
            trxid = op['id']
            if len(op['op']) == 2:
                op['op'] = op['op'][1]
            op = FilledOrder(op)
            op['trxid'] = trxid

            if trxid == latest_order:
                new_orders.append(op)
                break

            if first_order == None:
                first_order = trxid

        if latest_order != None and len(new_orders):
            # Reversed sort order to get them in timeline order
            for op in new_orders[::-1]:
                # modify message
                send_msg = dataParser(op)
                send_tg_message('*' + username + '*: ' +
                                send_msg.replace('sell', '_sold_'))

        if first_order:
            config.set(username, 'last_order_id', first_order)

    with open(conffile, 'w+') as configfile:
        config.write(configfile)
Exemplo n.º 2
0
Arquivo: ui.py Projeto: kjmeta1/uptick
def pprintOperation(op):
    from bitshares.price import Order, FilledOrder

    id = op["op"][0]
    op = op["op"][1]
    if id == 1:
        return str(Order(op))
    elif id == 4:
        return str(FilledOrder(op))
    elif id == 5:
        return "New account created for {}".format(op["name"])
    elif id == 2:
        return "Canceled order %s" % op["order"]
    elif id == 6:
        return "Account {} updated".format(Account(op["account"])["name"])
    elif id == 33:
        return "Claiming from vesting: %s" % str(Amount(op["amount"]))
    elif id == 15:
        return "Reserve {}".format(str(Amount(op["amount_to_reserve"])))
    elif id == 0:
        from_account = Account(op["from"])
        to_account = Account(op["to"])
        amount = Amount(op["amount"])
        return "Transfer from {from_account[name]} to {to_account[name]}: {amount}".format(
            **locals())
    else:
        return format_dict(op)
Exemplo n.º 3
0
    def process_market(self, data):
        """ This method is used for post processing of market
            notifications. It will return instances of either

            * :class:`bitshares.price.Order` or
            * :class:`bitshares.price.FilledOrder`

        """
        for d in data:
            if not d:
                continue
            if isinstance(d, str):
                # Single order has been placed
                log.info("Calling on_market with Order()")
                self.on_market(Order(d))
                continue
            elif isinstance(d, dict):
                d = [d]

            # Orders have been matched
            for p in d:
                if not isinstance(p, list):
                    p = [p]
                for i in p:
                    if isinstance(i, dict):
                        if "pays" in i and "receives" in i:
                            self.on_market(FilledOrder(i))
                        elif "for_sale" in i and "sell_price" in i:
                            self.on_market(Order(i))
Exemplo n.º 4
0
def pprintOperation(op):
    from bitshares.price import Order, FilledOrder
    if op["op"][0] == 1:
        return str(Order(op["op"][1]))
    if op["op"][0] == 4:
        return str(FilledOrder(op["op"][1]))
    else:
        return json.dumps(op["op"][1], indent=4)
Exemplo n.º 5
0
def pprintOperation(op):
    from bitshares.price import Order, FilledOrder
    id = op["op"][0]
    op = op["op"][1]
    if id == 1:
        return str(Order(op))
    elif id == 4:
        return str(FilledOrder(op))
    elif id == 2:
        return "Canceled order %s" % op["order"]
    elif id == 0:
        from_account = Account(op["from"])
        to_account = Account(op["to"])
        amount = Amount(op["amount"])
        return "Transfer from {from_account[name]} to {to_account[name]}: {amount}".format(
            **locals())
    else:
        return json.dumps(op, indent=4)
Exemplo n.º 6
0
    def process_market(self, data):
        """ This method is used for post processing of market
            notifications. It will return instances of either

            * :class:`bitshares.price.Order` or
            * :class:`bitshares.price.FilledOrder` or
            * :class:`bitshares.price.UpdateCallOrder`

            Also possible are limit order updates (margin calls)

        """
        for d in data:
            if not d:
                continue
            if isinstance(d, str):
                # Single order has been placed
                log.debug("Calling on_market with Order()")
                self.on_market(Order(d, bitshares_instance=self.bitshares))
                continue
            elif isinstance(d, dict):
                d = [d]

            # Orders have been matched
            for p in d:
                if not isinstance(p, list):
                    p = [p]
                for i in p:
                    if isinstance(i, dict):
                        if "pays" in i and "receives" in i:
                            self.on_market(
                                FilledOrder(i,
                                            bitshares_instance=self.bitshares))
                        elif "for_sale" in i and "sell_price" in i:
                            self.on_market(
                                Order(i, bitshares_instance=self.bitshares))
                        elif "collateral" in i and "call_price" in i:
                            self.on_market(
                                UpdateCallOrder(
                                    i, bitshares_instance=self.bitshares))
                        else:
                            if i:
                                log.error("Unknown market update type: %s" % i)
Exemplo n.º 7
0
def pprintOperation(op, show_memo=False, ctx=None):
    from bitshares.price import Order, FilledOrder

    if isinstance(op, dict) and "op" in op:
        id = op["op"][0]
        op = op["op"][1]
    else:
        id = op[0]
        op = op[1]
    if id == 1:
        return str(Order(op))
    elif id == 4:
        return str(FilledOrder(op))
    elif id == 5:
        return "New account created for {}".format(op["name"])
    elif id == 2:
        return "Canceled order %s" % op["order"]
    elif id == 6:
        return "Account {} updated".format(Account(op["account"])["name"])
    elif id == 33:
        return "Claiming from vesting: %s" % str(Amount(op["amount"]))
    elif id == 15:
        return "Reserve {}".format(str(Amount(op["amount_to_reserve"])))
    elif id == 0:
        from_account = Account(op["from"])
        to_account = Account(op["to"])
        amount = Amount(op["amount"])
        memo = ""
        if show_memo and ctx is not None:
            try:
                plain_memo = Memo(blockchain_instance=ctx.blockchain).decrypt(
                    op["memo"])
            except Exception as e:
                plain_memo = str(e)
            memo = " (memo: {plain_memo})".format(**locals())
        return "Transfer from {from_account[name]} to {to_account[name]}: {amount}{memo}".format(
            **locals())
    else:
        return format_dict(op)