示例#1
0
    async def setUp(self):
        super(TestDatabase, self).setUp()

        path = os.path.join(self.getStateDir(), 'sqlite')
        if not os.path.exists(path):
            os.makedirs(path)

        self.database = MarketDB(self.getStateDir(), 'market')

        self.order_id1 = OrderId(TraderId(b'3' * 20), OrderNumber(4))
        self.order_id2 = OrderId(TraderId(b'4' * 20), OrderNumber(5))
        self.order1 = Order(
            self.order_id1,
            AssetPair(AssetAmount(5, 'BTC'), AssetAmount(6, 'EUR')),
            Timeout(3600), Timestamp.now(), True)
        self.order2 = Order(
            self.order_id2,
            AssetPair(AssetAmount(5, 'BTC'), AssetAmount(6, 'EUR')),
            Timeout(3600), Timestamp.now(), False)
        self.order2.reserve_quantity_for_tick(
            OrderId(TraderId(b'3' * 20), OrderNumber(4)), 3)

        self.transaction_id1 = TransactionId(b'a' * 32)
        self.transaction1 = Transaction(
            self.transaction_id1,
            AssetPair(AssetAmount(100, 'BTC'), AssetAmount(30, 'MB')),
            OrderId(TraderId(b'0' * 20), OrderNumber(1)),
            OrderId(TraderId(b'1' * 20), OrderNumber(2)), Timestamp(20000))

        self.payment1 = Payment(TraderId(b'0' * 20), self.transaction_id1,
                                AssetAmount(5, 'BTC'), WalletAddress('abc'),
                                WalletAddress('def'), PaymentId("abc"),
                                Timestamp(20000))

        self.transaction1.add_payment(self.payment1)
示例#2
0
    def test_insert_or_update_transaction(self):
        """
        Test the conditional insertion or update of a transaction in the database
        """
        # Test insertion
        self.database.insert_or_update_transaction(self.transaction1)
        transactions = self.database.get_all_transactions()
        self.assertEqual(len(transactions), 1)

        # Test try to update with older timestamp
        before_trans1 = Transaction(
            self.transaction1.transaction_id, self.transaction1.assets,
            self.transaction1.order_id, self.transaction1.partner_order_id,
            Timestamp(int(self.transaction1.timestamp) - 1000))
        self.database.insert_or_update_transaction(before_trans1)
        transaction = self.database.get_transaction(
            self.transaction1.transaction_id)
        self.assertEqual(int(transaction.timestamp),
                         int(self.transaction1.timestamp))

        # Test update with newer timestamp
        after_trans1 = Transaction(
            self.transaction1.transaction_id, self.transaction1.assets,
            self.transaction1.order_id, self.transaction1.partner_order_id,
            Timestamp(int(self.transaction1.timestamp) + 1000))
        self.database.insert_or_update_transaction(after_trans1)
        transaction = self.database.get_transaction(
            self.transaction1.transaction_id)
        self.assertEqual(int(transaction.timestamp),
                         int(after_trans1.timestamp))
示例#3
0
    def from_database(cls, data, reserved_ticks):
        """
        Create an Order object based on information in the database.
        """
        (trader_id, order_number, asset1_amount, asset1_type, asset2_amount,
         asset2_type, traded_quantity, timeout, order_timestamp,
         completed_timestamp, is_ask, cancelled, verified) = data

        order_id = OrderId(TraderId(bytes(trader_id)),
                           OrderNumber(order_number))
        order = cls(
            order_id,
            AssetPair(AssetAmount(asset1_amount, str(asset1_type)),
                      AssetAmount(asset2_amount, str(asset2_type))),
            Timeout(timeout), Timestamp(order_timestamp), bool(is_ask))
        order._traded_quantity = traded_quantity
        order._cancelled = bool(cancelled)
        order._verified = verified
        if completed_timestamp:
            order._completed_timestamp = Timestamp(completed_timestamp)

        for reserved_order_id, quantity in reserved_ticks:
            order.reserved_ticks[reserved_order_id] = quantity
            order._reserved_quantity += quantity

        return order
