예제 #1
0
def create_msg(options=None):
    '''
    Standard for message passing.

    All messages contain an id, a message-id and a timestamp.

    id: public key
    message-id: global incremented value
    timestamp: current time in iso format
    '''

    if options is None:
        options = {}

    global message_id

    message = {
        "id": get_public_bytestring(),
        "message-id": message_id,
        "timestamp": datetime.datetime.now().isoformat(),
    }
    message.update(options)

    message_id = message_id + 1

    return message
예제 #2
0
def create_msg(options=None):
    '''
    Standard for message passing.

    All messages contain an id, a message-id and a timestamp.

    id: public key
    message-id: global incremented value
    timestamp: current time in iso format
    '''

    if options is None:
        options = {}

    global message_id

    message = {
        "id": get_public_bytestring(),
        "message-id": message_id,
        "timestamp": datetime.datetime.now().isoformat(),
    }

    message.update(options)

    message_id = message_id + 1

    return message
예제 #3
0
 def handle_trade(self, trade):
     id, trade_id = get_public_bytestring(), trade['trade-id']
     offer = get_offer(id=id, message_id=trade_id)
     if offer:
         offers.remove(offer)
         trades.append(offer)
         return create_confirm(recipient=trade['id'], trade_id=trade_id)
     else:
         return create_cancel(recipient=trade['id'], trade_id=trade_id)
예제 #4
0
 def handle_trade(self, trade):
     id, trade_id = get_public_bytestring(), trade["trade-id"]
     offer = get_offer(id=id, message_id=trade_id)
     if offer:
         offers.remove(offer)
         trades.append(offer)
         return create_confirm(recipient=trade["id"], trade_id=trade_id)
     else:
         return create_cancel(recipient=trade["id"], trade_id=trade_id)
예제 #5
0
def get_own_bids():
    return filter(
        lambda offer: offer['type'] == 'bid' and offer['id'] ==
        get_public_bytestring(), offers)
예제 #6
0
def get_asks():
    return filter(
        lambda offer: offer['type'] == 'ask' and offer['id'] !=
        get_public_bytestring(), offers)
예제 #7
0
def get_own_bids():
    return filter(lambda offer:
                offer['type'] == 'bid' and
                offer['id'] == get_public_bytestring(),
            offers)
예제 #8
0
def get_asks():
    return filter(lambda offer:
                offer['type'] == 'ask' and
                offer['id'] != get_public_bytestring(),
            offers)