写完这些,感觉自己蛮能折腾的~
想玩下ubuntu,把腾讯云的windows server 重装成ubuntu serve,摸索着通过ssh连接ubuntu
ubuntu serve只能terminator界面,由于工作的原因跑过linux,对terminator 界面已经不感冒了。
下面是火币otc的监控脚本,具体可以看这篇文章https://www.jianshu.com/p/ab85ee704836。(小修改)
在ubuntu上装了anaconda(装配也是遇到些坑,比如要用wget下载),默认不配置环境变量,找来自己配http://blog.csdn.net/m0_37041325/article/details/77169972
运行代码,又报错python Non-ASCII character '\xe5'
再搞定http://blog.csdn.net/gingerredjade/article/details/21878777
然后中文又没法显示,再改成英文输出
处理完若干问题之后,终于跑起来了,看到了结果
有没看到,1秒钟可以查询好多次,再对比下我自己电脑的。好几秒才查询一次。网速差距啊。。
image.png
虽然脚本跑起来了,但还有个问题:怎么停下来啊!!Ctrl+C不管用啊。
最后附上修改后的源码
import json
from urllib.request import Request, urlopen
import time
import pandas as pd
# coinID
btc = '1'
eth = '3'
usdt = '2'
# tradeType
buy = '1'
sell = '0'
def getPrice(coinID, tradeType):
huobiapi = "https://api-otc.huobi.pro/v1/otc/trade/list/public"
api_url = huobiapi + "?coinId=" + coinID + "&tradeType=" + tradeType + "¤tPage=1&payWay=&country=&merchant=1&online=1&range=0"
firefox_headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
request = Request( api_url, headers=firefox_headers )
html = urlopen( request )
data = html.read().decode( 'utf-8' )
dataJson = json.loads( data )
price = dataJson['data'][0]['price']
# print(price)
return price
i = 0
r = 0
log = pd.DataFrame()
while 1:
t = time.strftime( '%H:%M:%S', time.localtime( time.time() ) )
print( '当前时间:',t,'第',r,'次查询usdt报价' )
try:
usdt_buy = getPrice( coinID=usdt, tradeType=buy )
usdt_sell = getPrice( coinID=usdt, tradeType=sell )
print( '买价:',usdt_buy, '卖价:',usdt_sell )
usdt_chajia = round( usdt_buy - usdt_sell, 2 )
print( '差价:',usdt_chajia )
if usdt_chajia < 0:
i = i + 1
except:
pass
print( '发现价差', t, i )
r = r + 1
#time.sleep()
网友评论