forked from LUCIT-Systems-and-Development/unicorn-fy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_unicorn_fy.py
executable file
·100 lines (88 loc) · 4.11 KB
/
example_unicorn_fy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# File: example_unicorn_fy.py
#
# Part of ‘UnicornFy’
# Project website: https://github.com/oliver-zehentleitner/unicorn_fy
# Documentation: https://oliver-zehentleitner.github.io/unicorn_fy
# PyPI: https://pypi.org/project/unicorn-fy
#
# Author: Oliver Zehentleitner
# https://about.me/oliver-zehentleitner
#
# Copyright (c) 2019, Oliver Zehentleitner
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from unicorn_fy.unicorn_fy import UnicornFy
import json
# recevied data format from binance:
received_stream_data_json = {"stream": "btcusdt@trade",
"data": {"e": "trade",
"E": 1556876873656,
"s": "BTCUSDT",
"t": 117727701,
"p": "5786.76000000",
"q": "0.03200500",
"b": 341831847,
"a": 341831876,
"T": 1556876873648,
"m": True,
"M": True}}
received_stream_data_json = json.dumps(received_stream_data_json)
print("raw format:")
print(received_stream_data_json)
# unicorn_fy the format:
unicorn_fied_stream_data = UnicornFy.binance_com_websocket(received_stream_data_json)
print("unicorn_fied:")
print(unicorn_fied_stream_data)
# recevied data format from binance:
received_stream_data_json = {"stream": "ethbtc@ticker",
"data": {"e": "24hrTicker",
"E": 1556877162244,
"s": "ETHBTC",
"p": "-0.00057000",
"P": "-1.926",
"w": "0.02918378",
"x": "0.02959500",
"c": "0.02902900",
"Q": "0.51600000",
"b": "0.02901600",
"B": "0.47500000",
"a": "0.02903000",
"A": "5.48000000",
"o": "0.02959900",
"h": "0.02963400",
"l": "0.02820900",
"v": "222630.30500000",
"q": "6497.19329404",
"O": 1556790762240,
"C": 1556877162240,
"F": 119982523,
"L": 120137417,
"n": 154895}}
received_stream_data_json = json.dumps(received_stream_data_json)
print("raw format:")
print(received_stream_data_json)
# unicorn_fy the format:
unicorn_fied_stream_data = UnicornFy.binance_com_websocket(received_stream_data_json)
print("unicorn_fied:")
print(unicorn_fied_stream_data)