Skip to content

Commit

Permalink
[Price Feed] Allow FeedSource Failure. Improve price calculations. Co…
Browse files Browse the repository at this point in the history
…nsistent array structure
  • Loading branch information
xeroc committed Dec 1, 2015
1 parent 0c88fc5 commit 9676670
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 109 deletions.
29 changes: 21 additions & 8 deletions scripts/pricefeeds/config-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,19 @@
# the discount
"discount" : 1.0,
},
"USD" : {
## Exchanges trading BTC/BTS directly
## (this does not include any other trading pairs)
"BTC" : {
"sources" : ["poloniex",
#"btc38",
"bittrex",
"yunbi",
"huobi",
"btcchina",
"okcoin",
"ccedk",
"bittrex",
],
},
## Settings for CNY take popular chinese exchanges into
## account that let people trade without fees.
## Hence, the metric should be median, since the volume could
## be easily manipulated
"CNY" : {
"metric" : "median",
"sources" : ["poloniex",
Expand All @@ -91,20 +94,30 @@

################################################################################
## Exchanges and settings
##
## trust: a multiplicative factor for the volume
## allowFailure: bool variable that will (if not set or set to False) exit the
## script on error
################################################################################
feedSources = {}
feedSources["yahoo"] = feedsources.Yahoo(trust=1.0)
feedSources["btcavg"] = feedsources.BitcoinAverage(trust=1.0)

feedSources["poloniex"] = feedsources.Poloniex(trust=1.0)
feedSources["ccedk"] = feedsources.Ccedk(trust=1.0)
feedSources["yunbi"] = feedsources.Yunbi(trust=1.0)
feedSources["yunbi"] = feedsources.Yunbi(trust=1.0, allowFailure=True)
feedSources["btcchina"] = feedsources.BtcChina(trust=1.0)
feedSources["huobi"] = feedsources.Huobi(trust=1.0)
feedSources["okcoin"] = feedsources.Okcoin(trust=1.0)
feedSources["okcoin"] = feedsources.Okcoin(trust=1.0, allowFailure=True)

feedSources["bittrex"] = feedsources.Bittrex(trust=0.5)

feedSources["btcid"] = feedsources.BitcoinIndonesia(trust=0.0)
feedSources["btc38"] = feedsources.Btc38(trust=0.0)
feedSources["bter"] = feedsources.Bter(trust=0.0)

################################################################################
# Debug Mode! This loads old data and prevents the script for publishing any
# price feed!
################################################################################
debug = False # True or False
39 changes: 23 additions & 16 deletions scripts/pricefeeds/feedsources.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
}

class FeedSource() :
def __init__(self, trust=1.0, enable=True):
self.trust = trust
self.enabled = enable
self.feed = None
def __init__(self, trust=1.0, enable=True, allowFailure=False):
self.trust = trust
self.enabled = enable
self.allowFailure = allowFailure

## Why fail if the trust is 0
if self.trust == 0.0 :
self.allowFailure = True

class BitcoinIndonesia(FeedSource) :
def __init__(self, *args, **kwargs) :
Expand All @@ -50,7 +54,7 @@ def fetch(self):
"volume" : float(result["vol_"+coin.lower()])*self.trust }
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance!")
return
return feed
Expand Down Expand Up @@ -78,7 +82,7 @@ def fetch(self):
"volume" : float(result["vol"])*self.trust}
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance!")
return
return feed
Expand All @@ -97,7 +101,7 @@ def fetch(self):
result = response.json()
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance")
return
availableAssets = [ core_symbol ]
Expand Down Expand Up @@ -131,7 +135,7 @@ def fetch(self):
availableAssets = [ core_symbol, "BTC" ]
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance!")
return
try :
Expand All @@ -143,7 +147,7 @@ def fetch(self):
"volume" : (float(result[coin.lower()]["ticker"]["vol"])*float(result[coin.lower()]["ticker"]["last"])*self.trust) }
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance!")
return
return feed
Expand All @@ -161,7 +165,7 @@ def fetch(self):
result = response.json()
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance")
return
availableAssets = [ "BTC", core_symbol ]
Expand All @@ -187,7 +191,7 @@ def fetch(self):
availableAssets = [ core_symbol ]
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance!")
return
for coin in availableAssets :
Expand All @@ -209,7 +213,7 @@ def fetch(self):
result = response.json()["result"]
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance!")
return
for coin in result :
Expand Down Expand Up @@ -256,7 +260,10 @@ def fetch(self):
# feed[ core_symbol ][ self.bts_yahoo_map(a) ] = { "price" : (1/float(yahooprices[i])),
# "volume" : 1.0, }
except Exception as e:
sys.exit("\nError fetching results from yahoo! {0}".format(str(e)))
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance!")
return

return feed

Expand Down Expand Up @@ -295,7 +302,7 @@ def fetch(self):
"volume" : (float(result["ticker"]["vol"])*self.trust) }
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance!")
return
return feed
Expand All @@ -319,7 +326,7 @@ def fetch(self):
"volume" : (float(result["ticker"]["vol"])*self.trust) }
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance!")
return
return feed
Expand Down Expand Up @@ -348,7 +355,7 @@ def fetch(self):
"volume" : (float(result["ticker"]["vol"])*self.trust) }
except Exception as e:
print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__))
if self.trust > 0.8:
if not self.allowFailure:
sys.exit("\nExiting due to exchange importance!")
return
return feed
Loading

0 comments on commit 9676670

Please sign in to comment.