Skip to content

Commit

Permalink
Update params to use proper typings, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
mschmuckler committed May 14, 2021
1 parent b073f56 commit bbcdb16
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 43 deletions.
22 changes: 5 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 18 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import Axios, { AxiosError, AxiosInstance } from 'axios';
import qs from 'qs';
import {
APIOptions,
BotsParams,
BotsStatsParams,
DealsParams,
SmartTradeHistoryParams,
SmartTradeParams,
ThreeCommasError,
Expand Down Expand Up @@ -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);
}

Expand Down
33 changes: 33 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bbcdb16

Please sign in to comment.