forked from xeroc/bitshares-pricefeed
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test assets with formula, fix import issues and summary display.
- Loading branch information
Showing
6 changed files
with
71 additions
and
9 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
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,34 @@ | ||
import pytest | ||
import os | ||
import yaml | ||
import math | ||
|
||
@pytest.fixture | ||
def conf(request): | ||
confName = getattr(request.module, 'config') | ||
basePath = os.path.join(os.path.dirname(__file__), '../../') | ||
confDir = os.path.join(basePath, confName) | ||
conf = yaml.load(open(confDir)) | ||
producer = getattr(request.module, 'producer', 'null-account') | ||
conf['producer'] = producer | ||
return conf | ||
|
||
class Checkers: | ||
@staticmethod | ||
def check_price(prices, computedAssetName, collateralName, maxSpread): | ||
print(prices) | ||
assert computedAssetName in prices | ||
assetPrice = prices[computedAssetName] | ||
for field in ['mean', 'global_feed', 'price', 'weighted', 'cer', | ||
'priceChange', 'mssr', 'current_feed', 'short_backing_symbol', | ||
'median', 'mcr', 'std', 'number']: | ||
assert field in assetPrice | ||
assert collateralName == assetPrice['short_backing_symbol'] | ||
feedPrice = assetPrice['global_feed']['settlement_price'].as_quote(collateralName)['price'] | ||
computedPrice = assetPrice['price'] | ||
assert math.fabs(1 - (computedPrice / feedPrice)) < maxSpread | ||
|
||
@pytest.fixture | ||
def checkers(): | ||
return Checkers | ||
|
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,9 @@ | ||
from bitshares_pricefeed.pricefeed import Feed | ||
|
||
config = 'bitshares_pricefeed/examples/hero.yaml' | ||
|
||
def test_hero_computation(conf, checkers): | ||
feed = Feed(conf) | ||
feed.derive({'HERO'}) | ||
prices = feed.get_prices() | ||
checkers.check_price(prices, 'HERO', 'BTS', 0.1) |
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,9 @@ | ||
from bitshares_pricefeed.pricefeed import Feed | ||
|
||
config = 'bitshares_pricefeed/examples/hertz.yaml' | ||
|
||
def test_hertz_computation(conf, checkers): | ||
feed = Feed(conf) | ||
feed.derive({'HERTZ'}) | ||
prices = feed.get_prices() | ||
checkers.check_price(prices, 'HERTZ', 'BTS', 0.1) |
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,9 @@ | ||
from bitshares_pricefeed.pricefeed import Feed | ||
|
||
config = 'bitshares_pricefeed/examples/XCD.yaml' | ||
|
||
def test_XCD_computation(conf, checkers): | ||
feed = Feed(conf) | ||
feed.derive({'XCD'}) | ||
prices = feed.get_prices() | ||
checkers.check_price(prices, 'XCD', 'USD', 0.1) |