示例#4
0
    def test_from_network(self):
        # Test for from network
        data = StartTransaction.from_network(
            type(
                'Data', (object, ), {
                    "trader_id":
                    TraderId(b'0' * 20),
                    "transaction_id":
                    TransactionId(TraderId(b'0' * 20), TransactionNumber(1)),
                    "order_id":
                    OrderId(TraderId(b'0' * 20), OrderNumber(1)),
                    "recipient_order_id":
                    OrderId(TraderId(b'1' * 20), OrderNumber(2)),
                    "proposal_id":
                    1235,
                    "assets":
                    AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')),
                    "timestamp":
                    Timestamp(0)
                }))

        self.assertEquals(TraderId(b'0' * 20), data.trader_id)
        self.assertEquals(
            TransactionId(TraderId(b'0' * 20), TransactionNumber(1)),
            data.transaction_id)
        self.assertEquals(OrderId(TraderId(b'0' * 20), OrderNumber(1)),
                          data.order_id)
        self.assertEquals(OrderId(TraderId(b'1' * 20), OrderNumber(2)),
                          data.recipient_order_id)
        self.assertEquals(1235, data.proposal_id)
        self.assertEquals(Timestamp(0), data.timestamp)
示例#5
0
    def test_update_ticks(self):
        """
        Test updating ticks in an order book
        """
        self.order_book.insert_ask(self.ask)
        self.order_book.insert_bid(self.bid)

        ask_dict = {
            "trader_id": self.ask.order_id.trader_id.as_hex(),
            "order_number": int(self.ask.order_id.order_number),
            "assets": self.ask.assets.to_dictionary(),
            "traded": 100,
            "timeout": 3600,
            "timestamp": int(Timestamp.now())
        }
        bid_dict = {
            "trader_id": self.bid.order_id.trader_id.as_hex(),
            "order_number": int(self.bid.order_id.order_number),
            "assets": self.bid.assets.to_dictionary(),
            "traded": 100,
            "timeout": 3600,
            "timestamp": int(Timestamp.now())
        }

        ask_dict["traded"] = 50
        bid_dict["traded"] = 50
        self.order_book.completed_orders = []
        self.order_book.update_ticks(ask_dict, bid_dict, 100)
        self.assertEqual(len(self.order_book.asks), 1)
        self.assertEqual(len(self.order_book.bids), 1)
示例#6
0
def test_insert_or_update_transaction(db, transaction):
    """
    Test the conditional insertion or update of a transaction in the database
    """
    # Test insertion
    db.insert_or_update_transaction(transaction)
    transactions = db.get_all_transactions()
    assert len(transactions) == 1

    # Test try to update with older timestamp
    before_trans1 = Transaction(transaction.transaction_id, transaction.assets,
                                transaction.order_id,
                                transaction.partner_order_id,
                                Timestamp(int(transaction.timestamp) - 1000))
    db.insert_or_update_transaction(before_trans1)
    transaction = db.get_transaction(transaction.transaction_id)
    assert int(transaction.timestamp) == int(transaction.timestamp)

    # Test update with newer timestamp
    after_trans1 = Transaction(transaction.transaction_id, transaction.assets,
                               transaction.order_id,
                               transaction.partner_order_id,
                               Timestamp(int(transaction.timestamp) + 1000))
    db.insert_or_update_transaction(after_trans1)
    transaction = db.get_transaction(transaction.transaction_id)
    assert int(transaction.timestamp) == int(after_trans1.timestamp)
示例#7
0
def test_update_ticks(ask, bid, order_book):
    """
    Test updating ticks in an order book
    """
    order_book.insert_ask(ask)
    order_book.insert_bid(bid)

    ask_dict = {
        "trader_id": ask.order_id.trader_id.as_hex(),
        "order_number": int(ask.order_id.order_number),
        "assets": ask.assets.to_dictionary(),
        "traded": 100,
        "timeout": 3600,
        "timestamp": int(Timestamp.now())
    }
    bid_dict = {
        "trader_id": bid.order_id.trader_id.as_hex(),
        "order_number": int(bid.order_id.order_number),
        "assets": bid.assets.to_dictionary(),
        "traded": 100,
        "timeout": 3600,
        "timestamp": int(Timestamp.now())
    }

    ask_dict["traded"] = 50
    bid_dict["traded"] = 50
    order_book.completed_orders = []
    order_book.update_ticks(ask_dict, bid_dict, 100)
    assert len(order_book.asks) == 1
    assert len(order_book.bids) == 1
