UNPKG

@crypdex/hydro-sdk

Version:

Javascript SDK for the Hydro API

205 lines (204 loc) 7.99 kB
import { Candle } from '../models/Candle'; import { Fee } from '../models/Fee'; import { LockedBalance } from '../models/LockedBalance'; import { Market } from '../models/Market'; import { Order, Side, Status } from '../models/Order'; import { Orderbook, OrderbookLevel } from '../models/Orderbook'; import { OrderList } from '../models/OrderList'; import { Ticker } from '../models/Ticker'; import { TradeList } from '../models/TradeList'; import { SignatureHandler } from '../types'; export interface HydroClientArgs { sign?: SignatureHandler; account?: string; baseUrl?: string; privateKey?: string; } export declare class HydroClient { private handler; private sign; private constructor(); static create({sign, account, baseUrl, privateKey}: HydroClientArgs): HydroClient; /** * If you only want to make public API calls, no authentication is needed */ static withoutAuth(baseUrl?: string): HydroClient; /** * Provide a private key for authentication purposes * @param privateKey A private key in hex format with the form "0x..." */ static withPrivateKey(privateKey: string, baseUrl?: string): HydroClient; /** * If you don't want to supply your private key, or want to integrate with a wallet, provide * your own function to sign messages and the account you will be using. * @param sign A function that takes the input message and signs it with the private key of the account * @param account The account that will be doing the signing */ static withCustomAuth(sign: SignatureHandler, account: string, baseUrl?: string): HydroClient; setBaseUrl(baseUrl: string): this; /** * Public API Calls * * These calls do not require any authentication to complete, and will generally give you * public state about the Hydro API * * See https://docs.ddex.io/#public-rest-api */ /** * Returns all active markets * * See https://docs.ddex.io/#list-markets */ listMarkets(): Promise<Market[]>; /** * Returns a specific market * * See https://docs.ddex.io/#get-a-market * * @param marketId The id of the market, specified as a trading pair, e.g. "ZRX-ETH" */ getMarket(marketId: string): Promise<Market>; /** * Returns tickers for all active markets * * See https://docs.ddex.io/#list-tickers */ listTickers(): Promise<Ticker[]>; /** * Returns ticker for a specific market * * See https://docs.ddex.io/#get-a-ticker * * @param marketId The id of the market, specified as a trading pair, e.g. "ZRX-ETH" */ getTicker(marketId: string): Promise<Ticker>; /** * Returns the orderbook for a specific market * * See https://docs.ddex.io/#get-orderbook * * @param marketId The id of the market, specified as a trading pair, e.g. "ZRX-ETH" * @param level (Optional) The amount of detail returned in the orderbook. Default is level ONE. */ getOrderbook(marketId: string, level?: OrderbookLevel): Promise<Orderbook>; /** * Returns paginated trades for a specific market * * See https://docs.ddex.io/#get-trades * * @param marketId The id of the market, specified as a trading pair, e.g. "ZRX-ETH" * @param page (Optional) Which page to return. Default is page 1. * @param perPage (Optional) How many results per page. Default is 20. */ listTrades(marketId: string, page?: number, perPage?: number): Promise<TradeList>; /** * Returns "candles" for building a trading chart for a specific market * * See https://docs.ddex.io/#get-candles * * @param marketId The id of the market, specified as a trading pair, e.g. "ZRX-ETH" * @param from The beginning of the time range as a UNIX timestamp * @param to The end of the time range as a UNIX timestamp * @param granularity The width of each candle in seconds */ listCandles(marketId: string, from: number, to: number, granularity: number): Promise<Candle[]>; /** * Calculate an estimated fee taken by the exchange given a price and amount for an order * * See https://docs.ddex.io/#calculate-fees * * @param price The price of the order * @param amount The amount of token in the order */ calculateFees(price: string, amount: string, quoteSymbol?: string): Promise<Fee>; /** * Private API Calls * * These calls require authentication, meaning you must have a valid trading address * and the ability to sign requests with that address' private key. * * See https://docs.ddex.io/#private-rest-api */ /** * Build a new order to submit to the exchange * * See https://docs.ddex.io/#build-unsigned-order * * @param marketId The id of the market, specified as a trading pair, e.g. "ZRX-ETH" * @param side Whether this is a "buy" or "sell" order * @param price The price of the order * @param amount The amount of token in the order */ buildOrder(marketId: string, side: Side, price: string, amount: string): Promise<Order>; /** * Submit a signed order to the exchange * * See https://docs.ddex.io/#place-order * * @param orderId The id of a built order * @param signature String created by signing the orderId */ placeOrder(orderId: string, signature: string): Promise<Order>; /** * A convenience function that will build an order, sign the order, and then * immediately place the order on the system using the signing method passed * in. * * @param marketId The id of the market, specified as a trading pair, e.g. "ZRX-ETH" * @param side Whether this is a "buy" or "sell" order * @param price The price of the order * @param amount The amount of token in the order */ createOrder(marketId: string, side: Side, price: string, amount: string): Promise<Order>; /** * Cancel an order you have submitted to the exchange * * See https://docs.ddex.io/#cancel-order * * @param orderId The id of the order you wish to cancel */ cancelOrder(orderId: string): Promise<void>; /** * Return paginated orders you have submitted to the exchange * * See https://docs.ddex.io/#list-orders * * @param marketId (Optional) The id of the market, specified as a trading pair, e.g. "ZRX-ETH" * @param status (Optional) Choose between "pending" or "all" orders * @param page (Optional) Which page to return. Default is page 1. * @param perPage (Optional) How many results per page. Default is 20. */ listOrders(marketId?: string, status?: Status, page?: number, perPage?: number): Promise<OrderList>; /** * Return a specific order you have submitted to the exchange * * See https://docs.ddex.io/#get-order * * @param orderId The id of the order */ getOrder(orderId: string): Promise<Order>; /** * Return paginated list of all trades you have made * * See https://docs.ddex.io/#list-account-trades * * @param marketId The id of the market, specified as a trading pair, e.g. "ZRX-ETH" * @param page (Optional) Which page to return. Default is page 1. * @param perPage (Optional) How many results per page. Default is 20. */ listAccountTrades(marketId: string, page?: number, perPage?: number): Promise<TradeList>; /** * Return locked balances for each active token * * See https://docs.ddex.io/#list-locked-balances */ listLockedBalances(): Promise<LockedBalance[]>; /** * Return a specific locked balance * * See https://docs.ddex.io/#get-locked-balance * * @param symbol The symbol for the token you want to see your locked balance */ getLockedBalance(symbol: string): Promise<LockedBalance>; }