1 Star 0 Fork 39

fightThree/币安量化-网格交易

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
eth-run.py 2.47 KB
一键复制 编辑 原始数据 按行查看 历史
幸福村的码农 提交于 2021-02-21 10:08 . 调整信息
# -*- coding: utf-8 -*-
from app.BinanceAPI import BinanceAPI
from app.authorization import api_key,api_secret
from data.runBetData import RunBetData
from app.dingding import Message
import time
binan = BinanceAPI(api_key,api_secret)
runbet = RunBetData()
msg = Message()
class Run_Main():
def __init__(self):
self.coinType = runbet.get_cointype() # 交易币种
pass
def loop_run(self):
while True:
cur_market_price = binan.get_ticker_price(runbet.get_cointype()) # 当前交易对市价
grid_buy_price = runbet.get_buy_price() # 当前网格买入价格
grid_sell_price = runbet.get_sell_price() # 当前网格卖出价格
quantity = runbet.get_quantity() # 买入量
step = runbet.get_step() # 当前步数
if grid_buy_price >= cur_market_price: # 是否满足买入价
res = msg.buy_limit_msg(self.coinType, quantity, grid_buy_price)
if res['orderId']: # 挂单成功
runbet.set_ratio(runbet.get_cointype())
runbet.modify_price(grid_buy_price, step+1) #修改data.json中价格、当前步数
time.sleep(60*2) # 挂单后,停止运行1分钟
else:
break
elif grid_sell_price < cur_market_price: # 是否满足卖出价
if step==0: # setp=0 防止踏空,跟随价格上涨
runbet.modify_price(grid_sell_price,step)
else:
res = msg.sell_limit_msg(self.coinType, runbet.get_quantity(False), grid_sell_price)
if res['orderId']:
runbet.set_ratio(runbet.get_cointype())
runbet.modify_price(grid_sell_price, step - 1)
time.sleep(60*2) # 挂单后,停止运行1分钟
else:
break
else:
print("当前市价:{market_price}。未能满足交易,继续运行".format(market_price = cur_market_price))
if __name__ == "__main__":
instance = Run_Main()
try:
instance.loop_run()
except Exception as e:
error_info = "报警:币种{coin},服务停止.错误原因{info}".format(coin=instance.coinType,info=str(e))
msg.dingding_warn(error_info)
# 调试看报错运行下面,正式运行用上面
# if __name__ == "__main__":
# instance = Run_Main()
# instance.loop_run()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/fightThree/binance-quantization.git
git@gitee.com:fightThree/binance-quantization.git
fightThree
binance-quantization
币安量化-网格交易
master

搜索帮助