Skip to content

Commit cde4993

Browse files
committed
Bitcoin exchange REST api data
Multiple exchanges and tons of data hastily written to teach myself some development.
1 parent ae18168 commit cde4993

File tree

1 file changed

+230
-0
lines changed

1 file changed

+230
-0
lines changed

BTC Exchange Tickers.py

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
import time
2+
import json
3+
import requests
4+
5+
"""===============================================================================
6+
7+
Some api pages
8+
https://www.huobi.com/help/index.php?a=market_help&lang=en
9+
https://bitpay.com/bitcoin-payment-gateway-api
10+
https://blockchain.info/api
11+
https://localbitcoins.com/api-docs/public/
12+
https://www.bitstamp.net/api/
13+
https://coinbase.com/docs/api/overview
14+
https://coinbase.com/api/doc/1.0/prices/buy.html
15+
https://coinbase.com/api/v1/prices/spot_rate
16+
https://www.kraken.com/help/api
17+
https://www.bitfinex.com/pages/api
18+
http://bitcoincharts.com/about/markets-api/
19+
https://www.bitfinex.com/pages/api
20+
OKCOIN
21+
Market Depth - https://www.okcoin.com/api/depth.do?ok=1
22+
Futures Price Ticker - https://www.okcoin.com/api/future_ticker.do
23+
24+
http://btcchina.org/api-market-data-documentation-en
25+
26+
https://api.quadrigacx.com/v2/ticker?book=btc_cad
27+
https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&contract_type=this_week
28+
29+
30+
https://www.bitvc.com/help/api_futures_market?lang=en
31+
http://market.bitvc.com/futures/ticker_btc_week.js
32+
33+
34+
Tricks
35+
\t* indents things
36+
37+
38+
================================================================================="""
39+
"""class exchanges():
40+
bitStampTick
41+
bitFinexTick
42+
krakenTick"""
43+
44+
45+
46+
47+
def btstamp():
48+
bitStampTick = requests.get('https://www.bitstamp.net/api/ticker/')
49+
return bitStampTick.json()['last'] # replace last with timestamp etc
50+
51+
def bitfinex():
52+
bitFinexTick = requests.get("https://api.bitfinex.com/v1/ticker/btcusd")
53+
return bitFinexTick.json()['last_price']
54+
55+
def kraken():
56+
krakenTick = requests.post('https://api.kraken.com/0/public/Ticker',data=json.dumps({"pair":"XXBTZUSD"}),
57+
headers={"content-type":"application/json"})
58+
return krakenTick.json()['result']['XXBTZUSD']['c'][0]
59+
60+
61+
def coinbase():
62+
coinBaseTick = requests.get('https://coinbase.com/api/v1/prices/buy') # replace buy with spot_rate, sell etc
63+
return coinBaseTick.json()['amount'] # replace amount with currency etc
64+
65+
def coinsetUSD():
66+
coinsetter = requests.get('https://api.coinsetter.com/v1/marketdata/ticker') # replace buy with spot_rate, sell etc
67+
return coinsetter.json()['last'] ['price'] # replace amount with currency etc
68+
69+
70+
def btceBU():
71+
btceBtcTick = requests.get('https://btc-e.com/api/2/btc_usd/ticker')
72+
return btceBtcTick.json()['ticker']['last'] # replace last with updated etc
73+
74+
75+
def okcoinUSD():
76+
okcoinTick = requests.get("https://www.okcoin.com/api/ticker.do?ok=1")
77+
return okcoinTick.json()['ticker'] ['last'] # replace last with updated etc
78+
#Chinese CNY Spot
79+
80+
def okcoinCNY():
81+
okcoincn = requests.get("https://www.okcoin.cn/api/ticker.do")
82+
return okcoincn.json()['ticker'] ['last'] # replace last with updated etc
83+
84+
#def btcchinaCNY():
85+
btcchina = requests.get("https://data.btcchina.com/data/ticker?market=btccny")
86+
return btcchina.json() ['ticker'] ['high'] # replace last with updated etc
87+
88+
89+
#Canadian Exchanges
90+
91+
92+
def quadrigaUSD():
93+
quadrigausd = requests.get("https://api.quadrigacx.com/v2/ticker?book=btc_usd")
94+
return quadrigausd.json()['last'] # replace last with updated etc
95+
96+
97+
def quadrigaCAD():
98+
quadrigacad = requests.get("https://api.quadrigacx.com/v2/ticker?book=btc_cad")
99+
return quadrigacad.json()['last'] # replace last with updated etc
100+
101+
102+
103+
#OKCOIN USD Futures
104+
105+
106+
def okcUSDFUTWEEK():
107+
okcweek = requests.get("https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&contract_type=this_week")
108+
return okcweek.json()['ticker'] ['last'] # replace last with updated etc
109+
110+
111+
def okcUSDFUTBIWEEK():
112+
okcbiweek = requests.get("https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&contract_type=next_week")
113+
return okcbiweek.json()['ticker'] ['last'] # replace last with updated etc
114+
115+
116+
def okcUSDFUTQUARTER():
117+
okcquarter = requests.get("https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&contract_type=quarter")
118+
return okcquarter.json()['ticker'] ['last'] # replace last with updated etc
119+
120+
121+
#BITVC CNY Futures
122+
123+
def bitVCFUTWEEK():
124+
bitvcweek = requests.get("http://market.bitvc.com/futures/ticker_btc_week.js")
125+
return bitvcweek.json()['last'] # replace last with updated etc
126+
127+
def bitVCFUTBIWEEK():
128+
bitvcbiweek = requests.get("http://market.bitvc.com/futures/ticker_btc_next_week.js")
129+
return bitvcbiweek.json()['last'] # replace last with updated etc
130+
131+
def bitVCFUTQUARTERLY():
132+
bitvcquarterly = requests.get("http://market.bitvc.com/futures/ticker_btc_quarter.js")
133+
return bitvcquarterly.json()['last'] # replace last with updated etc
134+
135+
136+
137+
"""=============================================================================="""
138+
139+
140+
while True:
141+
#Spot Price
142+
btstampUSDLive = float(btstamp())
143+
bfxUSDLive = float(bitfinex())
144+
krakenUSDLive = float(kraken())
145+
coinbUSDLive = float(coinbase())
146+
btceUSDLive = float(btceBU())
147+
CoinsetterUSD = float(coinsetUSD())
148+
okcoinUSDSPOT = float(okcoinUSD())
149+
#Chinese CNY Spot
150+
okcoinCNYSPOT = float(okcoinCNY())
151+
#BTCChinaCNY = float(btcchinaCNY())
152+
#Canada Spot
153+
QuadrigaUSD = float(quadrigaUSD())
154+
QuadrigaCAD = float(quadrigaCAD())
155+
#OKCOIN USD Futures
156+
OkcWeekly = float(okcUSDFUTWEEK())
157+
OkcBiWeekly = float(okcUSDFUTBIWEEK())
158+
OkcQuarterly = float(okcUSDFUTQUARTER())
159+
#BITVC CNY FUTURES
160+
BitVCWeekly = float(bitVCFUTWEEK())
161+
BitVCBIWeekly = float(bitVCFUTBIWEEK())
162+
BitVCQUARTERLY = float(bitVCFUTQUARTERLY())
163+
164+
165+
166+
#Averages
167+
average1 = bfxUSDLive + btstampUSDLive + coinbUSDLive + krakenUSDLive + btceUSDLive + okcoinUSDSPOT
168+
average2 = OkcWeekly + OkcBiWeekly + OkcQuarterly
169+
average3 = BitVCWeekly + BitVCBIWeekly + BitVCQUARTERLY
170+
171+
172+
173+
#okcoinUSDLive = float(okcoin())
174+
175+
176+
#okcFutLive = float(okcoinFut())
177+
print ("#######################################################################")
178+
print ("=-=-=-=-=-=-=-=-=-=-=-=-=Spot Prices=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=")
179+
print ("Bitstamp Price in USD =", btstampUSDLive)
180+
print ("Bitfinex Price in USD =", bfxUSDLive)
181+
print ("Kraken Price in USD =", krakenUSDLive)
182+
print ("Coinbase Price in USD =", coinbUSDLive)
183+
print ("BTC-e Price in USD =", btceUSDLive)
184+
print ("Coinsetter Price in USD =", CoinsetterUSD)
185+
print ("OKCoin.com Price in USD =", okcoinUSDSPOT)
186+
print ("QuadrigaCX Price in USD =", QuadrigaUSD)
187+
print ("=-=-=-=-=-=-=-=-=-=-=CNY Spot Prices=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=")
188+
print ("OKCoin.cn Price in CNY =", okcoinCNYSPOT)
189+
#print ("BTCCHINA Price in CNY =", btcchinaCNY)
190+
print ("=-=-=-=-=-=-=-=-=-=-=CAD Spot Prices=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=")
191+
print ("QuadrigaCX Price in CAD =", QuadrigaCAD)
192+
print ("Average of Stamp/BFX/Coinbase/Kraken/BTC-e/OKCoin ", average1 / 6)
193+
print ("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=")
194+
print ("Difference betweeen Bitfinex and Bitstamp", bfxUSDLive - btstampUSDLive)
195+
print ("Difference betweeen Coinbase and Bitstamp", coinbUSDLive - btstampUSDLive)
196+
print ("Difference betweeen Bitstamp and BTC-e", btstampUSDLive - btceUSDLive)
197+
print ("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=")
198+
print ("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=")
199+
print ("#######################################################################")
200+
print ("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=")
201+
print ("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=")
202+
print ("=-=-=-=-=-=-=-=-=-=-=-=-=OKCOIN FUTURES IN USD=-=-=-=-=-=-=-=-=-=-=-=-=")
203+
print ("Weekly Futures Last Price =", OkcWeekly)
204+
print ("Bi-Weekly Futures Last Price =", OkcBiWeekly)
205+
print ("Quarterly Futures Last Price =", OkcQuarterly)
206+
print ("Average of all Futures Contract Types ", average2 / 3)
207+
print ("=-=-=-=-=-=-=-=-=-=-=-=-=BITVC FUTURES IN CNY=-=-=-=-=-=-=-=-=-=-=-=-=")
208+
print ("Weekly Futures Last Price =", BitVCWeekly)
209+
print ("Bi-Weekly Futures Last Price =", BitVCBIWeekly)
210+
print ("Quarterly Futures Last Price =", BitVCQUARTERLY)
211+
print ("Average of all Futures Contract Types ", average3 / 3)
212+
print ("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=")
213+
214+
time.sleep(15)
215+
216+
217+
218+
219+
220+
221+
222+
223+
224+
225+
226+
227+
228+
229+
230+

0 commit comments

Comments
 (0)