golosscripts.feed

Module Contents

log[source]
bitshares_markets = ['RUDEX.GOLOS/GPH', 'RUDEX.GOLOS/RUDEX.BTC', 'RUDEX.GOLOS/RUDEX.USDT'][source]
market_data[source]
class PriceSource[source]

Bases: enum.Enum

graphene = 1[source]
kuna = 2[source]
class Metric[source]

Bases: enum.Enum

median = 1[source]
mean = 2[source]
weighted_average = 3[source]
class FeedUpdater(node: Union[str, List[str]], keys: Union[str, List[str]], witness: str, dry_run: bool = False, source: str = 'graphene', node_gph: Optional[Union[str, List[str]]] = None, markets: Optional[List[str]] = None, metric: str = 'weighted_average', depth_pct: float = 20.0, threshold_pct: float = 10.0, interval: int = 3600, k: float = 1.0, max_age: int = 86400)[source]

Bases: golosscripts.golos_helper.GolosHelper

This class is used to calculate and update ‘sbd_exchange_rate’ for witness.

Parameters
  • node (str,list) – golos node to connect to

  • keys (str,list) – witness active keys

  • witness (str) – witness name to update feed for

  • dry_run (bool) – only do price calculation without sending transaction

  • node_gph (str,list) – graphene node

  • markets (list) – list of bitshares markets to use to obtain price, in format [‘QUOTE/BASE’]

  • metric (str) – what metric to use to calculate price

  • depth_pct (float) – how deeply measure market for volume

  • threshold_pct (float) – price change threshold to trigger price feed publish

  • interval (int) – how often calculate new price

  • k (float) – correction coefficient, adjusts price up or down

  • max_age (int) – max age of price feed to trigger force-publish

static calc_weighted_average_price(prices: List[market_data])[source]

Calculate weighted average price using “volume” key.

Parameters

prices (list) – list of market_data tuples

static is_last_price_too_old(witness_data: Witness, max_age: int)[source]

Check last price update time and return True if older than max_age.

Parameters
  • witness_data – witness object dict, usually golos.witness.Witness Witness instance

  • max_age (int) – max seconds since last update

async calc_price_gph_golos(self)[source]

Calculate price GPH/GOLOS using GOLOS markets on bitshares.

async calc_price_gbg_golos_bitshares(self)[source]

Calculate price GBG/GOLOS using GOLOS markets on bitshares.

async calc_price_kuna(self)[source]

Calculate price GBG/GOLOS using kuna.io GOL ticker.

async publish_price(self, force: bool = False)[source]

Publish price feed once.

Parameters

force (bool) – force-publish price even if update is not needed

async run_forever(self)[source]

Run in continuous mode to make price feed updates periodically.

Example for python 3.7+:

feed_updater = FeedUpdater()
asyncio.run(feed_updater.run_forever())