Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/invao/ccxt-private-ws
Private websocket connections with CCXT compatible data layout
https://github.com/invao/ccxt-private-ws
Last synced: 25 days ago
JSON representation
Private websocket connections with CCXT compatible data layout
- Host: GitHub
- URL: https://github.com/invao/ccxt-private-ws
- Owner: invao
- Created: 2019-09-25T07:59:16.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T14:38:25.000Z (about 2 years ago)
- Last Synced: 2024-11-09T14:17:54.687Z (about 1 month ago)
- Language: TypeScript
- Size: 621 KB
- Stars: 8
- Watchers: 3
- Forks: 5
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-ccxt - ccxt-private-ws - private websocket connections with CCXT compatible data layout (API)
README
# CCXT Private Websockets
A JavaScript library for cryptocurrency trading using authenticated websocket connections.
## Features
- Provides data structure compatibility to [CCXT](https://github.com/ccxt).
- Typescript support
- Missing websocket features are executed via REST API using CCXT**WARNING** THIS PROJECT IS IN AN EARLY STAGE, HAS NO TESTS AND GIVES YOU NO GUARANTEES ON ANYTHING!
## Supported Exchanges
| Exchange | Orders | Account | Notes |
| :------- | :-----: | :------: | :--------------------------------------- |
| Bitfinex | ✅ | ✅ |
| Binance | ✅ | ✅ | Order creation/cancellation via REST API |
| Kraken | ✅ | ❌ | Order creation/cancellation via REST API |
| Ftx | ✅ | ❌ | Order creation/cancellation via REST API |## Installation
```sh
yarn install ccxt-private-ws
```## Examples
### Subscribing to order stream
Import the library:
```typescript
import * as CcxtPrivateWs from 'ccxt-private-ws';
```Create an exchange instance using your credentials:
```typescript
const exchange = new CcxtPrivateWs['bitfinex']({ credentials: { apiKey: 'XXX', secret: 'YYY' } });
```Subscribe the channels you are interested in and start the connection.
```typescript
exchange.subscribeOrders({
callback: event => console.log(event.type, event.order)
});
exchange.connect();
```### Creating an order
```typescript
await exchange.createOrder({
symbol: 'USDT/USD';
type: 'limit';
side: 'buy';
amount: 1;
price: 1.001;
})
```### Canceling an order
```typescript
await exchange.createOrder({
id: 'XXXX-XXXX-XXXX-XXXX';
})
```## API
### Exchange Methods
#### `connect(): Promise`
Starts the connection to the exchange and does the authentication.
#### `disconnect(): Promise`
Stops the connection to the exchange.
#### `subscribeOrders(): void`
Enable order update subscription. For each order update an `order` event is emitted. Subscribe to the `order` event using `exchange.on('order, listener)`.
#### `subscribeBalances(): void`
Enable balance update subscription. For each balance update a `balance` event is emitted. Subscribe to the `balance` event using `exchange.on('balance, listener)`.
#### `createOrder?({ order }: { order: OrderInput }): Promise`
Creates an order.
#### `cancelOrder?({ id }: { id: string }): Promise`
Cancels an order.
#### `createClientId?(): string`
Creates an exchange compliant order client id that can be used when calling `createOrder`.
#### `getName(): string`
Returns the lowercase exchange name.
### Exchange Events
#### `on(event: 'order', listener: OrderListener): void`
Emitted when an order update is received. The listener event contains the full order that has been aggregated over all subsequent updates.
#### `on(event: 'balance', listener: BalanceListener): void`
Emitted when a balance update is received. The listener event might only contain the updated balances but will always contain current values for `total`, `used` and `free`.
#### `on(event: 'fullBalance', listener: BalanceListener): void`
Emitted when a balance update is received. This always contains all account balances for the specific exchange. Some exchanges might only send `balance` events.
#### `on(event: 'connect', listener: ConnectListener): void`
Emitted when the websocket connection was established and the authentication succeeded.