volume_BTC = [1, 2, 3, 4]
price_BTC = [50, 100, 150, 200]
volume_ETH = [1, 5, 8, 12]
price_ETH = [50, 40, 25, 9]
tickers = [volume_BTC, price_BTC, volume_ETH, price_ETH]
def check_state(now, prev):
if prev is None:
return None
elif now is None:
return None
elif now >= prev and now <= 1.5 * prev:
state = 0
elif now >= 1.5 * prev:
state = 1
elif now < prev and now * 1.5 >= prev:
state = 2
elif now * 1.5 < prev:
state = 3
# возвращаем состояние
return state
# Узнаем по каком тикеру сработало условие?
def check_condition(tickers):
list_tickers =[]
valueprev = None
for i_ticker in tickers:
for valuenow in i_ticker:
check_this_state = check_state(valuenow, valueprev)
valueprev = valuenow
list_tickers.append(check_this_state)
valueprev = None
return list_tickers
res = check_condition(tickers)
print(res)
volume_BTC = [1, 2, 3, 4]
price_BTC = [50, 100, 150, 200]
volume_ETH = [1, 5, 8, 12]
price_ETH = [50, 40, 25, 9]
tickers = [volume_BTC, price_BTC, volume_ETH, price_ETH]
tickers_state = {}
# check state . Описываем состояния для первого условия. Может быть 4 различных
def check_state(now, prev):
if prev is None:
return None
elif now is None:
return None
# [0; 1.5x]
elif now >= prev and now <= 1.5 * prev:
state = 0
# [1.5x;Бесконечность]
elif now >= 1.5 * prev:
state = 1
# [-1.5x;0]
elif now < prev and now * 1.5 >= prev:
state = 2
# [-Бесконечность]
elif now * 1.5 < prev:
state = 3
# возвращаем состояние
return state
# Узнаем состояние по первому условию для всего значений в колонке
def check_condition(ticker):
list_tickers =[]
valueprev = None
#for i_ticker in tickers:
for valuenow in ticker:
check_this_state = check_state(valuenow, valueprev)
valueprev = valuenow
list_tickers.append(check_this_state)
return list_tickers
for i_ticker in tickers:
res = check_condition(i_ticker)
print(res)
def check_state(now, prev):
if prev is None:
return None
elif now is None:
return None
elif now >= prev and now <= 1.5 * prev:
state = 0
elif now >= 1.5 * prev:
state = 1
elif now < prev and now * 1.5 >= prev:
state = 2
elif now * 1.5 < prev:
state = 3
# возвращаем состояние
return state