Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import logging

import pendulum
from polygon import (
RESTClient,
)

from minos.aggregate import (
Event,
)
Expand All @@ -15,7 +19,6 @@
from ..aggregates import (
StocksAggregate,
)
from polygon import RESTClient

logger = logging.getLogger(__name__)

Expand All @@ -31,8 +34,9 @@ async def set_stock_ticker(self, request: Request):

def call_remote(self, ticker, from_: str, to_: str):
with RESTClient("") as client:
resp = client.stocks_equities_aggregates(ticker, 1, "hour", from_, to_, adjusted=True, sort="asc",
limit=50000)
resp = client.stocks_equities_aggregates(
ticker, 1, "hour", from_, to_, adjusted=True, sort="asc", limit=50000
)
return resp.results

@enroute.periodic.event("* * * * *")
Expand All @@ -43,16 +47,15 @@ async def get_stock_values(self, request: Request):
if len(tickers) > 0:
for ticker in tickers:
ticker_updated = pendulum.parse(ticker["updated"])
results = await self.call_remote(ticker["ticker"],
now_minus_one_month.to_date_string(),
now.to_date_string())
results = await self.call_remote(
ticker["ticker"], now_minus_one_month.to_date_string(), now.to_date_string()
)
for result in results:
result_date = pendulum.parse(result["t"])
difference_ticker_result = ticker_updated.diff(result_date).in_hours()
if difference_ticker_result < 0:
await StocksAggregate.update_time_ticker(ticker["uuid"], result_date.to_datetime_string())
when = result_date.to_datetime_string()
await StocksAggregate.add_quotes(ticker["uuid"], {"close": result['c'],
"volume": result['v'],
"when": when})

await StocksAggregate.add_quotes(
ticker["uuid"], {"close": result["c"], "volume": result["v"], "when": when}
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import unittest

import pendulum

from src import (
Stocks,
StocksCommandService,
Expand Down Expand Up @@ -39,6 +38,5 @@ async def test_get_remote_quotes(self):
self.assertIsInstance(response, list)



if __name__ == "__main__":
unittest.main()