Clojurescript wrapper for the 0xProject/connect library, which servers as a gateway to any relayer that conforms to the standard relayer API v0.
Add [district0x/cljs-0x-connect "1.0.0"]
into your project.clj.
This namespace includes functions for interacting with a set of HTTP endpoints that implement the standard relayer API.
All functions return a JS Promise. Usage example:
(ns my-district
(:require [cljs-0x-connect.http-client :as http-client]))
Returns a new HttpClient instance, takes API url string as an argument.
Example:
(def client (http-client/create-http-client "https://api.com/"))
Retrieves fee information from the API, takes a fees request map and an (optional) paging options map (defaults to {:page 1 :per-page: 100}
) as the arguments.
Retrieves orders information from the API, takes an order request map and an (optional) paging options map as the arguments.
Retrieves information about a specific order from the API, takes a hash of the order as an argument.
Retrieves orderbook information from the API, takes an orderbook request map and an (optional) paging options map as the arguments.
Retrieves token pair information from the API, takes an token request map and an (optional) paging options map as the arguments.
Submits a signed order to the API, takes a signed order map as an argument
Example:
(def signed-order {:ec-signature: {:r "string"
:s "string,"
:v "number"}
:exchange-contract-address "string"
:expiration-unix-timestamp-sec #object[BigNumber]
:fee-fecipient "string"
:maker "string"
:maker-fee #object[BigNumber]
:maker-token-address "string"
:maker-token-amount #object[BigNumber]
:salt #object[BigNumber]
:taker "string"
:takerFee #object[BigNumber]
:taker-token-address "string"
:taker-token-amount #object[BigNumber]})
(http-client/submit-order-async chan signed-order)
This namesapce includes functions for interacting with a websocket endpoint that implements the standard relayer API.
Example:
(ns my-district
(:require [cljs-0x-connect.ws-orderbook :as ws-orderbook]))
Returns a new WebSocketOrderbookChannel instance, takes url string as an argument.
Example:
(def url "wss://api.radarrelay.com/0x/v0/ws")
(def config {:heartbeat-interval-ms 1000})
(def chan (ws-orderbook/create-orderbook-channel url config))
Returns an OrderbookChannelHandler instance that responds to various channel updates, takes a map of four functions as an argument.
Example:
(def handler (ws-orderbook/create-channel-handler {:on-snapshot (fn [chan opts resp] (prn "bids:" (count (aget resp "bids"))
"asks:" (count (aget resp "asks"))))
:on-update (fn [chan opts order] (prn "new order:" order))
:on-error (fn [chan opts resp] (prn "Error:" resp))
:on-close (fn [chan opts] (prn "closing"))}))
Subscribes to orderbook snapshots and updates from the websocket, takes as an argument an OrderbookChannelHandler instance and a map of:
- subscription options map (describing which token pair to subscribe to)
- an OrderbookChannelHandler instance. Example:
(def orderbook-subscription-opts {:base-token-address "0x2956356cd2a2bf3202f771f50d3d14a367b48070"
:quote-token-address "0xe41d2489571d322189246dafa5ebde1f4699f498"
:limit 20
:snapshot true})
(ws-orderbook/subscribe chan {:opts orderbook-subscription-opts
:handler handler})
Closes the websocket connection, takes a WebSocketOrderbookChannel instance as an argument.
Example:
(ws-orderbook/close chan)
Run test suite:
lein deps
# To run tests and rerun on changes
lein doo chrome-headless tests
Install into local repo:
lein cljsbuild test
lein install