Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tothemoon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
tothemoon
Commits
1b914140
Commit
1b914140
authored
Jun 12, 2016
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add poller functions in Python for all exchanges
parents
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
api.py
api.py
+57
-0
No files found.
api.py
0 → 100644
View file @
1b914140
import
requests
class
APIError
(
RuntimeError
):
pass
def
get_check_status
(
errstr
,
url
,
*
args
):
r
=
requests
.
get
(
url
,
timeout
=
10.0
,
*
args
)
if
r
.
status_code
!=
200
:
raise
APIError
(
errstr
)
return
r
.
json
()
def
poll_btce
():
url
=
'https://btc-e.com/api/3/ticker/btc_usd'
return
float
(
get_check_status
(
'BTC-e'
,
url
)[
'btc_usd'
][
'last'
]),
'USD'
def
poll_coinbase
():
url
=
'https://api.gdax.com/products/BTC-USD/ticker'
return
float
(
get_check_status
(
'Coinbase'
,
url
)[
'price'
]),
'USD'
def
poll_bitstamp
():
url
=
'https://www.bitstamp.net/api/v2/ticker/btcusd/'
return
float
(
get_check_status
(
'Bitstamp'
,
url
)[
'last'
]),
'USD'
def
poll_bitfinex
():
url
=
'https://api.bitfinex.com/v1/pubticker/btcusd'
return
float
(
get_check_status
(
'Bitfinex'
,
url
)[
'last_price'
]),
'USD'
def
poll_btcchina
():
url
=
'https://data.btcchina.com/data/ticker?market=btccny'
return
float
(
get_check_status
(
'BTCChina'
,
url
)[
'ticker'
][
'last'
]),
'CNY'
def
poll_huobi
():
url
=
'http://api.huobi.com/staticmarket/ticker_btc_json.js'
return
float
(
get_check_status
(
'Huobi'
,
url
)[
'ticker'
][
'last'
]),
'CNY'
def
poll_okcoin
():
url
=
'https://www.okcoin.com/api/v1/ticker.do?symbol=btc_usd'
return
float
(
get_check_status
(
'OKcoin'
,
url
)[
'ticker'
][
'last'
]),
'CNY'
def
poll_kraken
():
url
=
'https://api.kraken.com/0/public/Ticker?pair=XXBTZEUR'
return
float
(
get_check_status
(
'Kraken'
,
url
)[
'result'
][
'XXBTZEUR'
][
'c'
][
0
]),
'EUR'
def
poll_coinmarketcap
():
url
=
'https://api.coinmarketcap.com/v1/ticker/bitcoin'
return
get_check_status
(
'Coinmarketcap'
,
url
)[
0
][
'market_cap_usd'
],
'USD'
if
__name__
==
'__main__'
:
print
'btc-e'
,
poll_btce
()
print
'coinbase'
,
poll_coinbase
()
print
'bitstamp'
,
poll_bitstamp
()
print
'bitfinex'
,
poll_bitfinex
()
print
'btcchina'
,
poll_btcchina
()
print
'huobi'
,
poll_huobi
()
print
'okcoin'
,
poll_okcoin
()
print
'kraken'
,
poll_kraken
()
print
'coinmarketcap'
,
poll_coinmarketcap
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment