Skip to content

Commit

Permalink
Better funding response
Browse files Browse the repository at this point in the history
  • Loading branch information
MaticConradi committed Jun 3, 2022
1 parent 028fa72 commit 00b5c28
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
20 changes: 2 additions & 18 deletions app/components/ccxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,6 @@ def request_lld(cls, request):
fundingDate = datetime.strptime(rawData["fundingTimestamp"], "%Y-%m-%dT%H:%M:00.000Z").replace(tzinfo=utc)
else:
fundingDate = datetime.now().replace(tzinfo=utc)
indicativeFundingTimestamp = datetime.timestamp(fundingDate) + 28800
indicativeFundingDate = datetime.utcfromtimestamp(indicativeFundingTimestamp).replace(tzinfo=utc)
deltaFunding = fundingDate - datetime.now().astimezone(utc)
deltaIndicative = indicativeFundingDate - datetime.now().astimezone(utc)

hours1, seconds1 = divmod(deltaFunding.days * 86400 + deltaFunding.seconds, 3600)
minutes1 = int(seconds1 / 60)
hoursFunding = "{:d} {} ".format(hours1, "hours" if hours1 > 1 else "hour") if hours1 > 0 else ""
minutesFunding = "{:d} {}".format(minutes1 if hours1 > 0 or minutes1 > 0 else seconds1, ("minute" if minutes1 == 1 else "minutes") if hours1 > 0 or minutes1 > 0 else ("second" if seconds1 == 1 else "seconds"))
deltaFundingText = f"{hoursFunding}{minutesFunding}"

hours2, seconds2 = divmod(deltaIndicative.days * 86400 + deltaIndicative.seconds, 3600)
minutes2 = int(seconds2 / 60)
hoursIndicative = "{:d} {} ".format(hours2, "hours" if hours2 > 1 else "hour") if hours2 > 0 else ""
minutesIndicative = "{:d} {}".format(minutes2 if hours2 > 0 or minutes2 > 0 else seconds2, ("minute" if minutes2 == 1 else "minutes") if hours2 > 0 or minutes2 > 0 else ("second" if seconds2 == 1 else "seconds"))
deltaIndicativeText = f"{hoursIndicative}{minutesIndicative}"

fundingRate = float(rawData["fundingRate"]) * 100
predictedFundingRate = float(rawData["indicativeFundingRate"]) * 100
Expand All @@ -135,9 +119,9 @@ def request_lld(cls, request):

payload = {
"quotePrice": "Funding Rate: {:+.4f} %".format(fundingRate),
"quoteConvertedPrice": "Predicted Rate: {:+.4f} % *(in {})*".format(predictedFundingRate, deltaIndicativeText),
"quoteConvertedPrice": "Predicted Rate: {:+.4f} %".format(predictedFundingRate),
"title": ticker.get("name"),
"change": f"in {deltaFundingText}",
"change": f"<t:{datetime.timestamp(fundingDate)}:R>",
"thumbnailUrl": coinThumbnail,
"messageColor": "yellow" if averageFundingRate == 0.01 else ("light green" if averageFundingRate < 0.01 else "deep orange"),
"sourceText": f"Funding on {exchange.name}",
Expand Down
2 changes: 1 addition & 1 deletion build/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /usr/src/quote-server
COPY ./build/requirements.txt ./
RUN pip install -r ./requirements.txt

RUN git clone https://github.com/alphabotsystem/dependencies.git && cd ./dependencies && git checkout v1.4.0
RUN git clone https://github.com/alphabotsystem/dependencies.git && cd ./dependencies && git checkout v1.4.3
RUN pip install ./dependencies/py/parser
RUN rm -r ./dependencies

Expand Down

0 comments on commit 00b5c28

Please sign in to comment.