Skip to content

Commit d8d9072

Browse files
committed
Add buy orders
1 parent e1eafb3 commit d8d9072

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ python3 main.py
2828

2929
Example output on Binance:
3030
```
31-
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
3231
-------------------------------------------
33-
Start by selling QKC to USDT then sell USDT to BTC and finally sell BTC to QKC to make a profit 3.0077136787178382%
32+
New 1.0354% binance opportunity:
33+
1. sell WIN/BNB
34+
2. sell BNB/BRL
35+
3. buy WIN/BRL
3436
-------------------------------------------
3537
```
3638

main.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import octobot_commons.symbols as symbols
44
import octobot_commons.os_util as os_util
55

6-
import triangular_arbitrage.detector
6+
import triangular_arbitrage.detector as detector
77

88
if __name__ == "__main__":
99
benchmark = os_util.parse_boolean_environment_var("IS_BENCHMARKING", "False")
@@ -14,13 +14,23 @@
1414
# start arbitrage detection
1515
print("Scanning...")
1616
exchange_name = "binance"
17-
best_opportunities, best_profit = asyncio.run(triangular_arbitrage.detector.run_detection(exchange_name))
17+
best_opportunities, best_profit = asyncio.run(detector.run_detection(exchange_name))
1818
def opportunity_symbol(opportunity):
1919
return symbols.parse_symbol(str(opportunity.symbol))
2020

21+
def get_order_side(opportunity: detector.ShortTicker):
22+
return 'buy' if opportunity.reversed else 'sell'
23+
24+
def get_symbol(opportunity: detector.ShortTicker):
25+
if opportunity.reversed:
26+
return str(symbols.Symbol(f"{opportunity.symbol.quote}/{opportunity.symbol.base}"))
27+
return str(opportunity.symbol)
28+
2129
# Display arbitrage detection result
2230
print("-------------------------------------------")
23-
print(f"[{exchange_name}] Start by selling {str(opportunity_symbol(best_opportunities[0]).base)} to {str(opportunity_symbol(best_opportunities[0]).quote)} then sell {str(opportunity_symbol(best_opportunities[1]).base)} to {str(opportunity_symbol(best_opportunities[1]).quote)} and finally sell {str(opportunity_symbol(best_opportunities[2]).base)} to {str(opportunity_symbol(best_opportunities[2]).quote)} to make a profit of {(best_profit - 1) * 100}%")
31+
print(f"New {round(best_profit, 4)}% {exchange_name} opportunity:")
32+
for i in range(3):
33+
print(f"{i+1}. {get_order_side(best_opportunities[i])} {get_symbol(best_opportunities[i])}")
2434
print("-------------------------------------------")
2535

2636
if benchmark:

triangular_arbitrage/detector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
class ShortTicker:
1414
symbol: symbols.Symbol
1515
last_price: float
16+
reversed: bool = False
1617

1718

1819
async def fetch_tickers(exchange):
@@ -63,17 +64,17 @@ def get_opportunity_symbol(a, b):
6364
if not a_to_b:
6465
b_to_a = ticker_dict.get(get_opportunity_symbol(b,a))
6566
if b_to_a:
66-
a_to_b = ShortTicker(get_opportunity_symbol(a,b), 1/b_to_a.last_price)
67+
a_to_b = ShortTicker(symbols.Symbol(get_opportunity_symbol(a,b)), 1/b_to_a.last_price, reversed=True)
6768

6869
if not b_to_c:
6970
c_to_b = ticker_dict.get(get_opportunity_symbol(c,b))
7071
if c_to_b:
71-
b_to_c = ShortTicker(get_opportunity_symbol(b,c), 1/c_to_b.last_price)
72+
b_to_c = ShortTicker(symbols.Symbol(get_opportunity_symbol(b,c)), 1/c_to_b.last_price, reversed=True)
7273

7374
if not c_to_a:
7475
a_to_c = ticker_dict.get(get_opportunity_symbol(a,c))
7576
if a_to_c:
76-
c_to_a = ShortTicker(get_opportunity_symbol(c,a), 1/a_to_c.last_price)
77+
c_to_a = ShortTicker(symbols.Symbol(get_opportunity_symbol(c,a)), 1/a_to_c.last_price, reversed=True)
7778

7879
if not all([a_to_b, b_to_c, c_to_a]):
7980
continue

0 commit comments

Comments
 (0)