Example #1
0
def get_matching_orders(input_order):
    #  Same currency. Different Action (Buy/Sell)
    search_criteria_rate = {'currency' : input_order['currency']}
    search_criteria_rate['action'] = "Buy" if input_order['action'] == "Sell" else "Sell"
    search_criteria_rate['is_complete'] = 0
    search_criteria_market = copy.deepcopy(search_criteria_rate)
    search_criteria_rate['order_type'] = "For Price"
    search_criteria_market['order_type'] = "At Market"

    query_market = True
    quote   = c.get('currencies', input_order['currency'])
    rate    = input_order['rate']
    
    is_sell = input_order['action'] == "Sell"
    is_rate = input_order['order_type'] == "For Price"

    if not is_rate and quote['last_trade'] == -1:
        query_market = False

    if is_rate:
        search_criteria_rate['rate'] = GreaterEqual(rate) if is_sell else LessEqual(rate)
        if is_sell and rate > quote['lowest_sell_rate'] : query_market = False
        if not is_sell and rate < quote['highest_buy_rate'] : query_market = False
    else:
        # If it is a market order do not query the market_orders
        query_market = False

    # Get the search iterator over rate and market orders
    market_orders_itr = c.search('orders', search_criteria_market) if query_market else None
    rate_orders_itr   = c.search('orders', search_criteria_rate)
    # Fetch the actual records into memory
    market_orders     = [dict(row) for row in market_orders_itr] if market_orders_itr is not None else []
    rate_orders       = [dict(row) for row in rate_orders_itr]
    return (rate_orders, market_orders, quote)
Example #2
0
import sys
import hyperdex.client
from hyperdex.client import LessEqual, GreaterEqual, Range, Regex, LengthEquals, LengthLessEqual, LengthGreaterEqual
c = hyperdex.client.Client(sys.argv[1], int(sys.argv[2]))


def to_objectset(xs):
    return set([frozenset(x.items()) for x in xs])


assert c.put('kv', -2, {'v': -2}) == True
assert c.put('kv', -1, {'v': -1}) == True
assert c.put('kv', 0, {'v': 0}) == True
assert c.put('kv', 1, {'v': 1}) == True
assert c.put('kv', 2, {'v': 2}) == True
assert to_objectset(c.search('kv', {'k': LessEqual(0)})) == to_objectset([{
    'k':
    -2,
    'v':
    -2
}, {
    'k':
    -1,
    'v':
    -1
}, {
    'k':
    0,
    'v':
    0
}])
Example #3
0
#!/usr/bin/env python
import sys
import hyperdex.client
from hyperdex.client import LessEqual, GreaterEqual, Range, Regex, LengthEquals, LengthLessEqual, LengthGreaterEqual
c = hyperdex.client.Client(sys.argv[1], int(sys.argv[2]))
def to_objectset(xs):
    return set([frozenset(x.items()) for x in xs])
assert c.put('kv', 'A', {'v': 'A'}) == True
assert c.put('kv', 'B', {'v': 'B'}) == True
assert c.put('kv', 'C', {'v': 'C'}) == True
assert c.put('kv', 'D', {'v': 'D'}) == True
assert c.put('kv', 'E', {'v': 'E'}) == True
assert to_objectset(c.search('kv', {'k': LessEqual('C')})) == to_objectset([{'k': 'A', 'v': 'A'}, {'k': 'B', 'v': 'B'}, {'k': 'C', 'v': 'C'}])
assert to_objectset(c.search('kv', {'v': LessEqual('C')})) == to_objectset([{'k': 'A', 'v': 'A'}, {'k': 'B', 'v': 'B'}, {'k': 'C', 'v': 'C'}])
assert to_objectset(c.search('kv', {'k': GreaterEqual('C')})) == to_objectset([{'k': 'C', 'v': 'C'}, {'k': 'D', 'v': 'D'}, {'k': 'E', 'v': 'E'}])
assert to_objectset(c.search('kv', {'v': GreaterEqual('C')})) == to_objectset([{'k': 'C', 'v': 'C'}, {'k': 'D', 'v': 'D'}, {'k': 'E', 'v': 'E'}])
assert to_objectset(c.search('kv', {'k': Range('B', 'D')})) == to_objectset([{'k': 'B', 'v': 'B'}, {'k': 'C', 'v': 'C'}, {'k': 'D', 'v': 'D'}])
assert to_objectset(c.search('kv', {'v': Range('B', 'D')})) == to_objectset([{'k': 'B', 'v': 'B'}, {'k': 'C', 'v': 'C'}, {'k': 'D', 'v': 'D'}])