Example #1
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('0' * 40), OrderNumber(1)), ask_pair,
                 Timeout(3600), Timestamp.now(), True)
     ask._traded_quantity = ask_total_traded
     bid = Order(OrderId(TraderId('1' * 40), OrderNumber(1)), bid_pair,
                 Timeout(3600), Timestamp.now(), False)
     bid._traded_quantity = bid_total_traded
     tx = Transaction(
         TransactionId(TraderId('0' * 40), TransactionNumber(1)),
         AssetPair(AssetAmount(traded_amount, 'BTC'),
                   AssetAmount(traded_amount, 'MB')),
         OrderId(TraderId('0' * 40), OrderNumber(1)),
         OrderId(TraderId('1' * 40), OrderNumber(1)), Timestamp(0.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 = '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
Example #2
0
 def get_tick_block(return_ask, pair):
     tick_cls = Ask if return_ask else Bid
     ask = tick_cls(OrderId(TraderId('0' * 40), 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 = 'ask' if return_ask else 'bid'
     tick_block.transaction = {'tick': ask_tx, 'version': MarketCommunity.PROTOCOL_VERSION}
     return tick_block
Example #3
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('0' * 40), OrderNumber(1)), ask_pair, Timeout(3600), Timestamp.now(), True)
     ask._traded_quantity = ask_total_traded
     bid = Order(OrderId(TraderId('1' * 40), OrderNumber(1)), bid_pair, Timeout(3600), Timestamp.now(), False)
     bid._traded_quantity = bid_total_traded
     tx = Transaction(TransactionId(TraderId('0' * 40), TransactionNumber(1)),
                      AssetPair(AssetAmount(traded_amount, 'BTC'), AssetAmount(traded_amount, 'MB')),
                      OrderId(TraderId('0' * 40), OrderNumber(1)),
                      OrderId(TraderId('1' * 40), OrderNumber(1)), Timestamp(0.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 = '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