示例#8
0
 def get_tx_done_block(ask_amount, bid_amount, traded_amount,
                       ask_total_traded, bid_total_traded):
     ask_pair = AssetPair(AssetAmount(ask_amount, 'BTC'),
                          AssetAmount(ask_amount, 'MB'))
     bid_pair = AssetPair(AssetAmount(bid_amount, 'BTC'),
                          AssetAmount(bid_amount, 'MB'))
     ask = Order(OrderId(TraderId(b'0' * 20), OrderNumber(1)), ask_pair,
                 Timeout(3600), Timestamp.now(), True)
     ask._traded_quantity = ask_total_traded
     bid = Order(OrderId(TraderId(b'1' * 20), OrderNumber(1)), bid_pair,
                 Timeout(3600), Timestamp.now(), False)
     bid._traded_quantity = bid_total_traded
     tx = Transaction(
         TransactionId(TraderId(b'0' * 20), TransactionNumber(1)),
         AssetPair(AssetAmount(traded_amount, 'BTC'),
                   AssetAmount(traded_amount, 'MB')),
         OrderId(TraderId(b'0' * 20), OrderNumber(1)),
         OrderId(TraderId(b'1' * 20), OrderNumber(1)), Timestamp(0))
     tx.transferred_assets.first += AssetAmount(traded_amount, 'BTC')
     tx.transferred_assets.second += AssetAmount(traded_amount, 'MB')
     tx_done_block = MarketBlock()
     tx_done_block.type = b'tx_done'
     tx_done_block.transaction = {
         'ask': ask.to_status_dictionary(),
         'bid': bid.to_status_dictionary(),
         'tx': tx.to_dictionary(),
         'version': MarketCommunity.PROTOCOL_VERSION
     }
     tx_done_block.transaction['ask']['address'], tx_done_block.transaction[
         'ask']['port'] = "1.1.1.1", 1234
     tx_done_block.transaction['bid']['address'], tx_done_block.transaction[
         'bid']['port'] = "1.1.1.1", 1234
     return tx_done_block
示例#9
0
 def test_timed_out(self):
     # Test for timed out
     self.assertTrue(
         self.timeout1.is_timed_out(
             Timestamp(int(time.time() * 1000) - 3700 * 1000)))
     self.assertFalse(
         self.timeout2.is_timed_out(Timestamp(int(time.time() * 1000))))
示例#10
0
    def setUp(self):
        yield super(MatchingEngineTestSuite, self).setUp()
        # Object creation
        self.ask = Ask(
            OrderId(TraderId(b'2' * 20), OrderNumber(1)),
            AssetPair(AssetAmount(3000, 'BTC'), AssetAmount(30, 'MB')),
            Timeout(30), Timestamp.now())
        self.bid = Bid(
            OrderId(TraderId(b'4' * 20), OrderNumber(2)),
            AssetPair(AssetAmount(3000, 'BTC'), AssetAmount(30, 'MB')),
            Timeout(30), Timestamp.now())
        self.ask_order = Order(
            OrderId(TraderId(b'5' * 20), OrderNumber(3)),
            AssetPair(AssetAmount(3000, 'BTC'), AssetAmount(30, 'MB')),
            Timeout(30), Timestamp.now(), True)
        self.bid_order = Order(
            OrderId(TraderId(b'6' * 20), OrderNumber(4)),
            AssetPair(AssetAmount(3000, 'BTC'), AssetAmount(30, 'MB')),
            Timeout(30), Timestamp.now(), False)
        self.order_book = OrderBook()
        self.matching_engine = MatchingEngine(
            PriceTimeStrategy(self.order_book))

        self.ask_count = 2
        self.bid_count = 2
