Esempio n. 1
0
class PriceProvider:
    log = logging.getLogger()
    precision = 10**18

    def __init__(self, connection_manager, contract_address=None):

        network = connection_manager.network
        app_mode = connection_manager.options['networks'][network]['app_mode']

        if app_mode == "RRC20":
            self.contract_MoC = RDOCMoC(connection_manager,
                                        contract_address=contract_address,
                                        contracts_discovery=True)
        else:
            self.contract_MoC = MoC(connection_manager,
                                    contract_address=contract_address,
                                    contracts_discovery=True)

        if network in [
                'mocTestnetAlpha', 'mocTestnet', 'rdocTestnetAlpha',
                'rdocTestnet'
        ]:
            self.sc_Price_Provider = CoinPairPrice(
                connection_manager,
                contract_address=self.contract_MoC.sc_moc_state.price_provider(
                ))
        else:
            if app_mode == "RRC20":
                self.sc_Price_Provider = MoCMedianizer(
                    connection_manager,
                    contract_address=self.contract_MoC.sc_moc_state.
                    price_provider())
            else:
                self.sc_Price_Provider = RDOCMoCMedianizer(
                    connection_manager,
                    contract_address=self.contract_MoC.sc_moc_state.
                    price_provider())

    def price(self,
              formatted: bool = True,
              block_identifier: BlockIdentifier = 'latest'):
        """Get price"""

        result = self.sc_Price_Provider.price(
            formatted=formatted, block_identifier=block_identifier)

        return result
Esempio n. 2
0
Oracle price get current oracle from MOC
"""

from moneyonchain.manager import ConnectionManager
from moneyonchain.rdoc import RDOCMoC
from moneyonchain.rdoc import RDOCMoCMedianizer

# Network types
#
# rdocTestnet: Testnet
# rdocMainnet: Production Mainnet

network = 'rdocMainnet'
connection_manager = ConnectionManager(network=network)
print("Connecting to %s..." % network)
print(
    "Connected: {conectado}".format(conectado=connection_manager.is_connected))

print("Connecting to RDOC Main Contract")
moc_contract = RDOCMoC(connection_manager)

#oracle_provider = moc_contract.sc_moc_state.price_provider()
#print("Oracle address: {0}".format(oracle_provider))

#oracle_provider = '0x987ccC60c378a61d167B6DD1EEF7613c6f63938f'
#oracle_provider = '0xDC3551f16FfDeBAa3Cb8D3b6C16d2A5bB9646dA4'

#oracle = RDOCMoCMedianizer(connection_manager, contract_address=oracle_provider)
oracle = RDOCMoCMedianizer(connection_manager)
print("RIF Price in USD: {0}".format(oracle.price()))