-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed.py
129 lines (112 loc) · 3.77 KB
/
feed.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from bitshares.asset import Asset
from bitshares import BitShares
from bitshares.instance import set_shared_bitshares_instance
from bitshares.price import Price
from bitshares.market import Market
from bitsharesapi.websocket import BitSharesWebsocket
import pendulum
import math
def norn_feed(amplitude, reference_timestamp, current_timestamp, period, phase_offset):
"""
Given the reference timestamp, the current timestamp, the period (in days), the phase (in days), the reference asset value (ie 1.00) and the amplitude (> 0 && < 1), output the current value.
"""
waveform = math.sin(((((current_timestamp - (reference_timestamp + phase_offset))/period) % 1) * period) * ((2*math.pi)/period)) # Only change for an alternative HERTZ ABA.
return 1 + (amplitude * waveform)
def publish_wyrd(block_param):
"""
Triggers every 3 seconds.
Calculates then publishes the feeds for urthr, verthandi and skuld.
"""
print("publishing")
reference_timestamp = pendulum.parse("2015-10-13T14:12:24+00:00").timestamp() # Retrieving the Bitshares 2.0 genesis block timestamp
current_timestamp = pendulum.now().timestamp()
urthr_value = norn_feed(
0.05303030303, # amplitude
reference_timestamp,
current_timestamp,
86400 * 28, # period
0 # phase offset
)
print("urthr value established")
verthandi_value = norn_feed(
0.05303030303, # amplitude
reference_timestamp,
current_timestamp,
86400 * 28, # period
86400 * 9.33 # phase offset
)
print("verthandi value established")
skuld_value = norn_feed(
0.05303030303, # amplitude
reference_timestamp,
current_timestamp,
86400 * 28, # period
86400 * 18.66 # phase offset
)
print("skuld value established")
#print("urthr:" + str(urthr_value) + " verthandi:" + str(verthandi_value) + " skuld:" + str(skuld_value))
urthr = Price(urthr_value, "BTS/URTHR")
verthandi = Price(verthandi_value, "BTS/VERTHANDI")
skuld = Price(skuld_value, "BTS/SKULD")
print("values applied to bitasset price objects")
wallet_password = "LOCAL_WALLET_PASSWORD"
urthr.bitshares.wallet.unlock(wallet_password)
verthandi.bitshares.wallet.unlock(wallet_password)
skuld.bitshares.wallet.unlock(wallet_password)
print("wallet unlocked")
urthr.bitshares.publish_price_feed(
"URTHR",
urthr,
cer=urthr*0.95, # Setting in line with Wackou's price feed scripts
mssr=101,
mcr=105,
account="account_name"
)
verthandi.bitshares.publish_price_feed(
"VERTHANDI",
verthandi,
cer=verthandi*0.95, # Setting in line with Wackou's price feed scripts
mssr=101,
mcr=105,
account="account_name"
)
skuld.bitshares.publish_price_feed(
"SKULD",
skuld,
cer=skuld*0.95, # Setting in line with Wackou's price feed scripts
mssr=101,
mcr=105,
account="account_name"
)
print("completed feed")
if __name__ == "__main__":
"""
Script begins here
"""
print("Started")
full_node_list = [
"wss://eu.nodes.bitshares.ws", # Central Europe
"wss://us.nodes.bitshares.ws", # U.S. West Coast
"wss://sg.nodes.bitshares.ws", # Singapore
"wss://bitshares.crypto.fans/ws", # Munich, Germany
"wss://bit.btsabc.org/ws", # Hong Kong
"wss://api.bts.blckchnd.com" # Falkenstein, Germany
"wss://openledger.hk/ws", # Hong Kong
"wss://bitshares.openledger.info/ws",
"wss://bitshares-api.wancloud.io/ws", # China
"wss://dex.rnglab.org", # Netherlands
"wss://dexnode.net/ws", # Dallas, USA
"wss://kc-us-dex.xeldal.com/ws", # Kansas City, USA
"wss://la.dexnode.net/ws", # Los Angeles, USA
"wss://citadel.li/node", # Iceland - Reykjavik
"wss://bts.proxyhosts.info/wss", # Germany
"wss://api.dex.trading/", # France - Paris
"wss://api.open-asset.tech/ws" # Germany - Frankfurt
]
ws = BitSharesWebsocket(
full_node_list,
objects=["2.0.x", "2.1.x", "1.3.x"]
)
print("ws connection established")
ws.on_block += publish_wyrd
ws.run_forever()