示例#11
0
    def test_from_network(self):
        # Test for from network
        data = ProposedTrade.from_network(
            type(
                'Data', (object, ), {
                    "trader_id":
                    TraderId(b'0' * 20),
                    "order_number":
                    OrderNumber(1),
                    "recipient_order_id":
                    OrderId(TraderId(b'1' * 20), OrderNumber(2)),
                    "proposal_id":
                    1234,
                    "timestamp":
                    Timestamp(1462224447117),
                    "assets":
                    AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB'))
                }))

        self.assertEquals(TraderId(b'0' * 20), data.trader_id)
        self.assertEquals(OrderId(TraderId(b'0' * 20), OrderNumber(1)),
                          data.order_id)
        self.assertEquals(OrderId(TraderId(b'1' * 20), OrderNumber(2)),
                          data.recipient_order_id)
        self.assertEquals(1234, data.proposal_id)
        self.assertEquals(
            AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')),
            data.assets)
        self.assertEquals(Timestamp(1462224447117), data.timestamp)
示例#12
0
    def test_from_network(self):
        # Test for from network
        data = Payment.from_network(
            type(
                'Data', (object, ), {
                    "trader_id":
                    TraderId(b'0' * 20),
                    "transaction_id":
                    TransactionId(TraderId(b'2' * 20), TransactionNumber(2)),
                    "transferred_assets":
                    AssetAmount(3, 'BTC'),
                    "address_from":
                    WalletAddress('a'),
                    "address_to":
                    WalletAddress('b'),
                    "payment_id":
                    PaymentId('aaa'),
                    "timestamp":
                    Timestamp(4000),
                    "success":
                    True
                }))

        self.assertEquals(TraderId(b'0' * 20), data.trader_id)
        self.assertEquals(
            TransactionId(TraderId(b'2' * 20), TransactionNumber(2)),
            data.transaction_id)
        self.assertEquals(AssetAmount(3, 'BTC'), data.transferred_assets)
        self.assertEquals(Timestamp(4000), data.timestamp)
        self.assertTrue(data.success)
 def setUp(self):
     # Object creation
     self.memory_order_repository = MemoryOrderRepository(b'0' * 20)
     self.order_id = OrderId(TraderId(b'0' * 20), OrderNumber(1))
     self.order = Order(self.order_id, AssetPair(AssetAmount(100, 'BTC'), AssetAmount(30, 'MC')),
                        Timeout(0), Timestamp(10), False)
     self.order2 = Order(self.order_id, AssetPair(AssetAmount(1000, 'BTC'), AssetAmount(30, 'MC')),
                         Timeout(0), Timestamp(10), False)
示例#14
0
 def setUp(self):
     order_id = OrderId(TraderId(b'3' * 20), OrderNumber(1))
     self.ask_order = Order(
         order_id, AssetPair(AssetAmount(5, 'BTC'), AssetAmount(6, 'EUR')),
         Timeout(3600), Timestamp.now(), True)
     self.bid_order = Order(
         order_id, AssetPair(AssetAmount(5, 'BTC'), AssetAmount(6, 'EUR')),
         Timeout(3600), Timestamp.now(), False)
     self.queue = MatchPriorityQueue(self.ask_order)
示例#15
0
 def setUp(self):
     # Object creation
     self.proposed_trade = Trade.propose(
         TraderId(b'0' * 20), OrderId(TraderId(b'0' * 20), OrderNumber(1)),
         OrderId(TraderId(b'1' * 20), OrderNumber(2)),
         AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')),
         Timestamp(1462224447117))
     self.declined_trade = Trade.decline(
         TraderId(b'0' * 20), Timestamp(1462224447117), self.proposed_trade,
         DeclinedTradeReason.ORDER_COMPLETED)
