Loading ...

基于交易所延时的侧面高频

Author: 科莫多的巨蜥, Created: 2021-04-05 13:40:54, Updated: 2021-04-05 13:53:11

在Soul上听一个大佬说有一种侧面高频容量蛮大的,然后就啪的一下啊。分享给我了,就是,去ping交易所,ping回来的延时大的话,就代表有很多程序在下单(并不是)就无脑开一个多单。我也不知道为啥通过ping能确定方向。听了后感觉醍醐灌顶(脑洞好大)。然后,把它写成程序测试了一下。结果,大意了啊,直接在BTC上跑,亏钱了。也找了一些大佬了解了一下。发现浙好像是前几年比较流行的高频策略,但是近几年交易所的基础设施都在加强,这类机会就蛮少的。但是,BTC不能跑不代表其他币种不行。 于是用python撸了一个,去交易所访问询价询余额接口,返回的价格延时高于一定的值的时候就发一个邮件提醒自己。同时保存xlsx数据(用来分析)以下是结果和代码(标的选的是以太坊反正结果还阔以,图片在评论区Emm硕大的两张)代码如下:

import time
import ccxt
import send_mail
from threading import Thread
# 导入CSV安装包
import csv
import datetime
import xlsxwriter as xw
import sys

workbook= xw.Workbook("log.xlsx")
worksheet1=workbook.add_worksheet("sheet1")

worksheet1.activate()
title=["时间","交易所","延时","当前价格"]
worksheet1.write_row('A1',title)
i=2
i_save= 3600  # 多少次保存一次


# 1. 创建文件对象
#f = open('log.csv','w',encoding='utf-8')

# 2. 基于文件对象构建 csv写入对象
#csv_writer = csv.writer(f)

# 3. 构建列表头
#csv_writer.writerow(["时间","交易所","延时"])

# ccxt参考: http://cw.hubwiz.com/card/c/ccxt-dev-manual/1/8/3/
exchange_id = 'binance'
exchange_class = getattr(ccxt, exchange_id)
exchange = exchange_class({
    'apiKey': 'xxx',
    'secret': 'xxx',
    'timeout': 30000,
    'enableRateLimit': True,
})

apikey = "xxxx"
secretkey = "xxx"
password="xxx"

okex=ccxt.okex({
    'apiKey':apikey,
    'secret':secretkey,
    'password':password
})

# save = []
def test(ex):
    t1 = time.time()
    ex.fetch_balance()
    t2 = time.time()
    return (t2-t1)*1000

def run(ex,st):
    global i,i_save
    while True:
        time.sleep(1)  # 十五秒测一次ping
        save = (test(ex))
        tick = exchange.fetchTicker("ETH/USDT", params={})["last"]
        insertData =[str(datetime.datetime.now()),str(st),str(save),str(tick)]
        row = 'A' + str(i)
        print(i)
        worksheet1.write_row(row, insertData)
        i += 1
        if i > i_save:
            break
        if save > 1500:
            send_mail.Send_Email("买入信号")
        print(([str(datetime.datetime.now()), st, save]))
    workbook.close()

t1 = Thread(target=run, args=(exchange,"Binance"))
t2 = Thread(target=run, args=(okex,"OKEX"))
t1.start()
t2.start()

import time
import ccxt
import send_mail
from threading import Thread
# 导入CSV安装包
import csv
import datetime
import xlsxwriter as xw
import sys

workbook= xw.Workbook("log.xlsx")
worksheet1=workbook.add_worksheet("sheet1")

worksheet1.activate()
title=["时间","交易所","延时","当前价格"]
worksheet1.write_row('A1',title)
i=2
i_save= 3600  # 多少次保存一次


# 1. 创建文件对象
#f = open('log.csv','w',encoding='utf-8')

# 2. 基于文件对象构建 csv写入对象
#csv_writer = csv.writer(f)

# 3. 构建列表头
#csv_writer.writerow(["时间","交易所","延时"])

# ccxt参考: http://cw.hubwiz.com/card/c/ccxt-dev-manual/1/8/3/
exchange_id = 'binance'
exchange_class = getattr(ccxt, exchange_id)
exchange = exchange_class({
    'apiKey': 'xxx',
    'secret': 'xxx',
    'timeout': 30000,
    'enableRateLimit': True,
})

apikey = "xxxx"
secretkey = "xxx"
password="xxx"

okex=ccxt.okex({
    'apiKey':apikey,
    'secret':secretkey,
    'password':password
})

# save = []
def test(ex):
    t1 = time.time()
    ex.fetch_balance()
    t2 = time.time()
    return (t2-t1)*1000

def run(ex,st):
    global i,i_save
    while True:
        time.sleep(1)  # 十五秒测一次ping
        save = (test(ex))
        tick = exchange.fetchTicker("ETH/USDT", params={})["last"]
        insertData =[str(datetime.datetime.now()),str(st),str(save),str(tick)]
        row = 'A' + str(i)
        print(i)
        worksheet1.write_row(row, insertData)
        i += 1
        if i > i_save:
            break
        if save > 1500:
            send_mail.Send_Email("买入信号")
        print(([str(datetime.datetime.now()), st, save]))
    workbook.close()

t1 = Thread(target=run, args=(exchange,"Binance"))
t2 = Thread(target=run, args=(okex,"OKEX"))
t1.start()
t2.start()
康来还行,和所有高频策略一样。在市场活跃的时候策略阔能能发挥的更加nice。 Emm其实还有很多方法,阔以拿延时做文章。比如对延时进行学习,在一些野鸡交易所延时高的时候去三大扔单子吃风险敞口。 或者延时高的时候去吃BTC期权的波动率。。等等。。。抛砖引玉。。~~逃了


More

wxhlzg 看完了 所以还是不明白为什么ping能确定方向。。。。。

Xueqiu Bot 学到了,感谢分享