-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharbitraj_01.py
177 lines (150 loc) · 7.73 KB
/
arbitraj_01.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import json
import time
from datetime import datetime
from decimal import Decimal
import botfunction as func
from botclass import BinanceBookTicker as tickerClass
from botclass import TriangularPair as pairClass
from botclass import TestArbitraj as testClass
"""
Uclu arbitraj bot
"""
def main():
db = func.connectDB()
dbCursor = db.cursor()
# Read binance section from config.ini
binanceConfig = func.readConfig(filename="config.ini", section="binance")
url_book_ticker = binanceConfig["url_base"] + binanceConfig["url_book_ticker"]
test = testClass()
ticker = tickerClass()
ticker.dbCursor = dbCursor
start_time = time.time()
bakiye = Decimal(1000)
toplam = 0
adet = 0
komisyon = Decimal(0.00225)
arbitrajSabiti = 1 + komisyon
pair = pairClass()
pair.dbCursor = dbCursor
pairRows = pair.readAllPair(exchangeId=1, refSymbol="BUSD")
if (pairRows is not None) and (len(pairRows) > 0):
while True:
#print("*****************************")
for pairRow in pairRows:
rec = json.loads(pairRow[0])
aSymbol = rec["pair_a_symbol"]
bSymbol = rec["pair_b_symbol"]
cSymbol = rec["pair_c_symbol"]
symbols = [aSymbol, bSymbol, cSymbol]
ticker.symbols = symbols
while True:
tickerRows = ticker.getData(url=url_book_ticker)
for tickerRow in tickerRows:
if aSymbol == tickerRow["symbol"]:
aBidPrice = Decimal(tickerRow["bidPrice"])
aBidQty = Decimal(tickerRow["bidQty"])
aAskPrice = Decimal(tickerRow["askPrice"])
aAskQty = Decimal(tickerRow["askQty"])
if bSymbol == tickerRow["symbol"]:
bBidPrice = Decimal(tickerRow["bidPrice"])
bBidQty = Decimal(tickerRow["bidQty"])
bAskPrice = Decimal(tickerRow["askPrice"])
bAskQty = Decimal(tickerRow["askQty"])
if cSymbol == tickerRow["symbol"]:
cBidPrice = Decimal(tickerRow["bidPrice"])
cBidQty = Decimal(tickerRow["bidQty"])
cAskPrice = Decimal(tickerRow["askPrice"])
cAskQty = Decimal(tickerRow["askQty"])
AlAlSatOran = (1/aAskPrice) * (1/bAskPrice) * cBidPrice
AlSatSatOran = (1/cAskPrice) * bBidPrice * aBidPrice
# print(f"aPair: {aSymbol} bPair: {bSymbol} cPair: {cSymbol} AL_AL_SAT: {AlAlSatOran} "
# f"AL_SAT_SAT: {AlSatSatOran}")
if AlAlSatOran > arbitrajSabiti:
aMaxPrice = aAskPrice * aAskQty
bMaxPrice = bAskPrice * aAskPrice * bAskQty
cMaxPrice = cBidPrice * cBidQty
islemTutar = min(aMaxPrice, bMaxPrice, cMaxPrice)
toplam = toplam + AlAlSatOran - arbitrajSabiti
adet = adet + 1
print(f"{aSymbol} - {bSymbol} - {cSymbol} AL_AL_SAT: {AlAlSatOran} "
f" Kar: {(AlAlSatOran - arbitrajSabiti)} tutar: {islemTutar} Toplam: {toplam} Adet: {adet} "
f"Saat: {datetime.now().strftime('%H:%M:%S.%f')} Sn: {time.time()} ")
test.borsa_id = 1
test.apair = aSymbol
test.abase = aSymbol
test.aquote = aSymbol
test.abid_price = aBidPrice
test.aask_price = aAskPrice
test.abid_qty = aBidQty
test.aask_qty = aAskQty
test.bpair = bSymbol
test.bbase = bSymbol
test.bquote = bSymbol
test.bbid_price = bBidPrice
test.bask_price = bAskPrice
test.bbid_qty = bBidQty
test.bask_qty = bAskQty
test.cpair = cSymbol
test.cbase = cSymbol
test.cquote = cSymbol
test.cbid_price = cBidPrice
test.cask_price = cAskPrice
test.cbid_qty = cBidQty
test.cask_qty = cAskQty
test.yontem = "AL_AL_SAT"
test.capraz = AlAlSatOran
test.islemTutar = islemTutar
test.komisyon = arbitrajSabiti
test.kar = AlAlSatOran - arbitrajSabiti
test.prg = "arbitraj_01"
test.islzaman = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
test.zamanstr = datetime.now().strftime('%H:%M:%S.%f')
test.addData(dbCursor=dbCursor)
if AlSatSatOran > arbitrajSabiti:
cMaxPrice = cAskPrice * cAskQty
bMaxPrice = bBidPrice * aBidPrice * bBidQty
aMaxPrice = aBidPrice * aBidQty
islemTutar = min(aMaxPrice, bMaxPrice, cMaxPrice)
toplam = toplam + AlSatSatOran - arbitrajSabiti
adet = adet + 1
print(f"{aSymbol} - {bSymbol} - {cSymbol} AL_SAT_SAT: {AlSatSatOran} "
f" Kar: {(AlSatSatOran - arbitrajSabiti)} tutar: {islemTutar} Toplam: {toplam} Adet: {adet} "
f"Saat: {datetime.now().strftime('%H:%M:%S.%f') } Sn: {time.time()} ")
test.borsa_id = 1
test.apair = aSymbol
test.abase = aSymbol
test.aquote = aSymbol
test.abid_price = aBidPrice
test.aask_price = aAskPrice
test.abid_qty = aBidQty
test.aask_qty = aAskQty
test.bpair = bSymbol
test.bbase = bSymbol
test.bquote = bSymbol
test.bbid_price = bBidPrice
test.bask_price = bAskPrice
test.bbid_qty = bBidQty
test.bask_qty = bAskQty
test.cpair = cSymbol
test.cbase = cSymbol
test.cquote = cSymbol
test.cbid_price = cBidPrice
test.cask_price = cAskPrice
test.cbid_qty = cBidQty
test.cask_qty = cAskQty
test.yontem = "AL_SAT_SAT"
test.capraz = AlSatSatOran
test.islemTutar = islemTutar
test.komisyon = arbitrajSabiti
test.kar = AlSatSatOran - arbitrajSabiti
test.prg = "arbitraj_01"
test.islzaman = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
test.zamanstr = datetime.now().strftime('%H:%M:%S.%f')
test.addData(dbCursor=dbCursor)
# sonraki kaydı oku, aksi takdirde aynı kaydı oku arbitraj devam ediyor mu kontrol et
if (AlAlSatOran <= arbitrajSabiti) and (AlSatSatOran <= arbitrajSabiti):
break
print(f"Toplam süre: {(time.time() - start_time) / 60} dakika ")
print(f"Toplam tutar: {toplam} adet: {adet}")
# print(f"Çekilen kayıt sayısı: {len(symbolRows)}")
main()