Skip to content

Service Modes

Chris Priest edited this page Nov 7, 2017 · 1 revision

Finer control via "service modes"

Since all cryptocurrencies are open source, many of them have multiple instances of block explorers running for public consumption. These multiple services can be utilized in various ways to gain various advantages.

Each blockchain function's high level API function call accepts additional mode arguments.

  • random - This method will randomize all sources so it doesn't always call the best service.

  • paranoid - Integer 2 or greater - Paranoid mode means multiple services will be checked and a result will only be returned if all services agree. The number passed in is the number of services contacted. Default is 1.

  • average - Integer 2 or greater. This mode will call the external service multiple times and then return the average of returned results. Only applicable for functions that return a single numerical value, such as current_price, and get_optimal_fee. For instance, if you all get_current_price with average=4, 4 different services will be called to get current price, the results will be averaged, and returned.

  • verbose - True or False - If set to true, there will be extra debugging output

  • private - Integer greater than 0. This mode is only applicable to endpoints that take multiple addresses, (or a single extended public key). This will use a single service for each address. The number passed in corresponds to the amount of seconds each of the external calls will be spread out over. For instance, if you have 10 addresses you want the balance for, you use mode private=4 it will make those 10 different calls to 10 different services (chosen at random), and will spread them out over a 4 second period. Currently this mode can not be used in tandem with average an paranoid modes.

>>> from moneywagon import get_address_balance
>>> get_address_balance('btc', '1HWpyFJ7N6rvFkq3ZCMiFnqM6hviNFmG5X', paranoid=2, random=True)
0.0002

In the above example, two calls will be made to two different services. One goes to the first address balance service defined for BTC, and then another call will be made to the second defined address balance service. In the case of the BTC currency, the first and second services are BlockCypher and Blockr. To see which services are programmed to which currencies, refer to the crypto_data module.

You can also pass in an explicit set of services:

>>> from moneywagon import get_address_balance
>>> from moneywagon.services import Toshi, BlockchainInfo
>>> s = [Toshi, BlockchainInfo]
>>> get_address_balance('btc', '1HWpyFJ7N6rvFkq3ZCMiFnqM6hviNFmG5X', services=s, random=True)
0.0002

In this example, one single call will be made to either Blockchain.info or Toshi (chosen at random). If one of those services happens to be down at the moment, then the other one will be called and its value returned.

Clone this wiki locally