Skip to content

Commit

Permalink
Merge pull request hummingbot#6940 from yancong001/fix/next_funding_u…
Browse files Browse the repository at this point in the history
…tc_timestamp

Fix/update binance&okx nextFundingTime to 10-bit integer
  • Loading branch information
cardosofede authored Apr 1, 2024
2 parents e01ed79 + f7a7da3 commit 8977bff
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def get_funding_info(self, trading_pair: str) -> FundingInfo:
trading_pair=trading_pair,
index_price=Decimal(symbol_info["indexPrice"]),
mark_price=Decimal(symbol_info["markPrice"]),
next_funding_utc_timestamp=int(symbol_info["nextFundingTime"]),
next_funding_utc_timestamp=int(float(symbol_info["nextFundingTime"]) * 1e-3),
rate=Decimal(symbol_info["lastFundingRate"]),
)
return funding_info
Expand Down Expand Up @@ -189,7 +189,7 @@ async def _parse_funding_info_message(self, raw_message: Dict[str, Any], message
trading_pair=trading_pair,
index_price=Decimal(data["i"]),
mark_price=Decimal(data["p"]),
next_funding_utc_timestamp=int(data["T"]),
next_funding_utc_timestamp=int(float(data["T"]) * 1e-3),
rate=Decimal(data["r"]),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def get_funding_info(self, trading_pair: str) -> FundingInfo:
trading_pair=trading_pair,
index_price=Decimal(str(index_price["idxPx"])),
mark_price=Decimal(str(mark_price["markPx"])),
next_funding_utc_timestamp=int(funding_data["nextFundingTime"]),
next_funding_utc_timestamp=int(float(funding_data["nextFundingTime"]) * 1e-3),
rate=Decimal(str(funding_data["fundingRate"])),
)
return funding_info
Expand Down Expand Up @@ -385,7 +385,7 @@ async def _parse_funding_info_message(self, raw_message: Dict[str, Any], message
symbol = raw_message["arg"]["instId"]
trading_pair = await self._connector.trading_pair_associated_to_exchange_symbol(symbol)
funding_data = raw_message["data"][0]
self._last_next_funding_utc_timestamp = int(funding_data["nextFundingTime"])
self._last_next_funding_utc_timestamp = int(float(funding_data["nextFundingTime"]) * 1e-3)
self._last_rate = (Decimal(str(funding_data["fundingRate"])))
info_update = FundingInfoUpdate(trading_pair=trading_pair,
index_price=self._last_index_price,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def test_get_funding_info_from_exchange_successful(self, mock_api):
self.assertEqual(result.trading_pair, self.trading_pair)
self.assertEqual(result.index_price, Decimal(mock_response["indexPrice"]))
self.assertEqual(result.mark_price, Decimal(mock_response["markPrice"]))
self.assertEqual(result.next_funding_utc_timestamp, mock_response["nextFundingTime"])
self.assertEqual(result.next_funding_utc_timestamp, int(mock_response["nextFundingTime"] * 1e-3))
self.assertEqual(result.rate, Decimal(mock_response["lastFundingRate"]))

@aioresponses()
Expand All @@ -256,7 +256,7 @@ def test_get_funding_info(self, mock_api):
self.assertEqual(result.trading_pair, self.trading_pair)
self.assertEqual(result.index_price, Decimal(mock_response["indexPrice"]))
self.assertEqual(result.mark_price, Decimal(mock_response["markPrice"]))
self.assertEqual(result.next_funding_utc_timestamp, mock_response["nextFundingTime"])
self.assertEqual(result.next_funding_utc_timestamp, int(mock_response["nextFundingTime"] * 1e-3))
self.assertEqual(result.rate, Decimal(mock_response["lastFundingRate"]))

@patch("aiohttp.ClientSession.ws_connect", new_callable=AsyncMock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def test_get_funding_info(self, mock_api):
self.assertEqual(self.trading_pair, funding_info.trading_pair)
self.assertEqual(Decimal(index_price_resp["data"][0]["idxPx"]), funding_info.index_price)
self.assertEqual(Decimal(mark_price_resp["data"][0]["markPx"]), funding_info.mark_price)
self.assertEqual(int(funding_info_resp["data"][0]["nextFundingTime"]), funding_info.next_funding_utc_timestamp)
self.assertEqual(int(float(funding_info_resp["data"][0]["nextFundingTime"]) * 1e-3), funding_info.next_funding_utc_timestamp)
self.assertEqual(Decimal(funding_info_resp["data"][0]["fundingRate"]), funding_info.rate)

@patch("aiohttp.ClientSession.ws_connect", new_callable=AsyncMock)
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def test_listen_for_funding_info_successful(self):

expected_last_index_price = -3
expected_last_mark_price = -3
update_next_funding_utc_timestamp = int(index_price_event["data"][0]["nextFundingTime"])
update_next_funding_utc_timestamp = int(float(index_price_event["data"][0]["nextFundingTime"]) * 1e-3)
update_rate = Decimal(index_price_event["data"][0]["fundingRate"])

self.data_source._last_mark_price = expected_last_mark_price
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def expected_supported_position_modes(self) -> List[PositionMode]:

@property
def target_funding_info_next_funding_utc_timestamp(self):
return 1657099053000
return 1657099053

@property
def target_funding_info_next_funding_utc_str(self):
Expand Down

0 comments on commit 8977bff

Please sign in to comment.