Last active
May 17, 2018 07:08
-
-
Save liuqinh2s/c4a63d85b64d6abc3e6bb57f639a45fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while(True): | |
# 日线 | |
tradeDayLineURL = "https://www.aex.com/trade/getTradeDayLine.php?coinname=BTS&mk_type=bitcny" | |
tradeDayLineResponse = requests.post(tradeDayLineURL, headers=headers) | |
while tradeDayLineResponse.status_code!=200: | |
tradeDayLineResponse = requests.post(tradeDayLineURL, headers=headers) | |
dayContent = json.loads(tradeDayLineResponse.text) | |
dayListContent = list(dayContent) | |
dayLength = dayListContent.__len__() | |
# print(dayLength) | |
# 小时线 | |
tradeTimeLineURL = "https://www.aex.com/trade/getTradeTimeLine.php?coinname=BTS&mk_type=bitcny" | |
tradeTimeLineResponse = requests.post(tradeTimeLineURL, headers=headers) | |
while tradeTimeLineResponse.status_code!=200: | |
tradeTimeLineResponse = requests.post(tradeTimeLineURL, headers=headers) | |
hourContent = json.loads(tradeTimeLineResponse.text) | |
hourListContent = list(hourContent) | |
hourLength = hourListContent.__len__() | |
# print(hourLength) | |
dayMaxIndex=3 | |
dayMinIndex=4 | |
hourMaxIndex=3 | |
hourMinIndex=4 | |
three=3 | |
five=5 | |
dayMax = as_num(dayListContent[dayLength-three][dayMaxIndex]) | |
dayMin = as_num(dayListContent[dayLength-five][dayMinIndex]) | |
hourMax = as_num(hourListContent[hourLength-1][hourMaxIndex]) | |
hourMin = as_num(hourListContent[hourLength-1][hourMinIndex]) | |
# 市场挂单状况 | |
# marketURL = requests.post("https://api.aex.com/depth.php?c=bts&mk_type=bitcny", headers=headers, proxies=proxyDict) | |
marketResponse = requests.post("https://api.aex.com/depth.php?c=bts&mk_type=bitcny", headers=headers) | |
while marketResponse.status_code!=200: | |
marketResponse = requests.post("https://api.aex.com/depth.php?c=bts&mk_type=bitcny", headers=headers) | |
marketJson=json.loads(marketResponse.text) | |
print("算法:") | |
print("买:反打前三:当前价格高于前面三日最高价;卖:反打前五:当前价格比前面五日最低价格低") | |
print("判断是否买卖:") | |
isDetail=True | |
if canBuy: | |
msg="等待买入" | |
showDetailLog(isDetail, msg) | |
msg="前三天的最高价格依次是:" | |
showDetailLog(isDetail, msg) | |
dayCount = 1 | |
for i in range(dayLength - three, dayLength): | |
msg="第" + str(dayCount) + "天:" + str(dayListContent[i][dayMaxIndex]) | |
showDetailLog(isDetail, msg) | |
dayCount += 1 | |
if dayMax < as_num(dayListContent[i][dayMaxIndex]): | |
dayMax = as_num(dayListContent[i][dayMaxIndex]) | |
msg = "三天中最大值是:" + dayMax | |
showDetailLog(isDetail, msg) | |
msg = "当前价格是(取前一个小时的最低值为当前值):"+hourMin | |
showDetailLog(isDetail, msg) | |
buyPrice = marketJson["asks"][0][0] | |
strBuyPrice = str(buyPrice) | |
if hourMin>dayMax: | |
buy(1, strBuyPrice, "10", coinname, mk_type) | |
msg = "挂单成功,买入10个:"+coinname+",买入价格:"+strBuyPrice+",使用:"+mk_type+"支付" | |
print(msg) | |
showDetailLog(False, msg) | |
canBuy=False | |
canSale=True | |
if canSale: | |
msg = "等待卖出" | |
showDetailLog(isDetail, msg) | |
msg = "前五天的最低价格依次是:" | |
dayCount=1 | |
for i in range(dayLength - five, dayLength): | |
msg="第" + str(dayCount) + "天:" + str(dayListContent[i][dayMinIndex]) | |
showDetailLog(isDetail, msg) | |
dayCount += 1 | |
if dayMin > as_num(dayListContent[i][dayMinIndex]): | |
dayMin = as_num(dayListContent[i][dayMinIndex]) | |
msg = "五天中的最小值是:"+ dayMin | |
showDetailLog(isDetail, msg) | |
msg= "当前价格是(取前一个小时的最低值为当前值):" + hourMax | |
showDetailLog(isDetail, msg) | |
salePrice = marketJson["bids"][0][0] | |
strSalePrice = str(salePrice) | |
if hourMax<dayMin: | |
sale(2, strSalePrice, "10", coinname, mk_type) | |
msg = "挂单成功,卖出10个:" + coinname + ",卖出价格:"+strSalePrice+",使用:" + mk_type + "收款" | |
print(msg) | |
showDetailLog(False, msg) | |
canBuy=True | |
canSale=False | |
msg = "开始睡眠一个小时,当前时间是:" | |
showDetailLog(isDetail, msg) | |
msg = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) | |
showDetailLog(isDetail, msg) | |
time.sleep(3600) | |
msg = "一个小时过去了,当前时间是:" | |
showDetailLog(isDetail, msg) | |
msg = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) | |
showDetailLog(isDetail, msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment