コード例 #1
0
ファイル: api.py プロジェクト: radek1st/openrelay
def orders():
    for field in UNSUPPORTED_FIELDS:
        if request.args.get(field, False):
            return notsupported(field)
    count = int(request.args.get("limit", 25))
    makerTokenAddress = request.args.get("makerTokenAddress", None)
    takerTokenAddress = request.args.get("takerTokenAddress", None)
    if makerTokenAddress and takerTokenAddress:
        lookp_hash = hashlib.sha256(
            util.hexStringToBytes(makerTokenAddress) +
            util.hexStringToBytes(takerTokenAddress)).digest()
        index = dynamo.DynamoOrder.pairhash_index
    elif makerTokenAddress and not takerTokenAddress:
        lookup_hash = util.hexStringToBytes(makerTokenAddress)
        index = dynamo.DynamoOrder.makertoken_index
    elif not makerTokenAddress and takerTokenAddress:
        lookup_hash = util.hexStringToBytes(takerTokenAddress)
        index = dynamo.DynamoOrder.takertoken_index
    else:
        orders = dynamo.DynamoOrder.scan(limit=count)
        index = None
    if index:
        orders = index.query(lookup_hash, limit=count)

    return format_response(orders, count, request.headers.get("Accept", ""))
コード例 #2
0
ファイル: api.py プロジェクト: radek1st/openrelay
def pair_search(maker_token, taker_token):
    count = int(request.args.get("count", 25))
    orders = dynamo.DynamoOrder.pairhash_index.query(
        hashlib.sha256(
            util.hexStringToBytes(maker_token) +
            util.hexStringToBytes(taker_token)).digest(),
        scan_index_forward=(request.args.get("asc", "true") == "true"),
        limit=count)
    return format_response(orders, count, request.headers.get("Accept", ""))
コード例 #3
0
 def test_index(self):
     indexer.record_order(sample.data, Locker())
     item = next(dynamo.DynamoOrder.scan())
     test_order = item.ToOrder()
     self.assertEqual(test_order.price, 0.02)
     self.assertEqual(test_order.orderHash, util.hexStringToBytes(
         "731319211689ccf0327911a0126b0af0854570c1b6cdfeb837b0127e29fe9fd5"
     ))
コード例 #4
0
ファイル: order_test.py プロジェクト: zincoshine/openrelay
 def test_order_from_bytes(self):
     test_order = order.Order.FromBytes(sample.data)
     self.assertEqual(test_order.price, 0.02)
     self.assertEqual(
         test_order.orderHash,
         util.hexStringToBytes(
             "731319211689ccf0327911a0126b0af0854570c1b6cdfeb837b0127e29fe9fd5"
         ))
コード例 #5
0
ファイル: api.py プロジェクト: radek1st/openrelay
def single_order(order_hash):
    order = dynamo.DynamoOrder.get(util.hexStringToBytes(order_hash))
    accept = request.headers.get("Accept", "")
    if "application/octet-stream" in accept:
        resp = make_response(order.binary())
        resp.headers["Content-Type"] = "application/octet-stream"
    else:
        resp = make_response(json.dumps(order.ToOrder().to_dict()))
        resp.headers["Content-Type"] = "application/json"
    return resp
コード例 #6
0
ファイル: fill_indexer.py プロジェクト: zincoshine/openrelay
def process_fill(fill, locker):
    orderHash = util.hexStringToBytes(fill["orderHash"])
    dynamo_order = dynamo.DynamoOrder.addFilled(
        orderHash,
        int(fill.get("filledTakerTokenAmount", 0)),
        int(fill.get("cancelledTakerTokenAmount", 0)),
        locker
    )
    order = dynamo_order.ToOrder()
    total_unavailable = (
        util.bytesToInt(dynamo_order.takerTokenAmountFilled) +
        util.bytesToInt(dynamo_order.takerTokenAmountCancelled)
    )
    if total_unavailable >= (order.takerTokenAmount * .99):
        # The order is > 99% filled, delist it.
        dynamo_order.delete()
コード例 #7
0
ファイル: api.py プロジェクト: radek1st/openrelay
def taker_token_search(taker_token):
    count = int(request.args.get("count", 25))
    orders = dynamo.DynamoOrder.takertoken_index.query(
        util.hexStringToBytes(taker_token), limit=count)
    return format_response(orders, count, request.headers.get("Accept", ""))
コード例 #8
0
import util

data = util.hexStringToBytes(
    "90fe2af704b34e0224bf2299c838e04d4dcf1364324454186bb728a3ea55750e0"
    "618ff1b18ce6cf800000000000000000000000000000000000000001dad4783cf"
    "3fe3085c1426157ab175a6119a04ba05d090b51c40b020eab3bfcb6a2dff130df"
    "22e9c000000000000000000000000000000000000000000000000000000000000"
    "0000000000000000000000000002b5e3af16b1880000000000000000000000000"
    "0000000000000000000000000000de0b6b3a76400000000000000000000000000"
    "00000000000000000000000000000000000000000000000000000000000000000"
    "00000000000000000000000000000000000000000000000000000000000000000"
    "0000000000000000000000000000000059938ac4000643508ff7019bfb134363a"
    "86e98746f6c33262e68daf992b8df064217222b1b021fe6dba378a347ea5c581a"
    "dcd0e0e454e9245703d197075f5d037d0935ac2e12ac107cb04be663f54239483"
    "2bbcb348deda8b5aa393a97a4cc3139501007f1")

samples = [
    util.hexStringToBytes(
        '5409ed021d9299bf6814279a6a1411a7e866a63100000000000000000000000000000'
        '00000000000423233c6754bc02430551e763074856b54e9348ef940fcea9408917e7b'
        '131084fa32868f9022465bc22d5b2951db72b44cfb8089bb8cd374a3c354eab69e673'
        '309512a9d726f87304c6984054f87a93b000000000000000000000000000000000000'
        '000000000000000000000000271000000000000000000000000000000000000000000'
        '000000000000000000027100000000000000000000000000000000000000000000000'
        '0003782dace9d90000000000000000000000000000000000000000000000000000037'
        '82dace9d9000000000000000000000000000000000000000000000000000000000000'
        '59b5eea323ba7a7ab09492366890b0ffcc652e52c88347dc5bc7a516279b58f118196'
        '87f0043fe83e2ea97e3aedabd83bbf38a076952c8f3c8f1648ea7a10396fb68be062d'
        '32855f92d14acae57b2fe3449d3fc5bb8a9860c9dffca35a4848540300fd9647'),
    util.hexStringToBytes(
        '5409ed021d9299bf6814279a6a1411a7e866a63100000000000000000000000000000'