forked from cuemacro/findatapy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptodata_example.py
159 lines (131 loc) · 6.76 KB
/
cryptodata_example.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
__author__ = "saeedamen" # Saeed Amen
#
# Copyright 2016 Cuemacro
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on a "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
# TODO: Needs fixing, given change in APIs
if __name__ == "__main__":
###### below line CRUCIAL when running Windows, otherwise multiprocessing
# doesn"t work! (not necessary on Linux)
from findatapy.util import SwimPool;
SwimPool()
from findatapy.market import Market, MarketDataRequest, MarketDataGenerator
market = Market(market_data_generator=MarketDataGenerator())
# Choose run_example (0 = all examples)
# Example 1: bitcoincharts
# Example 2: poloniex (needs to be fixed)
# Example 3: binance
# Example 4: bitfinex
# Example 5: gdax
# Example 6: kraken
#
# Check findatapy/conf/time_series_tickers_list.csv for all possible tickers
# Note we use XBT instead of BTC. Same for XET (ETH) and XLC (LTC).
#
# Note: there will generally be a limit of how many data points you can
# pull in one call, so you might
# have to choose smaller time periods
run_example = 0
if run_example == 1 or run_example == 0:
### Download data from bitcoincharts ###
# fields contains ["close","volume"]
# return tick data
md_request = MarketDataRequest(start_date="11 Nov 2015",
finish_date="02 Feb 2018", cut="LOC",
freq="tick",
data_source="bitcoincharts",
category="crypto",
fields=["close", "volume"],
tickers=["XBTUSD_itbit"])
df = market.fetch_market(md_request)
print(df.head(5))
print(df.tail(5))
if run_example == 2 or run_example == 0:
### Download data from poloniex ###
# freq : daily or intraday, where intraday - returns 5 minutes data.
# fields contains ["close","high","low","open","quote-volume","volume","weighted-average"]
md_request = MarketDataRequest(start_date="18 Feb 2017",
finish_date="20 Feb 2017", cut="LOC",
freq="intraday", data_source="poloniex",
category="crypto",
fields=["close", "volume",
"weighted-average"],
tickers=["STRXBT"])
df = market.fetch_market(md_request)
print(df.head(5))
print(df.tail(5))
if run_example == 3 or run_example == 0:
### download data from binance ###
# freq: daily or intraday. intraday - return 1 minute data
# fields contain ["open","high","low","close","volume","quote-asset-volume",
# "trade-numbers","taker-buy-base-asset-volume","taker-buy-quote-asset-volume"]
# Note it may take a while due to the limit of numbers per second calling the API
md_request = MarketDataRequest(start_date="01 Feb 2017",
finish_date="20 Feb 2018", cut="LOC",
freq="daily", data_source="binance",
category="crypto",
fields=["close", "volume",
"quote-asset-volume"],
tickers=["WTCXBT"])
df = market.fetch_market(md_request)
print(df.head(5))
print(df.tail(5))
if run_example == 4 or run_example == 0:
### download data from bitfinex ###
# freq: daily or intraday. intraday - return 1 minute data
# fields contain ["open","close","high","low","volume"]
# Note it may take a while due to the limit of numbers per second calling the API
md_request = MarketDataRequest(start_date="11 Feb 2018",
finish_date="20 Feb 2018", cut="LOC",
freq="intraday", data_source="bitfinex",
category="crypto",
fields=["close", "volume", "high",
"open"],
tickers=["XLCUSD"])
df = market.fetch_market(md_request)
print(df.head(5))
print(df.tail(5))
if run_example == 5 or run_example == 0:
### Download data from gdax (now called coinbase pro) ###
# freq: daily or intraday. intraday - 1 minute data
# fields contain ["low","high","open","close","volume"]
# Note it may take a while due to the limit of numbers per second calling the API
md_request = MarketDataRequest(start_date="01 Jan 2018 00:00",
finish_date="01 Jan 2018 01:50",
cut="LOC",
freq="intraday", data_source="gdax",
category="crypto",
fields=["close", "volume", "low",
"high"],
tickers=["XBTUSD"])
df = market.fetch_market(md_request)
print(df.head(5))
print(df.tail(5))
if run_example == 6:
### Download data from kraken ###
# freq: tick (all trade data)
# fields contain ["close","volume","buy-sell","market-limit"]
# buy-sell : 1 means buy, and -1 means sell
# market-limit: 1 means market, and -1 means limit
# Note it may take a while due to the limit of numbers per second for
# calling the API
md_request = MarketDataRequest(start_date="19 Feb 2018",
finish_date="20 Feb 2018", cut="LOC",
freq="tick", data_source="kraken",
category="crypto",
fields=["close", "volume", "buy-sell",
"market-limit"],
tickers=["XBTUSD"])
df = market.fetch_market(md_request)
print(df.head(5))
print(df.tail(5))