A small library to interact with some cryptocurrency exchanges in a way that is convenient for my projects. Please note that this projects is suited for my very specific needs and it's not meant to be a general purpose library. If you find it useful, feel free to use it, but be aware that it may not cover all the features you need.
To install Tradekit, run:
npm install @enea-scaccabarozzi/tradekits
import { Binance, Bybit } from '@enea-scaccabarozzi/tradekits';
const exchange = new Binance({
proxies: [{
host: "string",
port: "number",
auth: { username: undefined, password: undefined },
protocol: undefined;
}];
sandbox: true;
auth: { key: "string", secret: "string" };
})
The Tradekit API allows you to manage proxies, authenticate, access market data, and handle account and position management within a trading environment. This README provides an overview of the available methods and options for interacting with the Tradekit API.
Manage the proxies used by Tradekit for network requests.
-
addProxy(proxy: ProxyOptions): ProxyOptions Adds a proxy configuration and returns the added proxy options.
-
setProxies(proxies: ProxyOptions[]): number Sets multiple proxies and returns the number of proxies set.
-
getProxies(): TradekitResult<ProxyOptions[]> Retrieves the list of configured proxies.
-
getCurrentProxy(): TradekitResult Retrieves the currently active proxy.
-
rotateProxy(): TradekitResult Rotates to the next proxy in the list and returns the new active proxy.
Manage authentication for accessing trading services.
-
setAuth(auth: TradekitAuth): boolean Sets the authentication credentials and returns a boolean indicating success.
-
getAuth(): TradekitResult Retrieves the current authentication credentials.
Enable or disable the sandbox mode for testing without affecting real accounts.
- setSandbox(sandbox: boolean): boolean Sets the sandbox mode and returns a boolean indicating if it was successfully set.
Access market data such as ticker information.
-
getTicker(opts: GetTikerOptions): Promise<TradekitResult> Retrieves the ticker data for a specified symbol.
-
getTickers(opts: GetTikersOptions): Promise<TradekitResult<Ticker[]>> Retrieves ticker data for multiple symbols.
-
subscribeToTicker(opts: SubscribeToTikerOptions): TradekitResult Subscribes to updates for a specified ticker.
-
subscribeToTickers(opts: SubscribeToTikersOptions): TradekitResult Subscribes to updates for multiple tickers.
Manage and retrieve account-related data.
-
getBalance(opts?: GetBalanceOptions): Promise<TradekitResult> Retrieves the balance for specified currencies.
-
setLeverage(opts: SetLeverageOptions): Promise<TradekitResult> Sets the leverage for trading and returns the new leverage.
Open and close trading positions.
-
openShort(opts: OpenPositionOptions): Promise<TradekitResult> Opens a short position with specified options.
-
closeShort(opts: ClosePositionOptions): Promise<TradekitResult> Closes a short position with specified options.
-
openLong(opts: OpenPositionOptions): Promise<TradekitResult> Opens a long position with specified options.
-
closeLong(opts: ClosePositionOptions): Promise<TradekitResult> Closes a long position with specified options.
Defines the configuration for a proxy.
Defines the authentication credentials.
Options for retrieving a single ticker.
export interface GetTikerOptions {
symbol: string;
}
Options for subscribing to a single ticker, extending GetTikerOptions
.
export type SubscribeToTikerOptions = GetTikerOptions & BaseSubscriptionOptions<Ticker>;
Options for retrieving multiple tickers.
export interface GetTikersOptions {
symbols: string[];
}
Options for subscribing to multiple tickers, extending GetTikersOptions
.
export type SubscribeToTikersOptions = GetTikersOptions & BaseSubscriptionOptions<Ticker[]>;
Options for retrieving account balances.
export interface GetBalanceOptions {
currencies?: string[];
}
Options for setting trading leverage.
export interface SetLeverageOptions {
leverage: number;
symbol?: string;
}
Options for opening a trading position.
export interface OpenPositionOptions {
symbol: string;
amount: number;
timeInForce?: number;
}
Options for closing a trading position.
export interface ClosePositionOptions {
symbol: string;
amount: number;
timeInForce?: number;
}
Base options for subscribing to updates, with generic type T
.
export interface BaseSubscriptionOptions<T> {
onUpdate: (data: T) => void | Promise<void>;
onConnect?: () => void | Promise<void>;
onClose?: () => void | Promise<void>;
onSubscribed?: () => void | Promise<void>;
onError?: (error: TradekitError) => void | Promise<void>;
}
Generic result type used by many Tradekit methods. It wraps the result data and any errors that may have occurred. See neverthrow for more information about this approach.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or new features.
This project is licensed under the MIT License. See the LICENSE file for details.