-
Notifications
You must be signed in to change notification settings - Fork 3
/
basic-chart.py
50 lines (31 loc) · 1.46 KB
/
basic-chart.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
# -*- coding: utf-8 -*-
import os
import sys
from asciichartpy import plot
# -----------------------------------------------------------------------------
this_folder = os.path.dirname(os.path.abspath(__file__))
root_folder = os.path.dirname(os.path.dirname(this_folder))
sys.path.append(root_folder + '/python')
sys.path.append(this_folder)
# -----------------------------------------------------------------------------
import ccxt # noqa: E402
# -----------------------------------------------------------------------------
kraken = ccxt.kraken()
coinbasepro = ccxt.coinbasepro()
symbol = 'BTC/USD'
# each ohlcv candle is a list of [ timestamp, open, high, low, close, volume ]
index = 4 # use close price from each ohlcv candle
def print_chart(exchange, symbol, timeframe):
print("\n" + exchange.name + ' ' + symbol + ' ' + timeframe + ' chart:')
# get a list of ohlcv candles
ohlcv = exchange.fetch_ohlcv(symbol, timeframe)
# get the ohlCv (closing price, index == 4)
series = [x[index] for x in ohlcv]
# print the chart
print("\n" + plot(series[-120:], {'height': 20})) # print the chart
last = ohlcv[len(ohlcv) - 1][index] # last closing price
return last
last = print_chart(kraken, 'BTC/USD', '1h')
print("\n" + kraken.name + " ₿ = $" + str(last) + "\n") # print last closing price
last = print_chart(coinbasepro, 'BTC/USD', '1h')
print("\n" + coinbasepro.name + " ₿ = $" + str(last) + "\n") # print last closing price