Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WebSocket example subscribe executions
from collections import deque
executions = deque(maxlen=100)
@sio.event
def message(data):
sma = 5 # default number of executions for mean
transactions = data['message']['data']['transactions']
# print('transaction type: {}'.format(type(transactions)))
# print(json.dumps(transactions, indent=2))
for num, transaction in enumerate(transactions):
print('transaction {0}: {1}'.format(num, transaction))
executions.appendleft(int(transaction['price']))
execution_num = len(executions)
if sma < execution_num:
l = list(executions)[0:sma]
print('executions average in queue: {}'.format(int(round(sum(l)/len(l)))))
elif sma > execution_num:
sma = execution_num
l = list(executions)[0:sma]
print('executions average in queue: {}'.format(int(round(sum(l)/len(l)))))
else:
print('executions are none')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment