-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added examples/py/fetch-ohlcv-kraken.py ccxt#110
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import sys | ||
import asciichart | ||
|
||
# ----------------------------------------------------------------------------- | ||
|
||
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 | ||
|
||
# ----------------------------------------------------------------------------- | ||
|
||
exchange = ccxt.kraken() | ||
symbol = 'LTC/EUR' | ||
|
||
# each ohlcv candle is a list of [ timestamp, open, high, low, close, volume ] | ||
index = 4 # use close price from each ohlcv candle | ||
|
||
length = 80 | ||
height = 15 | ||
|
||
|
||
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 datetime and other values | ||
for x in ohlcv: | ||
print(exchange.iso8601(x[0]), x) | ||
|
||
# print the chart | ||
print("\n" + asciichart.plot(series[-length:], {'height': height})) # print the chart | ||
|
||
last = ohlcv[len(ohlcv) - 1][index] # last closing price | ||
return last | ||
|
||
|
||
last = print_chart(exchange, symbol, '1m') | ||
print("\n" + exchange.name + " ₿ = $" + str(last) + "\n") # print last closing price |