-
Notifications
You must be signed in to change notification settings - Fork 97
Conversation
044d7ac
to
70c1d12
Compare
With massive shouts to @JonathonDunford for previous digging.
70c1d12
to
a780949
Compare
a780949
to
0302356
Compare
return of the ticker LOL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most comments are for clarification. Nothing holding us back from pushing.
depends_on = None | ||
|
||
|
||
def upgrade(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks beautiful. Like something I would write :P
|
||
getcontext().prec = 8 | ||
|
||
# TODO: finally extract these into constants |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of these days, we will make this a constant
ZERO_ADDR_BYTES = Web3.toBytes(hexstr=ZERO_ADDR) | ||
|
||
tokens_queue = Queue() | ||
# TODO: Populate from our own DB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is pretty important. Is there any way to import it from the main config for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really.
WHERE ("token_give" = $2 OR "token_get" = $2) | ||
AND "date" >= NOW() - '1 day'::INTERVAL | ||
""", | ||
Web3.toBytes(hexstr=ZERO_ADDR), # TODO: We can probably do with just token address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is future proof allowing a secondary address to check against though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough!
|
||
async with App().db.acquire_connection() as conn: | ||
return await conn.fetchrow(""" | ||
SELECT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful. Has this SQL been tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, I've snuck it into production at this point, even.
spread = await get_market_spread(token_addr, current_block) | ||
if spread["ask"]: | ||
# Spread comes back in token/base native values, denormalize it here | ||
ticker_info["ask"] = spread["ask"] * base_contract.denormalize_value(1.0) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we multiplying by denormalized 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, we'd convert amount_get
and amount_give
and then compute the price; however, ask
and bid
returned by the DB are max/min prices for their respective sides of the orderbook, so we convert them to eth-values using this formula.
token = tokens_queue.get() | ||
await update_ticker(token) | ||
tokens_queue.put(token) | ||
await asyncio.sleep(2.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you arrive at 2 seconds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Update every ticker about every half hour", with N_tokens = 1000 gives us ~2 seconds, ignoring processing time. Open for updates and discussion though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we run multiple threads of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could. Do we need to?
app/services/websocket_server.py
Outdated
""") | ||
|
||
def ticker_key(ticker): | ||
return "{}_{}".format("ETH", Web3.toHex(ticker["token_address"])[:9]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a little comment saying what's going on here.
|
||
def format_tickers(tickers): | ||
return { | ||
ticker_key(ticker): format_ticker(ticker) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python voodoo magic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AKA magic
for ticker in tickers | ||
} | ||
|
||
@routes.get('/returnTicker') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOOH Http too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed!
See #3 and previous work in #18.
With massive shouts to @JonathonDunford for previous digging.