1、代码:
import pandas as pd
import requests
import time
def get_USDCNY():
return requests.get('https://www.okcoin.com/api/v1/exchange_rate.do').json()['rate']
def get_bitmex_XBTZ16_askPrice():
bitmex_quarter_link = "https://www.bitmex.com/api/v1/quote?symbol=XBTZ16&count=2&reverse=true"
df1 = pd.read_json(bitmex_quarter_link)
bitmex_XBTZ16_askPrice = df1['askPrice'][0]
# bitmex_XBTZ16_askAmount = df1['askSize'][0]
# print "bitmex_XBTZ16_askPrice:", bitmex_XBTZ16_askPrice
# print "bitmex_XBTZ16_askAmount:", bitmex_XBTZ16_askAmount
return bitmex_XBTZ16_askPrice
def get_okcoin_quarter_bidPrice():
ok_quarter_link = "https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&contract_type=quarter"
df2 = pd.read_json(ok_quarter_link)
ok_quarter_bidPrice = df2['ticker']['buy']
# ok_quarter_bidAmount = df2['ticker'][0]
# print "ok_quarter_bidPrice:", ok_quarter_bidPrice
return ok_quarter_bidPrice
def get_okcoin_this_week_askPrice():
ok_this_week_link = "https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&contract_type=this_week"
df2 = pd.read_json(ok_this_week_link)
ok_this_week_askPrice = df2['ticker']['sell']
# ok_quarter_bidAmount = df2['ticker'][0]
# print "ok_quarter_bidPrice:", ok_quarter_bidPrice
return ok_this_week_askPrice
def get_okcoin_next_week_askPrice():
ok_next_week_link = "https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&contract_type=next_week"
df2 = pd.read_json(ok_next_week_link)
ok_next_week_askPrice = df2['ticker']['sell']
# ok_quarter_bidAmount = df2['ticker'][0]
# print "ok_quarter_bidPrice:", ok_quarter_bidPrice
return ok_next_week_askPrice
def get_okcoin_next_week_bidPrice():
ok_next_week_link = "https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&contract_type=next_week"
df2 = pd.read_json(ok_next_week_link)
ok_next_week_bidPrice = df2['ticker']['buy']
# ok_quarter_bidAmount = df2['ticker'][0]
# print "ok_quarter_bidPrice:", ok_quarter_bidPrice
return ok_next_week_bidPrice
def get_okcoin_spot_askPrice():
ok_spot_link = "https://www.okcoin.cn/api/v1/ticker.do?symbol=btc_cny"
df2 = pd.read_json(ok_spot_link)
ok_spot_askPrice = df2['ticker']['sell']
# ok_quarter_bidAmount = df2['ticker'][0]
# print "ok_quarter_bidPrice:", ok_quarter_bidPrice
return ok_spot_askPrice
def quarter_price_gap():
ok_quarter_bidPrice = get_okcoin_quarter_bidPrice()
bitmex_XBTZ16_askPrice = get_bitmex_XBTZ16_askPrice()
price_gap = (ok_quarter_bidPrice - bitmex_XBTZ16_askPrice) * get_USDCNY()
return price_gap
def ok_this_week_VS_quarter_price_gap():
ok_quarter_bidPrice = get_okcoin_quarter_bidPrice()
ok_this_week_askPrice = get_okcoin_this_week_askPrice()
price_gap = (ok_quarter_bidPrice - ok_this_week_askPrice) * get_USDCNY()
return price_gap
def ok_spot_VS_quarter_price_gap():
ok_quarter_bidPrice = get_okcoin_quarter_bidPrice()
ok_spot_askPrice = get_okcoin_spot_askPrice()
price_gap = (ok_quarter_bidPrice * get_USDCNY() - ok_spot_askPrice)
return price_gap
def ok_this_week_VS_next_week_price_gap():
ok_next_week_bidPrice = get_okcoin_next_week_bidPrice()
ok_this_week_askPrice = get_okcoin_this_week_askPrice()
price_gap = (ok_next_week_bidPrice - ok_this_week_askPrice)* get_USDCNY()
return price_gap
def ok_spot_VS_next_week_price_gap():
ok_spot_askPrice = get_okcoin_spot_askPrice()
ok_next_week_bidPrice = get_okcoin_next_week_bidPrice()
price_gap = (ok_next_week_bidPrice * get_USDCNY() - ok_spot_askPrice)
return price_gap
def ok_next_week_VS_quarter_price_gap():
ok_quarter_bidPrice = get_okcoin_quarter_bidPrice()
ok_next_week_askPrice = get_okcoin_next_week_askPrice()
price_gap = (ok_quarter_bidPrice - ok_next_week_askPrice ) * get_USDCNY()
return price_gap
if __name__ == '__main__':
while 1:
print ("======================================================")
print ("ok_quarter VS bitmex quarter:", quarter_price_gap())
print ("ok_this_week VS ok_quarter:", ok_this_week_VS_quarter_price_gap())
print ("ok_spot VS ok_quarter:", ok_spot_VS_quarter_price_gap())
print ("ok_this_week VS ok_next_week:", ok_this_week_VS_next_week_price_gap())
print ("ok_spot VS ok_next_week:", ok_spot_VS_next_week_price_gap())
print ('ok_next_week VS ok_quarter:', ok_next_week_VS_quarter_price_gap())
print ("======================================================")
time.sleep(2)
PS: 图是另一个数据比对程序,仅供参考。