-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from NibiruChain/jc/pf
Added pricefeed module
- Loading branch information
Showing
17 changed files
with
262 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .dex import Dex # noqa | ||
from .perp import Perp # noqa | ||
from .pricefeed import Pricefeed # noqa | ||
from .vpool import VPool # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from grpc import Channel | ||
|
||
from nibiru.proto.pricefeed import query_pb2 as pf_type | ||
from nibiru.proto.pricefeed import query_pb2_grpc as pf_query | ||
|
||
from .util import deserialize | ||
|
||
|
||
class Pricefeed: | ||
""" | ||
Pricefeed allows to query the endpoints made available by the Nibiru Chain's Pricefeed module. | ||
""" | ||
|
||
def __init__(self, channel: Channel): | ||
self.api = pf_query.QueryStub(channel) | ||
|
||
def params(self): | ||
req = pf_type.QueryParamsRequest() | ||
return deserialize(self.api.QueryParams(req)) | ||
|
||
def price(self, pair_id: str): | ||
req = pf_type.QueryPriceRequest( | ||
pair_id=pair_id, | ||
) | ||
return deserialize(self.api.QueryPrice(req)) | ||
|
||
def prices(self): | ||
req = pf_type.QueryPricesRequest() | ||
return deserialize(self.api.QueryPrices(req)) | ||
|
||
def raw_prices(self, pair_id: str): | ||
req = pf_type.QueryRawPricesRequest( | ||
pair_id=pair_id, | ||
) | ||
return deserialize(self.api.QueryRawPrices(req)) | ||
|
||
def oracles(self, pair_id: str): | ||
req = pf_type.QueryOraclesRequest( | ||
pair_id=pair_id, | ||
) | ||
return deserialize(self.api.QueryOracles(req)) | ||
|
||
def markets(self): | ||
req = pf_type.QueryMarketsRequest() | ||
return deserialize(self.api.QueryMarkets(req)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .dex import Dex # noqa | ||
from .perp import Perp # noqa | ||
from .pricefeed import Pricefeed # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from datetime import datetime | ||
|
||
from nibiru import utils | ||
from nibiru.proto.pricefeed import tx_pb2 as pb | ||
|
||
|
||
class Pricefeed: | ||
@staticmethod | ||
def post_price(oracle: str, token0: str, token1: str, price: float, expiry: datetime): | ||
price_dec = utils.float_to_sdkdec(price) | ||
return pb.MsgPostPrice( | ||
oracle=oracle, | ||
token0=token0, | ||
token1=token1, | ||
price=price_dec, | ||
expiry=utils.toTsPb(expiry), | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.