https://github.com/district0x/cljs-0x-connect
ClojureScript wrapper for 0x Connect library
https://github.com/district0x/cljs-0x-connect
wrapper-library
Last synced: 10 months ago
JSON representation
ClojureScript wrapper for 0x Connect library
- Host: GitHub
- URL: https://github.com/district0x/cljs-0x-connect
- Owner: district0x
- License: epl-1.0
- Created: 2018-03-08T17:03:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-22T16:00:19.000Z (over 8 years ago)
- Last Synced: 2025-07-14T01:18:18.355Z (12 months ago)
- Topics: wrapper-library
- Language: Clojure
- Homepage:
- Size: 411 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# cljs-0x-connect
[](https://travis-ci.org/district0x/cljs-0x-connect)
Clojurescript wrapper for the [0xProject/connect](https://0xproject.com/docs/connect) library, which servers as a gateway to any relayer that conforms to the [standard relayer API v0](https://github.com/0xProject/standard-relayer-api).
## Installation
Add `[district0x/cljs-0x-connect "1.0.0"]` into your project.clj.
## Usage
- [cljs-0x-connect.http-client](#http-client)
- [create-http-client](#create-http-client)
- [get-fees-async](#get-fees-async)
- [get-orders-async](#get-orders-async)
- [get-order-async](#get-order-async)
- [get-orderbook-async](#get-orderbook-async)
- [get-token-pairs-async](#get-token-pairs-async)
- [submit-order-async](#submit-order-async)
- [cljs-0x-connect.ws-orderbook](#ws-orderbook)
- [create-orderbook-channel](#create-orderbook-channel)
- [subscribe](#subscribe)
- [close](#close)
## `cljs-0x-connect.http-client`
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:
```clojure
(ns my-district
(:require [cljs-0x-connect.http-client :as http-client]))
```
#### `create-http-client`
Returns a new HttpClient instance, takes API url string as an argument.
Example:
```clojure
(def client (http-client/create-http-client "https://api.com/"))
```
#### `get-fees-async`
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.
[Example](https://github.com/district0x/cljs-0x-connect/blob/connect-with-cljsjs/test/tests/all.cljs#L30).
#### `get-orders-async`
Retrieves orders information from the API, takes an order request map and an (optional) paging options map as the arguments.
[Example](https://github.com/district0x/cljs-0x-connect/blob/connect-with-cljsjs/test/tests/all.cljs#L55).
#### `get-order-async`
Retrieves information about a specific order from the API, takes a hash of the order as an argument.
[Example](https://github.com/district0x/cljs-0x-connect/blob/connect-with-cljsjs/test/tests/all.cljs#L44).
Retrieves orderbook information from the API, takes an orderbook request map and an (optional) paging options map as the arguments.
[Example](https://github.com/district0x/cljs-0x-connect/blob/connect-with-cljsjs/test/tests/all.cljs#L37).
Retrieves token pair information from the API, takes an token request map and an (optional) paging options map as the arguments.
[Example](https://github.com/district0x/cljs-0x-connect/blob/connect-with-cljsjs/test/tests/all.cljs#L62).
#### `submit-order-async`
Submits a signed order to the API, takes a signed order map as an argument
Example:
```clojure
(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)
```
## `cljs-0x-connect.ws-orderbook`
This namesapce includes functions for interacting with a websocket endpoint that implements the standard relayer API.
Example:
```clojure
(ns my-district
(:require [cljs-0x-connect.ws-orderbook :as ws-orderbook]))
```
#### `create-orderbook-channel`
Returns a new WebSocketOrderbookChannel instance, takes url string as an argument.
Example:
```clojure
(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:
```clojure
(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"))}))
```
#### `subscribe`
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:
```clojure
(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})
```
#### `close`
Closes the websocket connection, takes a WebSocketOrderbookChannel instance as an argument.
Example:
```clojure
(ws-orderbook/close chan)
```
## Development
Run test suite:
```bash
lein deps
# To run tests and rerun on changes
lein doo chrome-headless tests
```
Install into local repo:
```bash
lein cljsbuild test
lein install
```