Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add change indicator for volume and last price #214

Merged
merged 2 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions bitvision/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,26 @@ function updateData(type) {
}

function reformatPriceData(priceData) {
return [
["Price ($)", String(priceData.last)],
["Volume", String(priceData.volume)],
["24H Low ($)", String(priceData.low)],
["24H High ($)", String(priceData.high)],
["Open Price ($)", String(priceData.open)]
];
let price_str = null;
if (priceData.last_incr) {
price_str = `${String(priceData.last)} ${figures.arrowUp.green}`;
} else {
price_str = `${String(priceData.last)} ${figures.arrowDown.red}`;
}
let vol_str = null;
if (priceData.vol_incr) {
vol_str = `${String(priceData.volume)} ${figures.arrowUp.green}`;
} else {
vol_str = `${String(priceData.volume)} ${figures.arrowDown.red}`;
}

return [
["Price ($)", price_str],
["Volume", vol_str],
["24H Low ($)", String(priceData.low)],
["24H High ($)", String(priceData.high)],
["Open Price ($)", String(priceData.open)]
];
}

function reformatPortfolioData(portfolioData, titles) {
Expand Down
29 changes: 23 additions & 6 deletions bitvision/services/retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,30 @@


def fetch_price_data():
with open("./cache/data/ticker.json", 'w') as price_data:
with open("./cache/data/ticker.json", 'rw') as price_data:
try:
response = requests.get("https://www.bitstamp.net/api/ticker/").json()

old_data = json.load(price_data)
# If ticker.json has data already, calculate changes for vol and price
# TODO: This will not work properly if the user has stale data.
if len(old_data["data"]) > 2:
new_last = round(float(response["last"]), 2)
last_incr = new_last > old_data["data"]["last"]

new_vol = round(float(response["volume"]), 2)
vol_incr = new_vol > old_data["data"]["volume"]

price_data.write(json.dumps({
"error": False,
"data": {
"last": round(float(response["last"]), 2),
"last": new_last,
"last_incr": last_incr,
"high": round(float(response["high"]), 2),
"low": round(float(response["low"]), 2),
"open": round(float(response["open"]), 2),
"volume": round(float(response["volume"]), 2)
"volume": new_vol,
"volume_incr": vol_incr
}
}, indent=2))
except:
Expand Down Expand Up @@ -98,6 +110,7 @@ def fetch_price_data():
"data": json.loads(graph_data)["data"]
}))


def fetch_tech_indicators():
with open("./cache/data/indicators.json", 'w') as indicators_json:
try:
Expand All @@ -114,10 +127,10 @@ def fetch_tech_indicators():
"EMA (6)"
]

get_val = lambda symb: round(indicators[symb][0], 2)
def get_val(symb): return round(indicators[symb][0], 2)
get_signal = {
"MOM (1)": lambda v: "BUY" if v >= 0 else "SELL",
"ADX (14)": lambda v: "BUY" if v >= 25 else "SELL", # Not sure about this
"ADX (14)": lambda v: "BUY" if v >= 25 else "SELL", # Not sure about this
"WILLR": lambda v: "SELL" if v <= -50 else "BUY",
"RSI (6)": lambda v: "SELL" if v >= 50 else "BUY",
"ATR (14)": lambda v: "N/A",
Expand All @@ -141,6 +154,7 @@ def fetch_tech_indicators():
"data": []
}, indent=2))


def fetch_blockchain_data():
with open("./cache/data/blockchain.json", 'w') as blockchain_data_json:
try:
Expand Down Expand Up @@ -181,6 +195,7 @@ def fetch_blockchain_data():
"data": []
}, indent=2))


def fetch_coindesk_stats():
with open("./cache/data/headlines.json", 'w') as headlines_json:
try:
Expand Down Expand Up @@ -233,6 +248,7 @@ def fetch_coindesk_stats():
"data": []
}, indent=2))


def fetch_portfolio_stats(client):
with open("./cache/data/portfolio.json", 'w') as portfolio_json:
try:
Expand All @@ -254,6 +270,7 @@ def fetch_portfolio_stats(client):
"data": {}
}))


def fetch_transaction_data(client):
with open("./cache/data/transactions.json", 'w') as transactions:
try:
Expand All @@ -274,7 +291,7 @@ def fetch_transaction_data(client):


def retrieve(names, client=None):
for name in names: # TODO: Parallelize
for name in names: # TODO: Parallelize
if name == "price_data":
fetch_price_data()
elif name == "tech_indicators":
Expand Down