Git Product home page Git Product logo

bybit-clj's Introduction

bybit-clj

A Clojure wrapper for the Bybit API, rest and websocket endpoints are available. Authentication and fastest json library is built in.

Docs

lein codox to generate docs in html format, is saved to docs/ folder in the root directory of this project.

Installation

Add the dependency to your project or build file.

Clojars Project

Usage

Quick Start

First, require it in the REPL:

(require '[bybit-clj.market :as bb-market])

Or in your application:

(ns my-app.core
  (:require [bybit-clj.ws :as bb-ws]))

The library is constructed similar to the Bybit API, for example, if you need to call a function that is under the Market tab. You will find that under bybit-clj.market.

Endpoints

Each function takes in a client, which requires a :url and optional authentication values (for private endpoints).

(...
(:require [bybit-clj.trade :as trade]
          [bybit-clj.market :as market]))

(def client {:url trade/url-trade-testnet
                  :key "key"
                  :secret "secret"})

(trade/place-order client "spot" "BTCUSDT" "Buy" "Limit" "0.001" {:price "30000"})

(trade/cancel-all-orders client "spot" {})

(trade/get-open-orders client "spot" {})

(market/get-time {:url market/url-market})

Websocket Feed

Heartbeat is currently not handled by choice, send a heartbeat packet every ~20 seconds to ensure connection.

opts is a map that takes the following keys:

  • :url - the websocket URL
  • :channels - vector of subscription strings eg. ["orderbook.50.BTCUSDT"]
  • :key - optional - your Bybit API key
  • :secret - optional - your Bybit API secret
  • :on-connect - optional - A unary function called after the connection has been established. The argument is a WebSocketSession.
  • :on-error - optional - A unary function called in case of errors. The argument is a Throwable describing the error.
  • :on-close - optional - A binary function called when the connection is closed. Arguments are an int status code and a String description of reason.
(def conn (create-websocket-connection 
   {:url "wss://stream.bybit.com/v5/public/spot"
    :channels ["orderbook.50.BTCUSDT" "publicTrade.BTCUSDT"]
    :on-receive (fn [x] (prn x))}))

(def conn (create-websocket-connection 
   {:url "wss://stream.bybit.com/v5/private"
    :key "invaluable-secret-key"
    :secret "my-super-secret-secret"
    :channels ["execution"]
    :on-receive (fn [x] (prn x))}))

bybit-clj's People

Contributors

freergit avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.