コード例 #1
0
ファイル: test_community.py プロジェクト: devos50/anydex-core
 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
コード例 #2
0
 def get_tick_block(return_ask, pair):
     tick_cls = Ask if return_ask else Bid
     ask = tick_cls(OrderId(TraderId(b'0' * 20), OrderNumber(1)), pair, Timeout(3600), Timestamp.now(), return_ask)
     ask_tx = ask.to_block_dict()
     ask_tx["address"], ask_tx["port"] = "127.0.0.1", 1337
     tick_block = MarketBlock()
     tick_block.type = b'ask' if return_ask else b'bid'
     tick_block.transaction = {'tick': ask_tx, 'version': MarketCommunity.PROTOCOL_VERSION}
     return tick_block
コード例 #3
0
ファイル: test_block.py プロジェクト: Tribler/anydex-core
def tx_done_block(ask, bid, accepted_trade):
    tx_done_block = MarketBlock()
    tx_done_block.type = b'tx_done'
    transaction = Transaction.from_accepted_trade(accepted_trade,
                                                  TransactionId(b'a' * 32))
    tx_done_block.transaction = {
        'ask': ask.to_block_dict(),
        'bid': bid.to_block_dict(),
        'tx': transaction.to_block_dictionary()
    }
コード例 #4
0
ファイル: test_block.py プロジェクト: Tribler/anydex-core
def payment_block():
    payment = {
        'trader_id': 'a' * 40,
        'transaction_id': 'a' * 64,
        'transferred': {
            'amount': 3,
            'type': 'BTC'
        },
        'payment_id': 'a',
        'address_from': 'a',
        'address_to': 'b',
        'timestamp': 1234,
    }
    payment_block = MarketBlock()
    payment_block.type = b'tx_payment'
    payment_block.transaction = {'payment': payment}
    return payment_block
コード例 #5
0
ファイル: test_block.py プロジェクト: Tribler/anydex-core
def tx_init_block(accepted_trade):
    tx_init_block = MarketBlock()
    tx_init_block.type = b'tx_init'
    tx_init_block.transaction = {'tx': accepted_trade.to_block_dictionary()}
    return tx_init_block
コード例 #6
0
ファイル: test_block.py プロジェクト: Tribler/anydex-core
def cancel_block():
    cancel_block = MarketBlock()
    cancel_block.type = b'cancel_order'
    cancel_block.transaction = {'trader_id': 'a' * 20, 'order_number': 1}
    return cancel_block
コード例 #7
0
ファイル: test_block.py プロジェクト: Tribler/anydex-core
def tick_block(ask):
    tick_block = MarketBlock()
    tick_block.type = b'ask'
    tick_block.transaction = {'tick': ask.to_block_dict()}
    return tick_block