|
|
|
@ -4,7 +4,7 @@ from core.util import logs
|
|
|
|
|
|
|
|
|
|
log = logs.get_logger("db")
|
|
|
|
|
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0)
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0) # noqa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert(data):
|
|
|
|
@ -28,6 +28,7 @@ async def get_refs():
|
|
|
|
|
:return: list of trade IDs
|
|
|
|
|
:rtype: list
|
|
|
|
|
"""
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0)
|
|
|
|
|
references = []
|
|
|
|
|
ref_keys = await r.keys("trade.*.reference")
|
|
|
|
|
for key in ref_keys:
|
|
|
|
@ -44,6 +45,7 @@ async def tx_to_ref(tx):
|
|
|
|
|
:return: reference
|
|
|
|
|
:rtype: string
|
|
|
|
|
"""
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0)
|
|
|
|
|
refs = await get_refs()
|
|
|
|
|
for reference in refs:
|
|
|
|
|
ref_data = await r.hgetall(f"trade.{reference}")
|
|
|
|
@ -62,6 +64,7 @@ async def ref_to_tx(reference):
|
|
|
|
|
:return: trade ID
|
|
|
|
|
:rtype: string
|
|
|
|
|
"""
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0)
|
|
|
|
|
ref_data = convert(await r.hgetall(f"trade.{reference}"))
|
|
|
|
|
if not ref_data:
|
|
|
|
|
return False
|
|
|
|
@ -74,6 +77,7 @@ async def get_ref_map():
|
|
|
|
|
:return: dict of references keyed by TXID
|
|
|
|
|
:rtype: dict
|
|
|
|
|
"""
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0)
|
|
|
|
|
references = {}
|
|
|
|
|
ref_keys = await r.keys("trade.*.reference")
|
|
|
|
|
for key in ref_keys:
|
|
|
|
@ -90,6 +94,7 @@ async def get_ref(reference):
|
|
|
|
|
:return: dict of trade information
|
|
|
|
|
:rtype: dict
|
|
|
|
|
"""
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0)
|
|
|
|
|
ref_data = await r.hgetall(f"trade.{reference}")
|
|
|
|
|
ref_data = convert(ref_data)
|
|
|
|
|
if "subclass" not in ref_data:
|
|
|
|
@ -107,6 +112,7 @@ async def get_tx(tx):
|
|
|
|
|
:return: dict of trade information
|
|
|
|
|
:rtype: dict
|
|
|
|
|
"""
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0)
|
|
|
|
|
tx_data = await r.hgetall(f"tx.{tx}")
|
|
|
|
|
tx_data = convert(tx_data)
|
|
|
|
|
if not tx_data:
|
|
|
|
@ -115,6 +121,7 @@ async def get_tx(tx):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_subclass(reference):
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0)
|
|
|
|
|
obj = await r.hget(f"trade.{reference}", "subclass")
|
|
|
|
|
subclass = convert(obj)
|
|
|
|
|
return subclass
|
|
|
|
@ -126,6 +133,7 @@ async def del_ref(reference):
|
|
|
|
|
:param reference: trade reference to delete
|
|
|
|
|
:type reference: string
|
|
|
|
|
"""
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0)
|
|
|
|
|
tx = await ref_to_tx(reference)
|
|
|
|
|
await r.delete(f"trade.{reference}")
|
|
|
|
|
await r.delete(f"trade.{tx}.reference")
|
|
|
|
@ -138,6 +146,7 @@ async def cleanup(subclass, references):
|
|
|
|
|
:param references: list of references to reconcile against
|
|
|
|
|
:type references: list
|
|
|
|
|
"""
|
|
|
|
|
r = aioredis.from_url("redis://redis:6379", db=0)
|
|
|
|
|
messages = []
|
|
|
|
|
ref_map = await get_ref_map()
|
|
|
|
|
for tx, reference in ref_map.items():
|
|
|
|
|