diff --git a/.gitignore b/.gitignore index 68bc17f..7ee6f99 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +.DS_Store # PyInstaller # Usually these files are written by a python script from a template diff --git a/README.md b/README.md index a69a0b1..a5dc768 100644 --- a/README.md +++ b/README.md @@ -1,56 +1,51 @@ # AEVO 刷交易量程序 # 更新记录 + ## 2024/2/20 + 增加订单检测,每次交易完成检查是否空仓,如果不是空仓市价平仓并取消所有挂单。 # 项目介绍 -AEVO是一个去中心化衍生品交易平台,主要交易品种是永续合约和期权。项目前身是Ribbon Finance,项目获得了Paradigm、Dragonfly和Coinbase等资本方的投资,项目最近上合约的速度非常快,很多项目在。 - -项目原先发过一个RBN的代币,并且21年发过一次空投,平均一个地址空投了50万RMB。未来老币RBN将置换成AEVO,根据文档中的描述,项目代币中16%的代币用于激励(包括空投),AEVO代币总量10亿枚,按照目前RBN的币价,这部分价值8000万U左右。 - -项目最近上了一个按交易量空投的活动。空投根据用户的空投交易量发放,空投交易量=交易量*boost因子,boost因子根据最近的7天交易量计算,交易越多提升越高。 +AEVO 是一个去中心化衍生品交易平台,主要交易品种是永续合约和期权。项目前身是 Ribbon Finance,项目获得了 Paradigm、Dragonfly 和 Coinbase 等资本方的投资,项目最近上合约的速度非常快,很多项目在。 -具体的规则可以在这里查看:https://aevo.mirror.xyz/pVCrIjnPwDkC7h16vr_Ca__AdsXL31ZL2VylkICX0Ss +项目原先发过一个 RBN 的代币,并且 21 年发过一次空投,平均一个地址空投了 50 万 RMB。未来老币 RBN 将置换成 AEVO,根据文档中的描述,项目代币中 16%的代币用于激励(包括空投),AEVO 代币总量 10 亿枚,按照目前 RBN 的币价,这部分价值 8000 万 U 左右。 +项目最近上了一个按交易量空投的活动。空投根据用户的空投交易量发放,空投交易量=交易量\*boost 因子,boost 因子根据最近的 7 天交易量计算,交易越多提升越高。 +具体的规则可以在这里查看:https://aevo.mirror.xyz/pVCrIjnPwDkC7h16vr_Ca__AdsXL31ZL2VylkICX0Ss - -# AEVO账户准备 +# AEVO 账户准备 项目链接: - - 官方链接:https://app.aevo.xyz/perpetual/ilv - - 我的邀请链接:https://app.aevo.xyz/r/Roan-Elastic-Nakamoto +- 官方链接:https://app.aevo.xyz/perpetual/ilv +- 我的邀请链接:https://app.aevo.xyz/r/Roan-Elastic-Nakamoto -连接钱包后存入USDC,OP或者Arbitrum网络的都可以,费用都很低。 +连接钱包后存入 USDC,OP 或者 Arbitrum 网络的都可以,费用都很低。 ![image-20240219175549654](https://s2.loli.net/2024/02/19/nEeOGIydctkHRj9.png) ![image-20240219173411045](https://s2.loli.net/2024/02/19/DRpF82oZ3VP4NJy.png) +# 创建 API - -# 创建API - -API可以直接在网站上创建或通过代码创建, 钱包数量少可以直接在网页创建,钱包多的可以用我的代码批量创建。 +API 可以直接在网站上创建或通过代码创建, 钱包数量少可以直接在网页创建,钱包多的可以用我的代码批量创建。 ## 在网页中创建 访问:https://app.aevo.xyz/settings/api-keys -点击 Creaate API创建API,创建完成后可以点击API Key和APISecret复制。第一次复制Secret的时候需要在小狐狸签名确认。 +点击 Creaate API 创建 API,创建完成后可以点击 API Key 和 APISecret 复制。第一次复制 Secret 的时候需要在小狐狸签名确认。 ![image-20240219174644354](https://s2.loli.net/2024/02/19/4JVzcHrZMx9pE7X.png) ![image-20240219174946898](https://s2.loli.net/2024/02/19/Q4dzXfoL3S1e7B9.png) - - # 使用代码创建 -用create_apiKey.py代码可以批量创建API,按照data/input目录下的aevoAccount.csv编辑自己的钱包文件,然后将路径填写到代码中,然后运行create_apiKey.py即可。 +用 create_apiKey.py 代码可以批量创建 API,按照 data/input 目录下的 aevoAccount.csv 编辑自己的钱包文件,然后将路径填写到代码中,然后运行 create_apiKey.py 即可。 ![image-20240219180019364](https://s2.loli.net/2024/02/19/EIPhs8g4fT6coWS.png) @@ -64,7 +59,7 @@ API可以直接在网站上创建或通过代码创建, 钱包数量少可以直 首先在代码目录下创建一个`.env`文件,然后按照下面的格式填入账户信息 -``` bash +```bash SIGNING=钱包私钥 WALLETADDRESS=钱包地址 APIKEY=API_Key @@ -73,16 +68,21 @@ APISECRET=API_Seret ![image-20240220191231393](https://s2.loli.net/2024/02/20/VlC2LGamAzyvHht.png) +刷交易的程序是 aevo_trade.py,下图的配置部分根据实际情况进行配置,修改完毕后运行程序。 +![image-20240220191348102](https://s2.loli.net/2024/02/20/P2Dr1LE5fuJRxhI.png) -刷交易的程序是aevo_trade.py,下图的配置部分根据实际情况进行配置,修改完毕后运行程序。 - - +### 运行脚本 -![image-20240220191348102](https://s2.loli.net/2024/02/20/P2Dr1LE5fuJRxhI.png) +```bash +# 安装依赖 +pip install -r requirements.txt +# 运行脚本 +python aevo_market_price_trade.py +``` ## 程序代码 代码链接:https://github.com/shuail0/aevoTrading -作者推特:https://twitter.com/crypto0xLeo \ No newline at end of file +作者推特:https://twitter.com/crypto0xLeo diff --git a/aevo_market_price_trade.py b/aevo_market_price_trade.py index b9100e9..8db2913 100644 --- a/aevo_market_price_trade.py +++ b/aevo_market_price_trade.py @@ -13,7 +13,7 @@ load_dotenv() - +# 市价单 async def main(): # ==================== 交易配置 ==================== @@ -43,47 +43,51 @@ async def main(): async for msg in aevo.read_messages(): data = json.loads(msg)["data"] # 如果数据里包含ticker,就执行交易 - if "tickers" in data: - print('开始执行第{}次交易'.format(number + 1)) - instrument_id = markets[0]['instrument_id'] - bid_price = float(data["tickers"][0]['bid']['price']) - ask_price = float(data["tickers"][0]['ask']['price']) - price_step = float(markets[0]['price_step']) - price_decimals = len(str(price_step).split('.')[1]) - # 计算价差比例 - spread = (ask_price - bid_price) / bid_price - print(f'买一价:{bid_price}, 卖一价:{ask_price}, 价差比例:{spread}') - if spread < 0.0005: - print('价差比例小于0.05%,直接下市价单') - # 下市价卖单 - response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=False, limit_price=0, quantity=quantity, post_only=False) - print(response) - buy_order_price = round( ask_price * 1.02, price_decimals) - # 下市价买单单 - response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=True, limit_price=buy_order_price, quantity=quantity, post_only=False) - print(response) + try: + if "tickers" in data: + print('开始执行第{}次交易'.format(number + 1)) + instrument_id = markets[0]['instrument_id'] + bid_price = float(data["tickers"][0]['bid']['price']) + ask_price = float(data["tickers"][0]['ask']['price']) + price_step = float(markets[0]['price_step']) + price_decimals = len(str(price_step).split('.')[1]) + # 计算价差比例 + spread = (ask_price - bid_price) / bid_price + print(f'买一价:{bid_price}, 卖一价:{ask_price}, 价差比例:{spread}') + if spread < 0.0005: + print('价差比例小于0.05%,直接下市价单') + # 下市价卖单 + response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=False, limit_price=0, quantity=quantity, post_only=False) + print(response) + buy_order_price = round( ask_price * 1.02, price_decimals) + # 下市价买单单 + response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=True, limit_price=buy_order_price, quantity=quantity, post_only=False) + print(response) - print('第{}次交易结束'.format(number),'开始查询是否有未平仓位。') - account_info = aevo.rest_get_account() - positions = account_info['positions'] - if len(positions) > 0: - # 找出instrument_name等于交易资产的position - for position in positions: - if position['instrument_name'] == f'{tradeAsset}-PERP': - # 市价平仓 - instrument_id, cpquantity, side = position['instrument_id'], float(position['amount']), position['side'] - is_buy = True if side == 'sell' else False - limit_price = 2**200 - 1 if is_buy else 0 - print(f'存在未平仓位,开始平仓,并取消所有挂单。instrument_id: {instrument_id}, quantity: {cpquantity}, is_buy: {is_buy}, limit_price: {limit_price}') - response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=False, limit_price=limit_price, quantity=cpquantity, post_only=False) - aevo.rest_cancel_all_orders() - # 暂停5秒 - number += 1 - await asyncio.sleep(5) - - if number >= max_trade_number: - print('交易次数已达到上限,程序退出') - exit() + print('第{}次交易结束'.format(number),'开始查询是否有未平仓位。') + account_info = aevo.rest_get_account() + positions = account_info['positions'] + if len(positions) > 0: + # 找出instrument_name等于交易资产的position + for position in positions: + if position['instrument_name'] == f'{tradeAsset}-PERP': + # 市价平仓 + instrument_id, cpquantity, side = position['instrument_id'], float(position['amount']), position['side'] + is_buy = True if side == 'sell' else False + limit_price = 2**200 - 1 if is_buy else 0 + print(f'存在未平仓位,开始平仓,并取消所有挂单。instrument_id: {instrument_id}, quantity: {cpquantity}, is_buy: {is_buy}, limit_price: {limit_price}') + response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=False, limit_price=limit_price, quantity=cpquantity, post_only=False) + aevo.rest_cancel_all_orders() + # 暂停5秒 + number += 1 + await asyncio.sleep(5) + + if number >= max_trade_number: + print('交易次数已达到上限,程序退出') + exit() + except Exception as e: + print(e) + continue if __name__ == "__main__": asyncio.run(main()) diff --git a/aevo_trade.py b/aevo_trade.py index 8216ff7..d843d03 100644 --- a/aevo_trade.py +++ b/aevo_trade.py @@ -8,13 +8,13 @@ load_dotenv() - +# 限价单 async def main(): # ==================== 交易配置 ==================== tradeAsset = 'ETH' # 设置交易币种 quantity = 0.01 # 设置每次交易数量(单位:币) - max_trade_number = 20 # 设置刷交易的次数,开平仓为一次 + max_trade_number = 100 # 设置刷交易的次数,开平仓为一次 # =============================================== aevo = AevoClient( @@ -38,40 +38,44 @@ async def main(): async for msg in aevo.read_messages(): data = json.loads(msg)["data"] # 如果数据里包含ticker,就执行交易 - if "tickers" in data: - print('开始执行第{}次交易'.format(number + 1)) - bid_price = float(data["tickers"][0]['bid']['price']) - ask_price = float(data["tickers"][0]['ask']['price']) - price_step = float(markets[0]['price_step']) - price_decimals = len(str(price_step).split('.')[1]) - limit_price = round((bid_price + ask_price) / 2, price_decimals) - instrument_id = markets[0]['instrument_id'] - response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=True, limit_price=limit_price, quantity=quantity, post_only=False) - print(response) - response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=False, limit_price=limit_price, quantity=quantity, post_only=False) - print(response) - number += 1 - - print('第{}次交易结束'.format(number),'开始查询是否有未平仓位。') - account_info = aevo.rest_get_account() - positions = account_info['positions'] - if len(positions) > 0: - # 找出instrument_name等于交易资产的position - for position in positions: - if position['instrument_name'] == f'{tradeAsset}-PERP': - # 市价平仓 - instrument_id, quantity, side = position['instrument_id'], float(position['amount']), position['side'] - is_buy = True if side == 'sell' else False - limit_price = 2**200 - 1 if is_buy else 0 - print(f'存在未平仓位,开始平仓,并取消所有挂单。instrument_id: {instrument_id}, quantity: {quantity}, is_buy: {is_buy}, limit_price: {limit_price}') - response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=False, limit_price=limit_price, quantity=quantity, post_only=False) - aevo.rest_cancel_all_orders() - # 暂停5秒 - await asyncio.sleep(5) - - if number >= max_trade_number: - print('交易次数已达到上限,程序退出') - exit() - + try: + if "tickers" in data: + print('开始执行第{}次交易'.format(number + 1)) + bid_price = float(data["tickers"][0]['bid']['price']) + ask_price = float(data["tickers"][0]['ask']['price']) + price_step = float(markets[0]['price_step']) + price_decimals = len(str(price_step).split('.')[1]) + limit_price = round((bid_price + ask_price) / 2, price_decimals) + instrument_id = markets[0]['instrument_id'] + response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=True, limit_price=limit_price, quantity=quantity, post_only=False) + print(response) + response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=False, limit_price=limit_price, quantity=quantity, post_only=False) + print(response) + number += 1 + + print('第{}次交易结束'.format(number),'开始查询是否有未平仓位。') + account_info = aevo.rest_get_account() + positions = account_info['positions'] + if len(positions) > 0: + # 找出instrument_name等于交易资产的position + for position in positions: + if position['instrument_name'] == f'{tradeAsset}-PERP': + # 市价平仓 + instrument_id, quantity, side = position['instrument_id'], float(position['amount']), position['side'] + is_buy = True if side == 'sell' else False + limit_price = 2**200 - 1 if is_buy else 0 + print(f'存在未平仓位,开始平仓,并取消所有挂单。instrument_id: {instrument_id}, quantity: {quantity}, is_buy: {is_buy}, limit_price: {limit_price}') + response = aevo.rest_create_order(instrument_id=instrument_id, is_buy=False, limit_price=limit_price, quantity=quantity, post_only=False) + aevo.rest_cancel_all_orders() + # 暂停5秒 + await asyncio.sleep(5) + + if number >= max_trade_number: + print('交易次数已达到上限,程序退出') + exit() + except Exception as e: + print(e) + continue + if __name__ == "__main__": asyncio.run(main())