INNER CODE UNIT · Python

close_enough_match

hadialaddin/crypto-genie · crypto-genie.py:166

def close_enough_match(price1, price2, size1, size2, positionType=False):
    # price1 is the fixed target and price2 is the dynamic one being checked
    if positionType=="Buy":
        price_matches = price2 <= price1 # Price can be at the exact level or closer to entry
    elif positionType=="Sell":
        price_matches = price2 >= price1 # Price can be at the exact level or closer to entry
    else:
        price_matches = price2 == price1
    size_matches = size1 == size2 or math.floor(size1 * 10)/10.0 == size2 or math.floor(size1 * 100)/100.0 == size2 or math.floor(size1 * 1000)/1000.0 == size2 or math.floor(size1 * 10000)/10000.0 == size2
    return price_matches and size_matches

def round_to_tick(price,tick_size):
    decimals_count = str(tick_size)[::-1].find('.') # Tick Size number of decimals
    return round(round(float(price)/float(tick_size))*float(tick_size), decimals_count)


###### ByBit Base Endpoints (only edit if they don't match the currently published ones by ByBit at: https://bybit-exchange.github.io/docs/linear/#t-websocket
wsURL_USDT_mainnet = "wss://stream.bybit.com/realtime_private"

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…