3commas-typescript 中文文档教程

发布于 3年前 浏览 20 项目主页 更新于 3年前

3Commas API Client for TypeScript

npm npm bundle size

Open in Gitpod

一个非官方的 3Commas API 包装器在打字稿中。 在此处查看官方文档。

Install

npm install 3commas-typescript

Usage

import { API } from '3commas-typescript';

const api = new API({
  key: 'YOUR_KEY', // Optional if only query endpoints with no security requirement
  secrets: 'YOUR_SECRETS', // Optional
  timeout: 60000, // Optional, in ms, default to 30000
  forcedMode: 'real' | 'paper',
  errorHandler: (response, reject) => {
    // Optional, Custom handler for 3Commas error
    const { error, error_description } = response;
    reject(new Error(error_description ?? error));
  },
});

Supported Request

Account

ping()

time()

transfer(params: TransferParams)

getTransferHistory(params: TransferHistoryParams)

getTransferData()

addExchangeAccount(params: any)

editExchangeAccount(params: any)

getExchange()

getMarketList()

getMarketPairs(params?: any)

getCurrencyRate(params: CurrencyParams)

getCurrencyRateWithLeverageData(params: MarketCurrencyParams)

getActiveTradeEntities(account_id: number)

sellAllToUSD(account_id: number)

sellAllToBTC(account_id: number)

getBalanceChartData(account_id: number, params: any)

loadBalances(account_id: number)

renameExchangeAccount(account_id: number, name: string)

removeExchangeAccount(account_id: number)

getPieChartData(account_id: number)

getAccountTableData(account_id: number)

getAccountInfo(account_id?: number)

User

changeUserMode(mode: 'paper' | 'real')

Smart Trade

getSmartTradeHistory(params?: SmartTradeHistoryParams)

smartTrade(params: SmartTradeParams)

getSmartTrade(id: number)

cancelSmartTrade(id: number)

updateSmartTrade(id: number)

averageSmartTrade(id: number, params: FundParams)

reduceFund(id: number, params: FundParams)

closeSmartTrade(id: number)

forceStartSmartTrade(id: number)

forceProcessSmartTrade(id: number)

setNoteSmartTrade(id: number, note: string)

getSubTrade(id: number)

closeSubTrade(smartTradeId: number, subTradeId: number)

cancelSubTrade(smartTradeId: number, subTradeId: number)

Bots

getBots(params?: BotsParams)

getBot(id: number)

getBotsStats(params?: BotsStatsParams)

getDeals(params?: DealsParams)

getDeal(id: number)

getDealSafetyOrders(id: number)

Custom Request

customRequest(method: string, version: number, path: string, payload?: any)

Websocket

subscribeSmartTrade(callback?: (data: WebSocket.Data) => void)

subscribeDeal(callback?: (data: WebSocket.Data) => void)

unsubscribe()

Response Type

智能交易端点返回的订单类型是使用 quicktype 生成的。

不保证类型正确性。 您可以在访问前执行类型检查。

try {
  const order = await api.getSmartTrade(1234567)
  const validatedOrder = api.validateOrderType(order)
  ...
} catch (error) {
  console.error(error)
}

Support

给我买杯咖啡

ETH:0xB6fc1dFABf1244138b048C3F80ba5678d8f6f0CE

BAT:0x336bFB8247640C0848F8aFFB80464f3fF489B888

3Commas API Client for TypeScript

npm npm bundle size

Open in Gitpod

An unofficial 3Commas API wrapper in TypeScript. Check out the offical documentation here.

Install

npm install 3commas-typescript

Usage

import { API } from '3commas-typescript';

const api = new API({
  key: 'YOUR_KEY', // Optional if only query endpoints with no security requirement
  secrets: 'YOUR_SECRETS', // Optional
  timeout: 60000, // Optional, in ms, default to 30000
  forcedMode: 'real' | 'paper',
  errorHandler: (response, reject) => {
    // Optional, Custom handler for 3Commas error
    const { error, error_description } = response;
    reject(new Error(error_description ?? error));
  },
});

Supported Request

Account

ping()

time()

transfer(params: TransferParams)

getTransferHistory(params: TransferHistoryParams)

getTransferData()

addExchangeAccount(params: any)

editExchangeAccount(params: any)

getExchange()

getMarketList()

getMarketPairs(params?: any)

getCurrencyRate(params: CurrencyParams)

getCurrencyRateWithLeverageData(params: MarketCurrencyParams)

getActiveTradeEntities(account_id: number)

sellAllToUSD(account_id: number)

sellAllToBTC(account_id: number)

getBalanceChartData(account_id: number, params: any)

loadBalances(account_id: number)

renameExchangeAccount(account_id: number, name: string)

removeExchangeAccount(account_id: number)

getPieChartData(account_id: number)

getAccountTableData(account_id: number)

getAccountInfo(account_id?: number)

User

changeUserMode(mode: 'paper' | 'real')

Smart Trade

getSmartTradeHistory(params?: SmartTradeHistoryParams)

smartTrade(params: SmartTradeParams)

getSmartTrade(id: number)

cancelSmartTrade(id: number)

updateSmartTrade(id: number)

averageSmartTrade(id: number, params: FundParams)

reduceFund(id: number, params: FundParams)

closeSmartTrade(id: number)

forceStartSmartTrade(id: number)

forceProcessSmartTrade(id: number)

setNoteSmartTrade(id: number, note: string)

getSubTrade(id: number)

closeSubTrade(smartTradeId: number, subTradeId: number)

cancelSubTrade(smartTradeId: number, subTradeId: number)

Bots

getBots(params?: BotsParams)

getBot(id: number)

getBotsStats(params?: BotsStatsParams)

getDeals(params?: DealsParams)

getDeal(id: number)

getDealSafetyOrders(id: number)

Custom Request

customRequest(method: string, version: number, path: string, payload?: any)

Websocket

subscribeSmartTrade(callback?: (data: WebSocket.Data) => void)

subscribeDeal(callback?: (data: WebSocket.Data) => void)

unsubscribe()

Response Type

The Order type returned by smart trade endpoint is generated using quicktype.

The type correctness isn't guaranteed. You can perform a type check before access.

try {
  const order = await api.getSmartTrade(1234567)
  const validatedOrder = api.validateOrderType(order)
  ...
} catch (error) {
  console.error(error)
}

Support

Buy me a coffee

ETH: 0xB6fc1dFABf1244138b048C3F80ba5678d8f6f0CE

BAT: 0x336bFB8247640C0848F8aFFB80464f3fF489B888

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文