-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExchange-sample.py
50 lines (34 loc) · 1.53 KB
/
Exchange-sample.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
import datetime
from Exchange import Exchange, ExchangeList
data_file = "./DB/exchanges.json"
# ----------------------------------------
# List of available exchanges
# ----------------------------------------
exchanges = ExchangeList(data_file)
print("List of exchanges:")
for exchange in exchanges.exchanges_get():
print(f'- {exchange}')
# ----------------------------------------
# BINANCE Exchange
# ----------------------------------------
binance = Exchange('binance',data_file)
# Info
print(f'\nExchange : {binance.name}, Id : {binance.id}, Version : {binance.version}, Supports fetch prices? : {binance.has_fetch_prices}\n')
# Products and the closing price
for product in binance.products:
product_id = binance.products[product]["id"]
price = binance.price_get(product_id)
date = datetime.datetime.fromtimestamp( price["timestamp"])
print(f'Product : {product}, Closing price : {price["close"]}, Date : {date}')
# ----------------------------------------
# FTX Exchange
# ----------------------------------------
ftx = Exchange('ftx',data_file)
# Info
print(f'\nExchange : {ftx.name}, Id : {ftx.id}, Version : {ftx.version}, Supports fetch prices? : {ftx.has_fetch_prices}\n')
# Products and the closing price
for product in ftx.products:
product_id = ftx.products[product]["id"]
price = ftx.price_get(product_id)
date = datetime.datetime.fromtimestamp( price["timestamp"])
print(f'Product : {product}, Closing price : {price["close"]}, Date : {date}')