python的自由组合问题,我绞尽乳汁了。各位大佬来LOOKLOOK

python的自由组合问题,我绞尽乳汁了。各位大佬来LOOKLOOK

题目来源及自己的思路

{

"binance": [

"ETH/BTC",

"NEO/BTC",

"NEO/ETH",

"BNT/ETH",

"BCC/BTC",

"GAS/BTC",

"BTC/USDT",

"ETH/USDT"

],

"huo": [

"ETH/BTC",

"NEO/BTC",

"BNB/ETH",

"NEO/ETH"

],

"bitmex": [

"ETH/BTC",

"LTC/BTC",

"BNB/BTC"

]

}
需要组成三角循环体
{ "ETH/BTC":"binance","NEO/BTC":"binance","NEO/ETH":"binance"}
{ "ETH/BTC":"binance","NEO/BTC":"huo","NEO/ETH":"binance"}
{ "ETH/BTC":"bitmex","NEO/BTC":"binance","NEO/ETH":"binance"}
{ "ETH/BTC":"bitmex","NEO/BTC":"binance","NEO/ETH":"binance"}
等等所有可能的组合
每个字典里面的"ETH/BTC==NEO/BTC==NEO/ETH"就是三角套利的结构,我试过两种方案,第一种是把所有的"/"分割开,提取所有的单独数字货币名字做成列表,在把列表进行组合成三角模型去配对后面交易所的名字上去。不过匹配不完全,pass
第二种是也是做成所有可能列表去求差集,陷入死循环体,出不了结果。
各位大佬有什么好的方法

相关代码

All_bitlist = []
for exchange in bitlist:

exchange = list(data.values())

for Trading_Pair_list in exchange:

for Trading_Pair in Trading_Pair_list:

All_bitlist.extend(Trading_Pair.split("/", 2))

All_bitlist = list(set(All_bitlist))

Newlist = []
for Tbits in combinations(All_bitlist, 3):

Tbits = list(Tbits)

Newlist2 = []

for Trading_Pair in permutations(Tbits, 2):

x, y = Trading_Pair

Trading_Pair = x + "/" + y

Newlist2.append(Trading_Pair)

Newlist.append(Newlist2)

你期待的结果是什么?实际看到的错误信息又是什么?

一生气删了好多,各种删除调试。这是残存代码

以上是 python的自由组合问题,我绞尽乳汁了。各位大佬来LOOKLOOK 的全部内容, 来源链接: utcz.com/a/164750.html

回到顶部