示例#16
0
    def setUp(self):
        # Object creation

        self.tick = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(1)),
                         AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')),
                         Timeout(100), Timestamp.now(), True)
        self.tick2 = Tick(OrderId(TraderId(b'1' * 20), OrderNumber(2)),
                          AssetPair(AssetAmount(120, 'BTC'), AssetAmount(30, 'MB')),
                          Timeout(100), Timestamp.now(), True)
        self.side = Side()
示例#17
0
    def setUp(self):
        BaseTestCase.setUp(self)

        self.ask = Ask(
            OrderId(TraderId(b'0' * 20), OrderNumber(1)),
            AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MB')),
            Timeout(30), Timestamp(0), True)
        self.bid = Ask(
            OrderId(TraderId(b'1' * 20), OrderNumber(1)),
            AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MB')),
            Timeout(30), Timestamp(0), False)
        self.transaction = Transaction(
            TransactionId(TraderId(b'0' * 20), TransactionNumber(1)),
            AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MB')),
            OrderId(TraderId(b'0' * 20), OrderNumber(1)),
            OrderId(TraderId(b'1' * 20), OrderNumber(1)), Timestamp(0))

        ask_tx = self.ask.to_block_dict()
        bid_tx = self.bid.to_block_dict()

        self.tick_block = MarketBlock()
        self.tick_block.type = b'ask'
        self.tick_block.transaction = {'tick': ask_tx}

        self.cancel_block = MarketBlock()
        self.cancel_block.type = b'cancel_order'
        self.cancel_block.transaction = {
            'trader_id': 'a' * 20,
            'order_number': 1
        }

        self.tx_block = MarketBlock()
        self.tx_block.type = b'tx_init'
        self.tx_block.transaction = {
            'ask': ask_tx,
            'bid': bid_tx,
            'tx': self.transaction.to_dictionary()
        }

        payment = {
            'trader_id': 'a' * 40,
            'transaction_number': 3,
            'transferred': {
                'amount': 3,
                'type': 'BTC'
            },
            'payment_id': 'a',
            'address_from': 'a',
            'address_to': 'b',
            'timestamp': 1234,
            'success': True
        }
        self.payment_block = MarketBlock()
        self.payment_block.type = b'tx_payment'
        self.payment_block.transaction = {'payment': payment}
示例#18
0
 def setUp(self):
     # Object creation
     self.proposed_trade = Trade.propose(
         TraderId(b'0' * 20), OrderId(TraderId(b'0' * 20), OrderNumber(1)),
         OrderId(TraderId(b'1' * 20), OrderNumber(2)),
         AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')),
         Timestamp(1462224447117))
     self.counter_trade = Trade.counter(
         TraderId(b'0' * 20),
         AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')),
         Timestamp(1462224447117), self.proposed_trade)
