Skip to content

Commit

Permalink
Merge branch 'release/0.3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Feb 26, 2016
2 parents dc7b8f8 + 98ae95d commit 5637cb9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
4 changes: 4 additions & 0 deletions scripts/pricefeeds/config-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
# Stop calling when collateral only pays off 110% of the debt
# This is denoted as: 1100 = 110% = 1.10
"maximum_short_squeeze_ratio" : 1100,
# If set to True, prices are also derived via 3
# markets instead of just two:
# E.g. : GOLD:USD -> USD:BTC -> BTC:BTS = GOLD:BTS
"derive_across_3markets" : False
},
# Exchanges trading BTC/BTS directly
# (this does not include any other trading pairs)
Expand Down
7 changes: 4 additions & 3 deletions scripts/pricefeeds/feedsources.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,10 @@ def fetch(self):
if hasattr(self, "quoteNames") and quote in self.quoteNames:
quote = self.quoteNames[quote]
feed[base] = {}
feed[base][quote] = {"price" : (float(ticker[market]["last"])),
"volume" : (float(ticker[market]["quoteVolume"]) * self.scaleVolumeBy)}
feed[base]["response"] = ticker[market]
if (float(ticker[market]["last"])) > 0 and float(ticker[market]["quoteVolume"]) > 0:
feed[base][quote] = {"price" : (float(ticker[market]["last"])),
"volume" : (float(ticker[market]["quoteVolume"]) * self.scaleVolumeBy)}
feed[base]["response"] = ticker[market]
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if not self.allowFailure:
Expand Down
46 changes: 35 additions & 11 deletions scripts/pricefeeds/pricefeeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,37 @@ def derive_prices(feed):
# This loop adds prices going via 2 markets:
# E.g. : CNY:BTC -> BTC:BTS = CNY:BTS
# I.e. : BTS : interasset -> interasset : targetasset
for targetasset in [asset] :
for interasset in _bases :
if interasset == targetasset :
continue
for ratio in price[targetasset][interasset] :
for idx in range(0, len(price[interasset][core_symbol])) :
if volume[interasset][core_symbol][idx] == 0 :
continue
price[targetasset][core_symbol].append((float(price[interasset][core_symbol][idx] * ratio)))
volume[targetasset][core_symbol].append((float(volume[interasset][core_symbol][idx] * ratio)))
for interasset in _bases :
if interasset == asset :
continue
for ratio in price[asset][interasset] :
for idx in range(0, len(price[interasset][core_symbol])) :
if volume[interasset][core_symbol][idx] == 0 :
continue
price[asset][core_symbol].append((float(price[interasset][core_symbol][idx] * ratio)))
volume[asset][core_symbol].append((float(volume[interasset][core_symbol][idx] * ratio)))

# derive BTS prices for all assets in asset_list_publish
# This loop adds prices going via 3 markets:
# E.g. : GOLD:USD -> USD:BTC -> BTC:BTS = GOLD:BTS
# I.e. : BTS : interassetA -> interassetA : interassetB -> asset : interassetB
if "derive_across_3markets" in this_asset_config and this_asset_config["derive_across_3markets"] :
for interassetA in _bases :
for interassetB in _bases :
if interassetB == asset :
continue
if interassetA == asset :
continue
if interassetA == interassetB :
continue

for ratioA in price[interassetB][interassetA] :
for ratioB in price[asset][interassetB] :
for idx in range(0, len(price[interassetA][core_symbol])) :
if volume[interassetA][core_symbol][idx] == 0 :
continue
price[asset][core_symbol].append((float(price[interassetA][core_symbol][idx] * ratioA * ratioB)))
volume[asset][core_symbol].append((float(volume[interassetA][core_symbol][idx] * ratioA * ratioB)))

# Derive all prices and pick the right one later
assetvolume = [v for v in volume[asset][core_symbol]]
Expand Down Expand Up @@ -363,7 +384,7 @@ def print_stats(feeds) :
"publish"])
t.align = 'c'
t.border = True
for asset in asset_list_publish :
for asset in feeds :
# Get Final Price according to price metric
this_asset_config = config.asset_config[asset] if asset in config.asset_config else config.asset_config["default"]
price_metric = this_asset_config["metric"] if "metric" in this_asset_config else config.asset_config["default"]["metric"]
Expand Down Expand Up @@ -500,6 +521,9 @@ def update_price_feed() :
"feed": price_feed,
"publish": asset_update_required
}
else :
print("Warning: Asset %s has a negative derived price of %f (%s metric)!" % (asset, float(derived_prices[asset][price_metric]), price_metric))
continue

if not debug :
# Print some stats ##########################################################
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

VERSION = '0.3.2'
VERSION = '0.3.3'

setup(name='graphenelib',
version=VERSION,
Expand Down

0 comments on commit 5637cb9

Please sign in to comment.