Coinmonks

Coinmonks is a non-profit Crypto Educational Publication. Other Project — https://coincodecap.com/…

Follow publication

Member-only story

Automating Profits with Crypto Arbitrage Bot

Print money with a crypto arb bot

Fadai Mammadov
Coinmonks
Published in
6 min readNov 4, 2024

Crypto arbitrage bot. Part 2

You can read the first part of the series here.

The function calculate_profit_with_fees_and_slippage calculates the potential profit from buying a cryptocurrency on one exchange and selling it on another, taking into account slippage, withdrawal fees, and trading fees.

def calculate_profit_with_fees_and_slippage(buy_exchange, sell_exchange, buy_price, sell_price, amount, withdrawal_fees, trading_fees, symbol, buy_order_book, sell_order_book):
try:
# Estimate slippage
buy_slippage = estimate_slippage(buy_order_book, amount, 'buy')
sell_slippage = estimate_slippage(sell_order_book, amount, 'sell')

# Adjust prices for slippage
adjusted_buy_price = buy_price * (1 + buy_slippage)
adjusted_sell_price = sell_price * (1 - sell_slippage)

buy_fee_rate = trading_fees.get(buy_exchange, {}).get(symbol, {}).get('taker', 0.001)
if buy_fee_rate is None:
print(f"Warning: Using default taker fee for {buy_exchange} {symbol}")
buy_fee_rate = 0.001
buy_fee = amount * buy_fee_rate
coins_bought = (amount - buy_fee) / adjusted_buy_price

coin = symbol.split('/')[0]
withdrawal_fee = withdrawal_fees.get(buy_exchange, {}).get(coin, 0) or 0
coins_after_withdrawal = coins_bought - withdrawal_fee

sell_fee_rate = trading_fees.get(sell_exchange, {}).get(symbol…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Coinmonks
Coinmonks

Published in Coinmonks

Coinmonks is a non-profit Crypto Educational Publication. Other Project — https://coincodecap.com/ & Email — gaurav@coincodecap.com

No responses yet

Write a response