示例#19
0
    def update_ticks(self, ask_order_dict, bid_order_dict, traded_quantity):
        """
        Update ticks according to a TrustChain block containing the status of the ask/bid orders.

        :type ask_order_dict: dict
        :type bid_order_dict: dict
        :type traded_quantity: int
        """
        ask_order_id = OrderId(TraderId(unhexlify(ask_order_dict["trader_id"])),
                               OrderNumber(ask_order_dict["order_number"]))
        bid_order_id = OrderId(TraderId(unhexlify(bid_order_dict["trader_id"])),
                               OrderNumber(bid_order_dict["order_number"]))

        self._logger.debug("Updating ticks in order book: %s and %s (traded quantity: %s)",
                           str(ask_order_id), str(bid_order_id), str(traded_quantity))

        # Update ask tick
        ask_exists = self.tick_exists(ask_order_id)
        if ask_exists and ask_order_dict["traded"] >= self.get_tick(ask_order_id).traded:
            tick = self.get_tick(ask_order_id)
            tick.traded = ask_order_dict["traded"]
            if tick.traded >= tick.assets.first.amount:
                self.remove_tick(tick.order_id)
                self.completed_orders.add(tick.order_id)
        elif not ask_exists and ask_order_dict["traded"] < ask_order_dict["assets"]["first"]["amount"] and \
                ask_order_id not in self.completed_orders:
            new_pair = AssetPair.from_dictionary(ask_order_dict["assets"])
            ask = Ask(ask_order_id, new_pair, Timeout(ask_order_dict["timeout"]),
                      Timestamp(ask_order_dict["timestamp"]), traded=ask_order_dict["traded"])
            self.insert_ask(ask)
        elif not ask_exists and ask_order_dict["traded"] >= ask_order_dict["assets"]["first"]["amount"]:
            self.completed_orders.add(ask_order_id)

        # Update bid tick
        bid_exists = self.tick_exists(bid_order_id)
        if bid_exists and bid_order_dict["traded"] >= self.get_tick(bid_order_id).traded:
            tick = self.get_tick(bid_order_id)
            tick.traded = bid_order_dict["traded"]
            if tick.traded >= tick.assets.first.amount:
                self.remove_tick(tick.order_id)
                self.completed_orders.add(tick.order_id)
        elif not bid_exists and bid_order_dict["traded"] < bid_order_dict["assets"]["first"]["amount"] and \
                bid_order_id not in self.completed_orders:
            new_pair = AssetPair.from_dictionary(bid_order_dict["assets"])
            bid = Bid(bid_order_id, new_pair, Timeout(bid_order_dict["timeout"]),
                      Timestamp(bid_order_dict["timestamp"]), traded=bid_order_dict["traded"])
            self.insert_bid(bid)
        elif not bid_exists and bid_order_dict["traded"] >= bid_order_dict["assets"]["first"]["amount"]:
            self.completed_orders.add(bid_order_id)
示例#20
0
    async def setUp(self):
        super(TickEntryTestSuite, self).setUp()

        # Object creation
        tick = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(1)),
                    AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')),
                    Timeout(0), Timestamp(0), True)
        tick2 = Tick(
            OrderId(TraderId(b'0' * 20), OrderNumber(2)),
            AssetPair(AssetAmount(63400, 'BTC'), AssetAmount(30, 'MB')),
            Timeout(100), Timestamp.now(), True)

        self.price_level = PriceLevel(Price(100, 1, 'MB', 'BTC'))
        self.tick_entry = TickEntry(tick, self.price_level)
        self.tick_entry2 = TickEntry(tick2, self.price_level)
示例#21
0
    def setUp(self):
        # Object creation
        tick = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(1)),
                    AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MC')),
                    Timeout(100), Timestamp.now(), True)
        tick2 = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(2)),
                     AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MC')),
                     Timeout(100), Timestamp.now(), True)

        self.price_level = PriceLevel(Price(50, 5, 'MC', 'BTC'))
        self.tick_entry1 = TickEntry(tick, self.price_level)
        self.tick_entry2 = TickEntry(tick, self.price_level)
        self.tick_entry3 = TickEntry(tick, self.price_level)
        self.tick_entry4 = TickEntry(tick, self.price_level)
        self.tick_entry5 = TickEntry(tick2, self.price_level)
示例#22
0
async def tick_entry2(price_level):
    tick = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(2)),
                AssetPair(AssetAmount(63400, 'BTC'), AssetAmount(30, 'MB')),
                Timeout(100), Timestamp.now(), True)
    tick_entry = TickEntry(tick, price_level)
    yield tick_entry
    await tick_entry.shutdown_task_manager()
示例#23
0
 def from_unpack_list(cls, trader_id, timestamp, order_number,
                      other_trader_id, other_order_number, decline_reason):
     return DeclineMatchPayload(
         TraderId(trader_id), Timestamp(timestamp),
         OrderNumber(order_number),
         OrderId(TraderId(other_trader_id),
                 OrderNumber(other_order_number)), decline_reason)
示例#24
0
 def from_unpack_list(cls, trader_id, timestamp, transaction_id,
                      incoming_address, outgoing_address):
     return WalletInfoPayload(
         TraderId(trader_id), Timestamp(timestamp),
         TransactionId(transaction_id),
         WalletAddress(incoming_address.decode('utf-8')),
         WalletAddress(outgoing_address.decode('utf-8')))
