问题描述
我希望创建一个基于 Python 的三角套利算法。我查看过的所有资源都与 Binace 等上的 Coin Exchanges 相关。我只是在寻找一个“引擎”,因为我可以简单地提供矩阵表(或任何其他选项,将不胜感激)
我正在编写我从 stackoverflow 中删除的代码(如下所示)
from typing import Tuple,List
from math import log
'''
rates = [
[1,0.23,0.26,17.41],[4.31,1,1.14,75.01],[3.79,0.88,65.93],[0.057,0.013,0.015,1],'''
rates = [
[1,2363.353782,1492.716318,7844.449626,10.980451,75149.558747],[0.00042,0.634884,3.309109,0.004684,32.1756],[0.0006,1.5656,5.2004,0.007319,50.117612],[0.000126,0.300385,0.191139,0.001401,9.603383],[0.0897,211.9355,135.762445,706.204,6785.758382],[0.0000001,0.0308,0.019833,0.1035,0.000146,]
currencies = ('YFIN','YFLR','xUSD','FXRP','FLTC','FDOGE')
#currencies = ('PLN','EUR','USD','RUB')
def negate_logarithm_convertor(graph: Tuple[Tuple[float]]) -> List[List[float]]:
''' log of each rate in graph and negate it'''
result = [[-log(edge) for edge in row] for row in graph]
return result
def arbitrage(currency_tuple: tuple,rates_matrix: Tuple[Tuple[float,...]]):
''' Calculates arbitrage situations and prints out the details of this calculations'''
trans_graph = negate_logarithm_convertor(rates_matrix)
# Pick any source vertex -- we can run Bellman-Ford from any vertex and get the right result
source = 0
n = len(trans_graph)
min_dist = [float('inf')] * n
min_dist[source] = source
# 'Relax edges |V-1| times'
for _ in range(n-1):
for source_curr in range(n):
for dest_curr in range(n):
if min_dist[dest_curr] > min_dist[source_curr] + trans_graph[source_curr][dest_curr]:
min_dist[dest_curr] = min_dist[source_curr] + trans_graph[source_curr][dest_curr]
# if we can still relax edges,then we have a negative cycle
for source_curr in range(n):
for dest_curr in range(n):
if min_dist[dest_curr] > min_dist[source_curr] + trans_graph[source_curr][dest_curr]:
#print(str(source_curr) + " END : " + str(dest_curr))
print('Found arbitrage: {0} --> {1}'.format(currency_tuple[source_curr],currency_tuple[dest_curr]))
if __name__ == "__main__":
arbitrage(currencies,rates)
输出:发现套利:FXRP --> YFLR
然而 - 这实际上并没有带来套利。
我正在寻找一个结果,无论“序列大小”如何,都可以提供所有可能的套利机会
希望结果示例: 'xUSD --> FXRP --> FLTC --> xUSD
我还看了: How to use Python and Pandas to find bests opportunities in triangular arbitrage 尽管这段代码看起来最终得到了修复,但它并没有解释套利过程。
所以我想知道是否有人有 python 套利计算的例子——而不是与所有加密货币交易所等的整个框架连接。
干杯
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)