Example #1
0
def apply_exchange_buy():
    order = BuyOrder()
    bid = order
    print(eoslib.n2s(bid.buyer.name))
    eoslib.requireAuth(bid.buyer.name)
    assert bid.quantity > 0, "invalid quantity"
    assert bid.expiration > eoslib.now(), "order expired"
    print(eoslib.n2s(bid.buyer.name), " created bid for ", order.quantity,
          " currency at price: ", order.price, "\n")
    buyer_account = Account(bid.buyer.name)
    buyer_account.eos_balance -= bid.quantity

    print('buyer_account:', buyer_account)
    lowest_ask = Ask.front_by_price()
    if not lowest_ask:
        print("\n No asks found, saving buyer account and storing bid\n")
        assert not order.fill_or_kill, "order not completely filled"
        bid.store()
        buyer_account.open_orders += 1
        buyer_account.save()
        return

    print("ask: ", lowest_ask, "\n")
    print("bid: ", bid, "\n")

    seller_account = Account(lowest_ask.seller.name)

    while lowest_ask.price <= bid.price:
        print("lowest ask <= bid.price\n", lowest_ask.price, bid.price)
        match(bid, buyer_account, lowest_ask, seller_account)

        if lowest_ask.quantity == 0:
            seller_account.open_orders -= 1
            seller_account.save()
            buyer_account.save()
            lowest_ask.remove()
            lowest_ask = Ask.front_by_price()
            if not lowest_ask:
                break
            seller_account = Account(lowest_ask.seller.name)
        else:
            break
            # buyer's bid should be filled
    print("lowest_ask >= bid.price or buyer's bid has been filled\n")

    if bid.quantity and not order.fill_or_kill:
        buyer_account.open_orders += 1
    buyer_account.save()
    print("saving buyer's account\n")
    if bid.quantity:
        print(bid.quantity, " eos left over")
        assert not order.fill_or_kill, "order not completely filled"
        bid.store()
        return
    print("bid filled\n")
Example #2
0
def apply_exchange_sell():
    order = SellOrder()
    ask = order
    requireAuth(ask.seller.name)

    assert ask.quantity > 0, "invalid quantity"
    assert ask.expiration > now(), "order expired"

    print("\n\n", eoslib.n2s(ask.seller.name), " created sell for ",
          order.quantity, " currency at price: ", order.price, "\n")

    existing_ask = Ask.load_by_order_id(ask.seller)
    assert not existing_ask, "order with this id already exists"

    seller_account = Account(ask.seller.name)
    seller_account.currency_balance -= ask.quantity

    highest_bid = Bid.back_by_price()
    if not highest_bid:
        assert not order.fill_or_kill, "order not completely filled"
        print("\n No bids found, saving seller account and storing ask\n")
        ask.store()
        seller_account.open_orders += 1
        seller_account.save()
        return

    print("\n bids found, lets see what matches\n")
    buyer_account = Account(highest_bid.buyer.name)

    while highest_bid.price >= ask.price:
        match(highest_bid, buyer_account, ask, seller_account)
        if highest_bid.quantity == 0:
            buyer_account.open_orders -= 1
            seller_account.save()
            buyer_account.save()
            highest_bid.remove()
            highest_bid = Bid.back_by_price()
            if not highest_bid:
                break
            buyer_account = Account(highest_bid.buyer.name)
        else:
            break
            # buyer's bid should be filled

    if ask.quantity and not order.fill_or_kill:
        seller_account.open_orders += 1
    seller_account.save()
    if ask.quantity:
        assert not order.fill_or_kill, "order not completely filled"
        print("saving ask\n")
        ask.store()
        return
    print("ask filled\n")
Example #3
0
def apply(receiver, code, action):
    print('+++++action:', n2s(action))
    if not action == N('sayhello'):
        return

    if 1:
        test_crash2()
        #    test_base_exception()
        test_base_exception2()
        test_memory_out()
        test_memory_out2()

    if 1:
        test_crash1()
        #    test_crash2()
        test_recursive_call()

        test_delete1()
        test_delete2()
        test_delete3()
    if 1:
        test_reload()
        test_context_manager()

#----------------------------

    test_getattr()
    test_setattr()

    #    test_code_object()
    test_code_object2()

    test_builtin_types()
    test_builtins()
    #--------------------------

    test_call_with_key_words()

    test_change_builtin_module()
    test_change_builtin_module2()
    test_change_builtin_module3()
    test_change_builtin_module4()

    test_set_func()

    test_import()
    test_import2()
    test_str_format()
    test_open()
    test_yield()
    test_large_pow()
    test_large_pack()
    test_large_pack2()
Example #4
0
def apply(name, type):
    #    print('hello from python apply',name,type)
    print(eoslib.n2s(name), eoslib.n2s(type))
    if type == eoslib.N(b'transfer'):
        msg = eoslib.read_message()
        result = struct.unpack('QQQ', msg)
        #         print(result)
        from_ = result[0]
        to_ = result[1]
        amount = result[2]

        eoslib.require_auth(from_)
        eoslib.require_notice(from_)
        eoslib.require_notice(to_)

        from_ = Account(from_)
        to_ = Account(to_)
        if from_.balance >= amount:
            from_.balance -= amount
            to_.balance += amount
            from_.store()
            to_.store()
Example #5
0
def dotest():
    msg = readMessage()

    name = uint64(msg[:8])
    print(name)
    print(eoslib.n2s(name))

    id = uint64(msg[8:])
    requireAuth(name)

    ask = Ask.front_by_price()
    print(ask)

    bid = Bid.front_by_price()
    print(bid)
Example #6
0
 def p(self):
     print(eoslib.n2s(self.issuer), self.amount, self.symbol,
           self.precision, self.can_freeze, self.can_recall,
           self.can_whitelist)
Example #7
0
 def p(self):
     print(eoslib.n2s(self.to), self.amount, self.symbol)
Example #8
0
 def p(self):
     print(eoslib.n2s(self._from), eoslib.n2s(self.to), self.amount,
           self.precision, self.symbol, self.memo)
Example #9
0
 def p(self):
     print(n2s(self.to), self.amount, self.symbol)
Example #10
0
 def p(self):
     print(n2s(self._from), n2s(self.to), self.amount, self.precision,
           self.symbol, unpack(self.memo))