示例#25
0
 def setUp(self):
     # Object creation
     self.payment = Payment(
         TraderId(b'0' * 20),
         TransactionId(TraderId(b'2' * 20), TransactionNumber(2)),
         AssetAmount(3, 'BTC'), WalletAddress('a'), WalletAddress('b'),
         PaymentId('aaa'), Timestamp(4000), True)
示例#26
0
 def from_unpack_list(cls, trader_id, timestamp, transaction_trader_id, transaction_number,
                      transferred_amount, transferred_type, address_from, address_to, payment_id, success):
     return PaymentPayload(TraderId(trader_id), Timestamp(timestamp),
                           TransactionId(TraderId(transaction_trader_id), TransactionNumber(transaction_number)),
                           AssetAmount(transferred_amount, transferred_type.decode('utf-8')),
                           WalletAddress(address_from.decode('utf-8')),
                           WalletAddress(address_to.decode('utf-8')), PaymentId(payment_id.decode('utf-8')), success)
示例#27
0
 def from_unpack_list(cls, trader_id, timestamp, order_number, asset1_amount, asset1_type, asset2_amount,
                      asset2_type, timeout, traded, recipient_order_number, match_trader_id, matchmaker_trader_id):
     return MatchPayload(TraderId(trader_id), Timestamp(timestamp), OrderNumber(order_number),
                         AssetPair(AssetAmount(asset1_amount, asset1_type.decode('utf-8')),
                                   AssetAmount(asset2_amount, asset2_type.decode('utf-8'))),
                         Timeout(timeout), traded, OrderNumber(recipient_order_number),
                         TraderId(match_trader_id), TraderId(matchmaker_trader_id))
示例#28
0
    def from_database(cls, data, payments):
        """
        Create a Transaction object based on information in the database.
        """
        (trader_id, transaction_id, order_number, partner_trader_id, partner_order_number,
         asset1_amount, asset1_type, asset1_transferred, asset2_amount, asset2_type, asset2_transferred,
         transaction_timestamp, sent_wallet_info, received_wallet_info, incoming_address, outgoing_address,
         partner_incoming_address, partner_outgoing_address) = data

        transaction_id = TransactionId(bytes(transaction_id))
        transaction = cls(transaction_id,
                          AssetPair(AssetAmount(asset1_amount, str(asset1_type)),
                                    AssetAmount(asset2_amount, str(asset2_type))),
                          OrderId(TraderId(bytes(trader_id)), OrderNumber(order_number)),
                          OrderId(TraderId(bytes(partner_trader_id)), OrderNumber(partner_order_number)),
                          Timestamp(transaction_timestamp))

        transaction._transferred_assets = AssetPair(AssetAmount(asset1_transferred, str(asset1_type)),
                                                    AssetAmount(asset2_transferred, str(asset2_type)))
        transaction.sent_wallet_info = sent_wallet_info
        transaction.received_wallet_info = received_wallet_info
        transaction.incoming_address = WalletAddress(str(incoming_address))
        transaction.outgoing_address = WalletAddress(str(outgoing_address))
        transaction.partner_incoming_address = WalletAddress(str(partner_incoming_address))
        transaction.partner_outgoing_address = WalletAddress(str(partner_outgoing_address))
        transaction._payments = payments

        return transaction
示例#29
0
def order2():
    order_id2 = OrderId(TraderId(b'4' * 20), OrderNumber(5))
    order2 = Order(order_id2,
                   AssetPair(AssetAmount(5, 'BTC'), AssetAmount(6, 'EUR')),
                   Timeout(3600), Timestamp.now(), False)
    order2.reserve_quantity_for_tick(
        OrderId(TraderId(b'3' * 20), OrderNumber(4)), 3)
    return order2
示例#30
0
 def test_to_network(self):
     # Test for to network
     self.assertEquals(
         (TraderId(b'0' * 20), Timestamp(1462224447117), OrderNumber(1),
          OrderId(TraderId(b'1' * 20),
                  OrderNumber(2)), self.proposed_trade.proposal_id,
          AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB'))),
         self.proposed_trade.to_network())