forked from bmoscon/cryptofeed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_loop.py
42 lines (27 loc) · 878 Bytes
/
demo_loop.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
'''
Copyright (C) 2017-2025 Bryant Moscon - [email protected]
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import asyncio
from cryptofeed import FeedHandler
from cryptofeed.defines import TRADES
from cryptofeed.exchanges import Coinbase
async def trade(t, receipt):
print(t)
f = FeedHandler()
def stop():
loop = asyncio.get_event_loop()
loop.stop()
def add_new_feed():
loop = asyncio.get_event_loop()
f.add_feed(Coinbase(symbols=['ETH-USD'], channels=[TRADES], callbacks={TRADES: trade}), loop=loop)
def main():
loop = asyncio.get_event_loop()
f.add_feed(Coinbase(symbols=['BTC-USD'], channels=[TRADES], callbacks={TRADES: trade}))
f.run(start_loop=False)
loop.call_later(2, add_new_feed)
loop.call_later(15, stop)
loop.run_forever()
if __name__ == '__main__':
main()