Skip to content

Commit

Permalink
Merge pull request #4 from mschmuckler/add-bots-and-deals-endpoints
Browse files Browse the repository at this point in the history
Add some bots an deals endpoints
  • Loading branch information
kirosc authored May 15, 2021
2 parents cb12f66 + bbcdb16 commit ea1f128
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ forceProcessSmartTrade(id: number)
setNoteSmartTrade(id: number, note: string)
```

### Bots

```ts
getBots(params?: BotsParams)

getBotsStats(params?: BotsStatsParams)

getDeals(params?: DealsParams)
```

## Response Type

The Order type returned by smart trade endpoint is generated using [quicktype](https://github.com/quicktype/quicktype).
Expand Down
27 changes: 27 additions & 0 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,6 +271,30 @@ export class API {
});
}

async getBots(
params: BotsParams = {
limit: 50,
sort_by: 'created_at',
sort_direction: 'desc',
}
) {
return await this.request('GET', 1, '/bots', params);
}

async getBotsStats(params?: BotsStatsParams) {
return await this.request('GET', 1, '/bots/stats', params);
}

async getDeals(
params: DealsParams = {
limit: 50,
order: 'created_at',
order_direction: 'desc',
}
) {
return await this.request('GET', 1, '/deals', params);
}

/**
* Validate the response order is consistent with the generated type
* Or, an error is thrown
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 ea1f128

Please sign in to comment.