|
3 | 3 | import grpc |
4 | 4 | import pytest |
5 | 5 |
|
| 6 | +from pyinjective.async_client_v2 import AsyncClient |
6 | 7 | from pyinjective.client.chain.grpc.chain_grpc_exchange_v2_api import ChainGrpcExchangeV2Api |
7 | 8 | from pyinjective.client.model.pagination import PaginationOption |
8 | 9 | from pyinjective.core.network import DisabledCookieAssistant, Network |
@@ -72,6 +73,7 @@ async def test_fetch_exchange_params( |
72 | 73 | deprecated_enforced_restrictions_contracts=[], |
73 | 74 | white_knight_liquidators=white_knight_liquidators, |
74 | 75 | white_knight_liquidator_reward_share_rate="0.050000000000000000", |
| 76 | + min_expiry_futures_market_duration_seconds=3600, |
75 | 77 | ) |
76 | 78 | exchange_servicer.exchange_params.append(exchange_query_pb.QueryExchangeParamsResponse(params=params)) |
77 | 79 |
|
@@ -130,6 +132,7 @@ async def test_fetch_exchange_params( |
130 | 132 | "deprecatedEnforcedRestrictionsContracts": params.deprecated_enforced_restrictions_contracts, |
131 | 133 | "whiteKnightLiquidators": params.white_knight_liquidators, |
132 | 134 | "whiteKnightLiquidatorRewardShareRate": params.white_knight_liquidator_reward_share_rate, |
| 135 | + "minExpiryFuturesMarketDurationSeconds": str(params.min_expiry_futures_market_duration_seconds), |
133 | 136 | } |
134 | 137 | } |
135 | 138 |
|
@@ -1290,18 +1293,23 @@ async def test_fetch_derivative_markets( |
1290 | 1293 | open_notional_cap=open_notional_cap, |
1291 | 1294 | has_disabled_minimal_protocol_fee=False, |
1292 | 1295 | cross_margin_eligible=False, |
| 1296 | + synthetic_trade_fee_rate="1000000000000000", |
1293 | 1297 | ) |
1294 | 1298 | market_info = market_pb.PerpetualMarketInfo( |
1295 | 1299 | market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", |
1296 | 1300 | hourly_funding_rate_cap="625000000000000", |
1297 | 1301 | hourly_interest_rate="4166660000000", |
1298 | 1302 | next_funding_timestamp=1708099200, |
1299 | 1303 | funding_interval=3600, |
| 1304 | + funding_impact_notional="1000000000000000000000", |
1300 | 1305 | ) |
1301 | 1306 | funding_info = market_pb.PerpetualMarketFunding( |
1302 | 1307 | cumulative_funding="-107853477278881692857461", |
1303 | 1308 | cumulative_price="0", |
1304 | 1309 | last_timestamp=1708099200, |
| 1310 | + period_start=1708095600, |
| 1311 | + last_premium="100000000000000", |
| 1312 | + last_sample_timestamp=1708099140, |
1305 | 1313 | ) |
1306 | 1314 | perpetual_info = exchange_query_pb.PerpetualMarketState( |
1307 | 1315 | market_info=market_info, |
@@ -1361,6 +1369,7 @@ async def test_fetch_derivative_markets( |
1361 | 1369 | }, |
1362 | 1370 | "hasDisabledMinimalProtocolFee": market.has_disabled_minimal_protocol_fee, |
1363 | 1371 | "crossMarginEligible": market.cross_margin_eligible, |
| 1372 | + "syntheticTradeFeeRate": market.synthetic_trade_fee_rate, |
1364 | 1373 | }, |
1365 | 1374 | "perpetualInfo": { |
1366 | 1375 | "marketInfo": { |
@@ -1369,11 +1378,15 @@ async def test_fetch_derivative_markets( |
1369 | 1378 | "hourlyInterestRate": market_info.hourly_interest_rate, |
1370 | 1379 | "nextFundingTimestamp": str(market_info.next_funding_timestamp), |
1371 | 1380 | "fundingInterval": str(market_info.funding_interval), |
| 1381 | + "fundingImpactNotional": market_info.funding_impact_notional, |
1372 | 1382 | }, |
1373 | 1383 | "fundingInfo": { |
1374 | 1384 | "cumulativeFunding": funding_info.cumulative_funding, |
1375 | 1385 | "cumulativePrice": funding_info.cumulative_price, |
1376 | 1386 | "lastTimestamp": str(funding_info.last_timestamp), |
| 1387 | + "periodStart": str(funding_info.period_start), |
| 1388 | + "lastPremium": funding_info.last_premium, |
| 1389 | + "lastSampleTimestamp": str(funding_info.last_sample_timestamp), |
1377 | 1390 | }, |
1378 | 1391 | }, |
1379 | 1392 | "markPrice": full_market.mark_price, |
@@ -1417,18 +1430,23 @@ async def test_fetch_derivative_market( |
1417 | 1430 | quote_decimals=6, |
1418 | 1431 | has_disabled_minimal_protocol_fee=False, |
1419 | 1432 | cross_margin_eligible=False, |
| 1433 | + synthetic_trade_fee_rate="1000000000000000", |
1420 | 1434 | ) |
1421 | 1435 | market_info = market_pb.PerpetualMarketInfo( |
1422 | 1436 | market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", |
1423 | 1437 | hourly_funding_rate_cap="625000000000000", |
1424 | 1438 | hourly_interest_rate="4166660000000", |
1425 | 1439 | next_funding_timestamp=1708099200, |
1426 | 1440 | funding_interval=3600, |
| 1441 | + funding_impact_notional="1000000000000000000000", |
1427 | 1442 | ) |
1428 | 1443 | funding_info = market_pb.PerpetualMarketFunding( |
1429 | 1444 | cumulative_funding="-107853477278881692857461", |
1430 | 1445 | cumulative_price="0", |
1431 | 1446 | last_timestamp=1708099200, |
| 1447 | + period_start=1708095600, |
| 1448 | + last_premium="100000000000000", |
| 1449 | + last_sample_timestamp=1708099140, |
1432 | 1450 | ) |
1433 | 1451 | perpetual_info = exchange_query_pb.PerpetualMarketState( |
1434 | 1452 | market_info=market_info, |
@@ -1483,6 +1501,7 @@ async def test_fetch_derivative_market( |
1483 | 1501 | "quoteDecimals": market.quote_decimals, |
1484 | 1502 | "hasDisabledMinimalProtocolFee": market.has_disabled_minimal_protocol_fee, |
1485 | 1503 | "crossMarginEligible": market.cross_margin_eligible, |
| 1504 | + "syntheticTradeFeeRate": market.synthetic_trade_fee_rate, |
1486 | 1505 | }, |
1487 | 1506 | "perpetualInfo": { |
1488 | 1507 | "marketInfo": { |
@@ -1491,11 +1510,15 @@ async def test_fetch_derivative_market( |
1491 | 1510 | "hourlyInterestRate": market_info.hourly_interest_rate, |
1492 | 1511 | "nextFundingTimestamp": str(market_info.next_funding_timestamp), |
1493 | 1512 | "fundingInterval": str(market_info.funding_interval), |
| 1513 | + "fundingImpactNotional": market_info.funding_impact_notional, |
1494 | 1514 | }, |
1495 | 1515 | "fundingInfo": { |
1496 | 1516 | "cumulativeFunding": funding_info.cumulative_funding, |
1497 | 1517 | "cumulativePrice": funding_info.cumulative_price, |
1498 | 1518 | "lastTimestamp": str(funding_info.last_timestamp), |
| 1519 | + "periodStart": str(funding_info.period_start), |
| 1520 | + "lastPremium": funding_info.last_premium, |
| 1521 | + "lastSampleTimestamp": str(funding_info.last_sample_timestamp), |
1499 | 1522 | }, |
1500 | 1523 | }, |
1501 | 1524 | "markPrice": full_market.mark_price, |
@@ -1769,6 +1792,7 @@ async def test_fetch_perpetual_market_info( |
1769 | 1792 | hourly_interest_rate="4166660000000", |
1770 | 1793 | next_funding_timestamp=1708099200, |
1771 | 1794 | funding_interval=3600, |
| 1795 | + funding_impact_notional="1000000000000000000000", |
1772 | 1796 | ) |
1773 | 1797 | exchange_servicer.perpetual_market_info_responses.append( |
1774 | 1798 | exchange_query_pb.QueryPerpetualMarketInfoResponse(info=perpetual_market_info) |
@@ -1784,6 +1808,7 @@ async def test_fetch_perpetual_market_info( |
1784 | 1808 | "hourlyInterestRate": perpetual_market_info.hourly_interest_rate, |
1785 | 1809 | "nextFundingTimestamp": str(perpetual_market_info.next_funding_timestamp), |
1786 | 1810 | "fundingInterval": str(perpetual_market_info.funding_interval), |
| 1811 | + "fundingImpactNotional": perpetual_market_info.funding_impact_notional, |
1787 | 1812 | } |
1788 | 1813 | } |
1789 | 1814 |
|
@@ -1837,6 +1862,9 @@ async def test_fetch_perpetual_market_funding( |
1837 | 1862 | cumulative_funding="-107853477278881692857461", |
1838 | 1863 | cumulative_price="0", |
1839 | 1864 | last_timestamp=1708099200, |
| 1865 | + period_start=1708095600, |
| 1866 | + last_premium="100000000000000", |
| 1867 | + last_sample_timestamp=1708099140, |
1840 | 1868 | ) |
1841 | 1869 | exchange_servicer.perpetual_market_funding_responses.append( |
1842 | 1870 | exchange_query_pb.QueryPerpetualMarketFundingResponse(state=perpetual_market_funding) |
@@ -1852,6 +1880,9 @@ async def test_fetch_perpetual_market_funding( |
1852 | 1880 | "cumulativeFunding": perpetual_market_funding.cumulative_funding, |
1853 | 1881 | "cumulativePrice": perpetual_market_funding.cumulative_price, |
1854 | 1882 | "lastTimestamp": str(perpetual_market_funding.last_timestamp), |
| 1883 | + "periodStart": str(perpetual_market_funding.period_start), |
| 1884 | + "lastPremium": perpetual_market_funding.last_premium, |
| 1885 | + "lastSampleTimestamp": str(perpetual_market_funding.last_sample_timestamp), |
1855 | 1886 | } |
1856 | 1887 | } |
1857 | 1888 |
|
@@ -2240,34 +2271,26 @@ async def test_fetch_fee_discount_tier_statistics( |
2240 | 2271 |
|
2241 | 2272 | assert statistics == expected_statistics |
2242 | 2273 |
|
2243 | | - @pytest.mark.asyncio |
2244 | | - async def test_fetch_mito_vault_infos( |
2245 | | - self, |
2246 | | - exchange_servicer, |
2247 | | - ): |
2248 | | - master_address = "inj1zlh5sqevkfphtwnu9cul8p89vseme2eqt0snn9" |
2249 | | - derivative_address = "inj1zlh5" |
2250 | | - spot_address = "inj1zlh6" |
2251 | | - cw20_address = "inj1zlh7" |
2252 | | - response = exchange_query_pb.MitoVaultInfosResponse( |
2253 | | - master_addresses=[master_address], |
2254 | | - derivative_addresses=[derivative_address], |
2255 | | - spot_addresses=[spot_address], |
2256 | | - cw20_addresses=[cw20_address], |
2257 | | - ) |
2258 | | - exchange_servicer.mito_vault_infos_responses.append(response) |
| 2274 | + def test_mito_vault_info_types_remain_serializable(self): |
| 2275 | + request = exchange_query_pb.MitoVaultInfosRequest.FromString(b"") |
| 2276 | + assert request.SerializeToString() == b"" |
2259 | 2277 |
|
2260 | | - api = self._api_instance(servicer=exchange_servicer) |
| 2278 | + payload = b"\n\x06master\x12\x0aderivative\x1a\x04spot\x22\x04cw20" |
| 2279 | + response = exchange_query_pb.MitoVaultInfosResponse.FromString(payload) |
| 2280 | + assert response == exchange_query_pb.MitoVaultInfosResponse( |
| 2281 | + master_addresses=["master"], |
| 2282 | + derivative_addresses=["derivative"], |
| 2283 | + spot_addresses=["spot"], |
| 2284 | + cw20_addresses=["cw20"], |
| 2285 | + ) |
| 2286 | + assert response.SerializeToString() == payload |
2261 | 2287 |
|
2262 | | - mito_vaults = await api.fetch_mito_vault_infos() |
2263 | | - expected_mito_vaults = { |
2264 | | - "masterAddresses": [master_address], |
2265 | | - "derivativeAddresses": [derivative_address], |
2266 | | - "spotAddresses": [spot_address], |
2267 | | - "cw20Addresses": [cw20_address], |
2268 | | - } |
| 2288 | + @pytest.mark.parametrize("client_type", [ChainGrpcExchangeV2Api, AsyncClient]) |
| 2289 | + def test_fetch_mito_vault_infos_is_unavailable(self, client_type): |
| 2290 | + with pytest.raises(AttributeError, match="fetch_mito_vault_infos"): |
| 2291 | + getattr(client_type, "fetch_mito_vault_infos") |
2269 | 2292 |
|
2270 | | - assert mito_vaults == expected_mito_vaults |
| 2293 | + assert "MitoVaultInfos" not in exchange_query_pb.DESCRIPTOR.services_by_name["Query"].methods_by_name |
2271 | 2294 |
|
2272 | 2295 | @pytest.mark.asyncio |
2273 | 2296 | async def test_fetch_market_id_from_vault( |
|