I have a JSON file valorMercado.js
with the following values:
{"BTC":{"USD":2167.85},"ETH":{"USD":167.88},"DASH":{"USD":102.31}}
{"BTC":{"USD":2253.12},"ETH":{"USD":177.76},"DASH":{"USD":109.17}}
{"BTC":{"USD":2251.47},"ETH":{"USD":177.71},"DASH":{"USD":109.12}}
...
Each time a new line is added, I want to make the average on the last five numbers of each coin to make the simple moving average ("Simple Moving Average"). However, I do not know how to recover the values from the mercaval.js file to treat them.
import numpy as np
# leer el fichero, cada vez hay una otra valor poner las 5 ultimas en a y la ultima en lastValue
fiveLast = np.array(a[-5:])
lastValue = a[-1]
# calculemos sma
fiveLastMean = np.mean(fiveLast)
# poner en marcha una alerta si lastValue < o > nowValue
for i in a.shape[1] :
if (fiveLastMean[1] < nowValue[1]):
result[i] = buy
else if(fiveLastMean[1] > nowValue[1]):
result[i] = sell
The output should be a matrix of variables that belong to {buy, leave, sold}. For example:
[buy, buy, leave]
For "buy BTC, ETH and do nothing with DASH".