-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTradingPairGenerator.py
123 lines (90 loc) · 3.23 KB
/
TradingPairGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 14 14:27:09 2018
@author: nathanielastudillo
"""
import requests
import json
import time
import numpy as np
'''
Functions to get lists of pairs from each of the 3 arbitrage exchanges
'''
def BFNXpairs():
'''
This function returns a list of pairs from Bitfinex
All lowercase, format of base currency then market currency
'''
index = 0
BFNXsymbolsURL = "https://api.bitfinex.com/v1/symbols_details" #url to pass to response object
BFNXpairResponse = requests.get(BFNXsymbolsURL) #pull JSON from Bitfinex and store it in Request object
responsedict = json.loads(BFNXpairResponse.text) #turn the JSON stored in Request object into a dictionary
pairlistBFNX = [] #list to store pairs on Bitfinex
for thing in responsedict: #storing pairs from BFNX as a list
pairlistBFNX.append(responsedict[index]['pair'])
index += 1
return pairlistBFNX
def HITBTCpairs():
'''
This function returns a list of pairs from HITBtc
All uppercase, base currency second, market currency first
'''
index = 0
symbolURL = 'https://api.hitbtc.com/api/2/public/symbol'
pairResponse = requests.get(symbolURL)
responsedict = json.loads(pairResponse.text)
pairlistHITBTC = []
for thing in responsedict:
pairlistHITBTC.append(responsedict[index]['id'])
index += 1
return pairlistHITBTC
def BITTREXpairs():
'''
This function returns a list of pairs from BITTREX
BITTREX RESTapi returns JSON with 'MarketCurrency' and 'BaseCurrency' keys
'''
index = 0
symbolURL = 'https://bittrex.com/api/v1.1/public/getmarkets'
pairResponse = requests.get(symbolURL)
responsedict = json.loads(pairResponse.text)
pairlist = []
for thing in responsedict['result']:
pairlist.append(responsedict['result'][index]['MarketName'])
index += 1
return pairlist
BFNXpairs = BFNXpairs()
HITBTCpairs = HITBTCpairs()
BITTREXpairs = BITTREXpairs()
print(BFNXpairs)
print(HITBTCpairs)
commonpairs = []
for pair in BFNXpairs:
if pair.upper() in HITBTCpairs:
commonpairs.append(pair)
commondif = {}
difpercent = []
def BFNXprice(pair):
time.sleep(3)
BFNXbaseurl = 'https://api.bitfinex.com/v1/pubticker/'
response = requests.get(BFNXbaseurl + pair)
responsedict = json.loads(response.text)
x = responsedict['last_price']
print(x)
# y = float(x) if '.' in x else int(x)
return x
def HITBTCprice(pair):
HITBTCbaseurl = 'https://api.hitbtc.com/api/2/public/ticker/'
pair = pair.upper()
response = requests.get(HITBTCbaseurl + pair)
responsedict = json.loads(response.text)
x = responsedict['last']
# print(type(x))
# y = float(x) if '.' in x else int(x)
return x
for pair in commonpairs:
BFNXfloat = float(BFNXprice(pair))
HITBTCfloat = float(HITBTCprice(pair))
commondif[pair] = {'BFNX': BFNXfloat, 'HITBTC': HITBTCfloat, 'dif' : abs(BFNXfloat - HITBTCfloat)}
for key in commondif.keys():
print(key, (commondif[key]['dif'] / max(commondif[key]['BFNX'],commondif[key]['HITBTC']))*100)