From bbcdb16c969fe171a8ad91c645c890a61e4a1533 Mon Sep 17 00:00:00 2001 From: Matthew Schmuckler Date: Fri, 14 May 2021 11:26:00 -0700 Subject: [PATCH] Update params to use proper typings, update README --- README.md | 22 +++++----------------- src/index.ts | 44 ++++++++++++++++++-------------------------- src/types/types.ts | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index cded779..237b070 100644 --- a/README.md +++ b/README.md @@ -111,23 +111,11 @@ setNoteSmartTrade(id: number, note: string) ### Bots ```ts -getBots() - -getBotsStats() - -getDeals( - limit: number = 50, - offset: number = 0, - scope: string = 'completed', - order: - | 'created_at' - | 'updated_at' - | 'closed_at' - | 'profit' - | 'profit_percentage' = 'created_at', - orderDirection: 'asc' | 'desc' = 'desc', - botId?: string -) +getBots(params?: BotsParams) + +getBotsStats(params?: BotsStatsParams) + +getDeals(params?: DealsParams) ``` ## Response Type diff --git a/src/index.ts b/src/index.ts index 069baa9..94daad3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,9 @@ import Axios, { AxiosError, AxiosInstance } from 'axios'; import qs from 'qs'; import { APIOptions, + BotsParams, + BotsStatsParams, + DealsParams, SmartTradeHistoryParams, SmartTradeParams, ThreeCommasError, @@ -268,38 +271,27 @@ export class API { }); } - async getBots() { - return await this.request('GET', 1, '/bots'); + async getBots( + params: BotsParams = { + limit: 50, + sort_by: 'created_at', + sort_direction: 'desc', + } + ) { + return await this.request('GET', 1, '/bots', params); } - async getBotsStats() { - return await this.request('GET', 1, '/bots/stats'); + async getBotsStats(params?: BotsStatsParams) { + return await this.request('GET', 1, '/bots/stats', params); } async getDeals( - limit: number = 50, - offset: number = 0, - scope: string = 'completed', - order: - | 'created_at' - | 'updated_at' - | 'closed_at' - | 'profit' - | 'profit_percentage' = 'created_at', - orderDirection: 'asc' | 'desc' = 'desc', - botId?: string - ) { - const params = { - limit, - offset, - scope, - order, - order_direction: orderDirection, - }; - - if (botId) { - params['bot_id'] = botId; + params: DealsParams = { + limit: 50, + order: 'created_at', + order_direction: 'desc', } + ) { return await this.request('GET', 1, '/deals', params); } diff --git a/src/types/types.ts b/src/types/types.ts index c9bd952..766857a 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -16,6 +16,39 @@ export interface ThreeCommasError { }; } +export interface BotsParams { + limit?: number; // Max 100 + offset?: number; + account_id?: number; + scope?: 'enabled' | 'disabled'; + strategy?: 'long' | 'short'; + sort_by?: 'profit' | 'created_at' | 'updated_at'; + sort_direction?: 'asc' | 'desc'; + quote?: string; +} + +export interface BotsStatsParams { + account_id?: number; + bot_id?: number; +} + +export interface DealsParams { + limit?: number; // Max 1000 + offset?: number; + account_id?: number; + bot_id?: number; + scope?: 'active' | 'finished' | 'completed' | 'cancelled' | 'failed'; + order?: + | 'created_at' + | 'updated_at' + | 'closed_at' + | 'profit' + | 'profit_percentage'; + order_direction?: 'asc' | 'desc'; + base?: string; + quote?: string; +} + export interface TransferParams { currency: string; amount: number | string;