Class: Honeymaker::Exchanges::Bybit

Inherits:
Honeymaker::Exchange show all
Defined in:
lib/honeymaker/exchanges/bybit.rb

Constant Summary collapse

BASE_URL =
"https://api.bybit.com"

Constants inherited from Honeymaker::Exchange

Honeymaker::Exchange::ERROR_PATTERNS, Honeymaker::Exchange::OPTIONS

Instance Method Summary collapse

Methods inherited from Honeymaker::Exchange

#cache_ttl, #classify_error, #find_ticker, #get_price, #symbols, #tickers_info

Instance Method Details

#get_bid_ask(symbol) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/honeymaker/exchanges/bybit.rb', line 35

def get_bid_ask(symbol)
  with_rescue do
    response = connection.get("/v5/market/tickers") do |req|
      req.params = { category: "spot", symbol: symbol }
    end

    ticker = response.body["result"]["list"].first
    {
      bid: BigDecimal(ticker["bid1Price"]),
      ask: BigDecimal(ticker["ask1Price"])
    }
  end
end

#get_tickers_infoObject



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
# File 'lib/honeymaker/exchanges/bybit.rb', line 8

def get_tickers_info
  with_rescue do
    response = connection.get("/v5/market/instruments-info") do |req|
      req.params = { category: "spot" }
    end

    response.body["result"]["list"].filter_map do |product|
      lot_size_filter = product["lotSizeFilter"]
      price_filter = product["priceFilter"]

      {
        ticker: product["symbol"],
        base: product["baseCoin"],
        quote: product["quoteCoin"],
        minimum_base_size: lot_size_filter["minOrderQty"],
        minimum_quote_size: lot_size_filter["minOrderAmt"],
        maximum_base_size: lot_size_filter["maxOrderQty"],
        maximum_quote_size: lot_size_filter["maxOrderAmt"],
        base_decimals: Utils.decimals(lot_size_filter["basePrecision"]),
        quote_decimals: Utils.decimals(lot_size_filter["quotePrecision"]),
        price_decimals: Utils.decimals(price_filter["tickSize"]),
        available: product["status"] == "Trading"
      }
    end
  end
end