-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadExchangeRatesGDAX.py
135 lines (86 loc) · 2.87 KB
/
readExchangeRatesGDAX.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
# Name: readExchangeRatesGDAX.py
# Author: Matt Nutsch
# Date Created: 1-19-2018
# Last Edited: 1-27-2018
# Description: This script reads cryptocurrency exchange rate information from the exchange GDAX.
#examples of calling the functions
#print "Reading the exchange rates from the GDAX exchange."
#print "The BCH-USD price is: " + getBCHToUSDFromGDAX();
#print "The LTC-USD price is: " + getLTCToUSDFromGDAX();
#print "The BTC-USD price is: " + getBTCToUSDFromGDAX();
#print "The ETH-USD price is: " + getETHToUSDFromGDAX();
#import libraries
import urllib, json, time
gdax_bchUsdPrice = 0.00
gdax_ethUsdPrice = 0.00
gdax_ltcUsdPrice = 0.00
gdax_btcUsdPrice = 0.00
###################################################
def getBCHToUSDFromGDAX():
#BCH-USD
#Get the BCH-USD price.
#set up the URL
url = "https://api.gdax.com/products/BCH-USD/ticker"
#read the page contents
response = urllib.urlopen(url)
data = json.loads(response.read())
gdax_bchUsdPrice = data["price"]
#output the data so that we can see it
#print "The raw output is: "
#print data
#print "The BCH-USD price is: " + gdax_bchUsdPrice
#pause briefly
time.sleep(.300)
return gdax_bchUsdPrice;
###################################################
def getETHToUSDFromGDAX():
#ETH-USD
#Get the ETH-USD price.
#set up the URL
url = "https://api.gdax.com/products/ETH-USD/ticker"
#read the page contents
response = urllib.urlopen(url)
data = json.loads(response.read())
gdax_ethUsdPrice = data["price"]
#output the data so that we can see it
#print "The raw output is: "
#print data
#print "The ETH-USD price is: " + gdax_ethUsdPrice
#pause briefly
time.sleep(.300)
return gdax_ethUsdPrice;
###################################################
def getLTCToUSDFromGDAX():
#LTC-USD
#Get the LTC-USD price.
#set up the URL
url = "https://api.gdax.com/products/LTC-USD/ticker"
#read the page contents
response = urllib.urlopen(url)
data = json.loads(response.read())
gdax_ltcUsdPrice = data["price"]
#output the data so that we can see it
#print "The raw output is: "
#print data
#print "The LTC-USD price is: " + gdax_ltcUsdPrice
#pause briefly
time.sleep(.300)
return gdax_ltcUsdPrice;
###################################################
def getBTCToUSDFromGDAX():
#BTC-USD
#Get the BTC-USD price.
#set up the URL
url = "https://api.gdax.com/products/BTC-USD/ticker"
#read the page contents
response = urllib.urlopen(url)
data = json.loads(response.read())
gdax_btcUsdPrice = data["price"]
#output the data so that we can see it
#print "The raw output is: "
#print data
#print "The BTC-USD price is: " + gdax_btcUsdPrice
#pause briefly
time.sleep(.300)
return gdax_btcUsdPrice;
###################################################