import { Socket as PhoenixSocket } from 'phoenix-channels'; import { Contract } from 'web3-eth-contract'; import BigNumber from 'bignumber.js'; import { GetAccountAddressResult } from '../queries/account/getAccountAddress'; import { AssetsNoncesData } from '../queries/nonces'; import { OrdersForMovementData } from '../queries/movement/getOrdersForMovementQuery'; import { GetStatesData, SyncStatesData, SignStatesData } from '../mutations/stateSyncing'; import { FiatCurrency } from '../constants/currency'; import { mapMarketsForNashProtocol } from '../helpers'; import { OrderBook, TradeHistory, Ticker, Trade, CandleRange, CandleInterval, Movement, MovementStatus, MovementType, AccountPortfolio, Period, CancelledOrder, AccountBalance, AccountTransaction, OrderPlaced, Market, Order, DateTime, AccountOrder, OrderBuyOrSell, OrderCancellationPolicy, CurrencyAmount, CurrencyPrice, PaginationCursor, OrderStatus, OrderType, SignMovementResult, AssetData, Asset } from '../types'; import { CryptoCurrency } from '../constants/currency'; import { APIKey } from '@neon-exchange/nash-protocol-mpc'; import { NEO_NETWORK, BTC_NETWORK, Networks, ETH_NETWORK } from './networks'; export interface ClientOptions { host: string; maxEthCostPrTransaction?: string; debug?: boolean; neoScan?: string; neoNetworkSettings?: typeof NEO_NETWORK[Networks.MainNet]; ethNetworkSettings?: typeof ETH_NETWORK[Networks.MainNet]; btcNetworkSettings?: typeof BTC_NETWORK[Networks.MainNet]; } export declare const EnvironmentConfiguration: { production: ClientOptions; sandbox: ClientOptions; dev1: ClientOptions; dev2: ClientOptions; dev3: ClientOptions; dev4: ClientOptions; local: ClientOptions; }; export declare const sanitizeAddMovementPayload: (payload: { recycled_orders: []; resigned_orders: []; recycledOrders: []; resignedOrders: []; digests: []; signed_transaction_elements: []; signedTransactionElements: []; }) => { recycled_orders: []; resigned_orders: []; recycledOrders: []; resignedOrders: []; digests: []; signed_transaction_elements: []; signedTransactionElements: []; }; export interface NonceSet { noncesFrom: number[]; noncesTo: number[]; nonceOrder: number; } interface ListAccountTradeParams { before?: PaginationCursor; limit?: number; marketName?: string; } interface ListAccountTransactionsParams { cursor?: string; fiatSymbol?: string; limit?: number; } interface GetAccountPortfolioParams { fiatSymbol?: FiatCurrency; period?: Period; } interface ListTradeParams { marketName: string; limit?: number; before?: PaginationCursor; } interface ListCandlesParams { marketName: string; before?: DateTime; interval?: CandleInterval; limit?: number; } interface ListMovementsParams { currency?: CryptoCurrency; status?: MovementStatus; type?: MovementType; } interface ListAccountOrderParams { before?: PaginationCursor; buyOrSell?: OrderBuyOrSell; limit?: number; marketName?: string; rangeStart?: DateTime; rangeStop?: DateTime; status?: [OrderStatus]; type?: [OrderType]; shouldIncludeTrades?: boolean; } export declare const MISSING_NONCES = "missing_asset_nonces"; export declare const MAX_SIGN_STATE_RECURSION = 5; interface SubscriptionHandlers { onResult: (p: T) => void; onError: (p: Error) => void; onAbort: (p: Error) => void; onStart: (p: object) => void; } interface NashSocketEvents { /** * See https://www.npmjs.com/package/phoenix-channels */ socket: InstanceType; onUpdatedAccountOrders(variables: { buyOrSell?: OrderBuyOrSell; marketName?: string; rangeStart?: DateTime; rangeStop?: DateTime; status?: OrderStatus[]; type?: OrderType[]; }, handlers: SubscriptionHandlers<{ data: { updatedAccountOrders: Order[]; }; }>): void; onUpdatedCandles(variables: { interval: CandleInterval; marketName: string; }, handlers: SubscriptionHandlers<{ data: { updatedCandles: CandleRange[]; }; }>): void; onUpdatedTickers(handlers: SubscriptionHandlers<{ data: { updatedTickers: Ticker[]; }; }>): void; onNewTrades(variables: { marketName: string; }, handlers: SubscriptionHandlers<{ data: { newTrades: Trade[]; }; }>): void; onUpdatedOrderbook(variables: { marketName: string; }, handlers: SubscriptionHandlers<{ data: { updatedOrderBook: OrderBook; }; }>): void; onAccountTrade(variables: { marketName: string; }, handlers: SubscriptionHandlers<{ data: { newAccountTrades: Trade[]; }; }>): void; } export declare const findBestNetworkNode: (nodes: any) => Promise; export declare class Client { ethVaultContract: Contract; apiKey: APIKey; private maxEthCostPrTransaction; private opts; private apiUri; private wsToken; private wsUri; private isMainNet; private gql; private web3; private authorization; marketData: { [key: string]: Market; }; nashProtocolMarketData: ReturnType; assetData: { [key: string]: AssetData; }; private tradedAssets; private assetNonces; private currentOrderNonce; /** * Create a new instance of [[Client]] * * @param opts * @returns * * Example * ``` * import { Client, EnvironmentConfiguration } from '@neon-exchange/api-client-typescript' * * const nash = new Client(EnvironmentConfiguration.sandbox) * ``` */ constructor(opts: ClientOptions); /** * Sets up a websocket and authenticates it using the current token. * * @returns * * Example * ``` * import { Client, EnvironmentConfiguration } from '@neon-exchange/api-client-typescript' * * const nash = new Client(EnvironmentConfiguration.sandbox) * await nash.login({ email, password }) * * const connection = nash.createSocketConnection() * * // Getting the orderbook for the neo_eth marked * connection.onUpdatedOrderbook( * { marketName: 'neo_eth' }, * { * onResult: ({ * data: { * updatedOrderBook: { bids, asks } * } * }) => { * console.log(`updated bids ${bids.length}`) * console.log(`updated asks ${asks.length}`) * } * } * ) * * // Getting the user orderobok for all markets * connection.onUpdatedAccountOrders( * {}, * { * onResult: ({ * data: { * updatedAccountOrders * } * }) => { * console.log(`Updated orders: {updatedAccountOrders.length}`) * } * } * ) * * ``` */ createSocketConnection(): NashSocketEvents; /** * Login against the central account service. A login is required for all signed * request. * @returns * @param secret string * @param apiKey string * @returns * * Example * ``` * try { * nash.login(require('PATH_TO_KEY.json')) * } catch (e) { * console.error(`login failed ${e}`) * } * ``` */ login({ secret, apiKey }: { apiKey: string; secret: string; }): Promise; /** * Get a single [[Ticker]] for the given market name. * * @param marketName * @returns * * Example * ``` * const ticker = await nash.getTicker('neo_gas') * console.log(ticker) * ``` */ getTicker(marketName: string): Promise; /** * Get the [[OrderBook]] for the given market. * * @param marketName * @returns * * Example * ``` * const orderBook = await nash.getOrderBook('neo_gas') * console.log(orderBook.bids) * ``` */ getOrderBook(marketName: string): Promise; /** * Get [[TradeHistory]] for the given market name. * * @param marketName * @param limit * @param before * @returns * * Example * ``` * const tradeHistory = await nash.listTrades({ * marketname : 'neo_gas' * }) * console.log(tradeHistory.trades) * ``` */ listTrades({ marketName, limit, before }: ListTradeParams): Promise; /** * Fetches as list of all available [[Ticker]] that are active on the exchange. * * @returns * * Example * ``` * const tickers = await nash.listTickers() * console.log(tickers) * ``` */ listTickers(): Promise; /** * Fetches as list of all available [[Asset]] that are active on the exchange. * * @returns * * Example * ``` * const assets = await nash.listAssets() * console.log(assets) * ``` */ listAssets(): Promise; /** * List a [[CandleRange]] for the given market. * * @param marketName * @param before * @param interval * @param limit * @returns * * Example * ``` * const candleRange = await nash.listCandles({ * marketName : 'neo_gas' * }) * console.log(candleRange) * `` */ listCandles({ marketName, before, interval, limit }: ListCandlesParams): Promise; /** * List all available markets. * * @returns * * Example * ``` * const markets = await nash.listMarkets() * console.log(markets) * ``` */ listMarkets(): Promise; /** * Get a specific [[Market]] by name. * * @param marketName * @returns * * Example * ``` * const market = await nash.getMarket('neo_gas') * console.log(market) * ``` */ getMarket(marketName: string): Promise; /** * list available orders for the current authenticated account. * @param before * @param buyOrSell * @param limit * @param marketName * @param rangeStart * @param rangeStop * @param status * @param type * @returns * * Example * ``` * const accountOrder = await nash.listAccountOrders({ * marketName : 'neo_eth' * }) * console.log(accountOrder.orders) * ``` */ listAccountOrders({ before, buyOrSell, limit, marketName, rangeStart, rangeStop, status, type, shouldIncludeTrades }?: ListAccountOrderParams): Promise; /** * list available trades for the current authenticated account. * * @param {ListAccountTradeParams} params * @returns * * Example * ``` * const tradeHistory = await nash.listAccountTrades({ * limit : 10, * marketName : 'neo_eth' * }) * console.log(tradeHistory.trades) * ``` */ listAccountTrades({ before, limit, marketName }?: ListAccountTradeParams): Promise; /** * List available account transactions. * * @param cursor * @param fiatSymbol * @param limit * @returns * * Example * ``` * const accountTransaction = await nash.listAccountTransactions({ * limit : 150, * ${paramName} : ${paramValue} * }) * console.log(accountTransaction.transactions) * ``` */ listAccountTransactions({ cursor, fiatSymbol, limit }?: ListAccountTransactionsParams): Promise; /** * List all balances for current authenticated account. * * @param ignoreLowBalance * @returns * * Example * ``` * const accountBalance = await nash.listAccountBalances() * console.log(accountBalance) * ``` */ listAccountBalances(ignoreLowBalance: any): Promise; /** * Get the deposit address for the given crypto currency. * * @param currency * @returns * * Example * ``` * import { CryptoCurrency } from '@neon-exchange/api-client-typescript' * * const address = await nash.getAccountAddress(CryptoCurrency.NEO) * console.log(address) * ``` */ getAccountAddress(currency: CryptoCurrency): Promise; /** * @param {CryptoCurrency} currency [description] * @return {Promise} [description] * * @deprecated will be removed in next major version use getAccountAddress */ getDepositAddress(currency: CryptoCurrency): Promise; /** * Get the [[AccountPortfolio]] for the current authenticated account. * * @param fiatSymbol * @param period * @returns * * Example * ``` * const accountPortfolio = await nash.getAccountPortfolio({ * fiatSymbol: "USD", * * }) * console.log(accountPortfolio) * ``` */ getAccountPortfolio({ fiatSymbol, period }?: GetAccountPortfolioParams): Promise; /** * Get a [[Movement]] by the given id. * * @param movementID * @returns * * Example * ``` * const movement = await nash.getMovement(1) * console.log(movement) * ``` */ getMovement(movementID: number): Promise; /** * Get [[AccountBalance]] for the given crypto currency. * * @param currency * @returns * * Example * ``` * import { CryptoCurrency } from '@neon-exchange/api-client-typescript' * * const accountBalance = await nash.getAcountBalance(CryptoCurrency.ETH) * console.log(accountBalance) * ``` */ getAccountBalance(currency: CryptoCurrency): Promise; /** * Get an order by ID. * * @param orderId * @returns * * Example * ``` * const order = await nash.getAccountOrder('999') * console.log(order) * ``` */ getAccountOrder(orderId: string): Promise; /** * List all movements for the current authenticated account. * * @param currency * @param status * @param type * @returns * * Example * ``` * const movements = await nash.listMovements({ * currency : 'eth' * }) * console.log(movements) * ``` */ listMovements({ currency, status, type }: ListMovementsParams): Promise; /** * List all orders for a given movement * * @returns * * Example * ``` * const getOrdersForMovementData = await nash.getOrdersForMovement(unit) * console.log(getOrdersForMovementData) * ``` */ getOrdersForMovement(asset: string): Promise; /** * List all current asset nonces * * @returns * * Example * ``` * const getNoncesData = await nash.getAssetNonces() * console.log(getNoncesData) * ``` */ getAssetNonces(assetList: string[]): Promise; /** * Gets Balance States, Signs Balance States, then Syncs Balance states to the server * * @returns * * Example * ``` * const getSignSyncStates = await nash.getSignAndSyncStates() * console.log(getSignSyncStates) * ``` */ getSignAndSyncStates(): Promise; private state_map_from_states; /** * Submit all states and open orders to be signed for settlement * * @returns * * Example * ``` * const signStatesResult = await nash.signStates(getStatesResult) * console.log(signStatesResult) * ``` */ signStates(getStatesData: GetStatesData, depth?: number): Promise; /** * List all states and open orders to be signed for settlement * * @returns * * Example * ``` * const getStatesData = await nash.getStates() * console.log(getStatesData) * ``` */ syncStates(signStatesData: SignStatesData): Promise; /** * Cancel an order by ID. * * @param orderID * @returns * * Example * ``` * const cancelledOrder = await nash.cancelOrder('11') * console.log(cancelledOrder) * ``` */ cancelOrder(orderID: string, marketName: string): Promise; /** * Cancel all orders by market name * * @param marketName * @returns * * Example * ``` * const result = await nash.cancelAllOrders('neo_gas') * console.log(result) * ``` */ cancelAllOrders(marketName?: string): Promise; /** * Place a limit order. * * @param allowTaker * @param amount * @param buyOrSell * @param cancelationPolicy * @param limitPrice * @param marketName * @param cancelAt * @returns * * Example * ```typescript * import { * createCurrencyAmount, * createCurrencyPrice, * OrderBuyOrSell, * OrderCancellationPolicy * } from '@neon-exchange/api-client-typescript' * * const order = await nash.placeLimitOrder( * false, * createCurrencyAmount('1', CryptoCurrency.NEO), * OrderBuyOrSell.BUY, * OrderCancellationPolicy.GOOD_TIL_CANCELLED, * createCurrencyPrice('0.01', CryptoCurrency.GAS, CryptoCurrency.NEO), * 'neo_gas' * ) * console.log(order.status) * ``` */ placeLimitOrder(allowTaker: boolean, amount: CurrencyAmount, buyOrSell: OrderBuyOrSell, cancellationPolicy: OrderCancellationPolicy, limitPrice: CurrencyPrice, marketName: string, cancelAt?: DateTime): Promise; /** * Place a market order. * * @param amount * @param buyOrSell * @param marketName * @returns * * Example * ```typescript * import { * createCurrencyAmount, * OrderBuyOrSell, * } from '@neon-exchange/api-client-typescript' * * const order = await nash.placeMarketOrder( * createCurrencyAmount('1.00', CryptoCurrency.NEO), * OrderBuyOrSell.SELL, * 'neo_gas' * ) * console.log(order.status) * ``` */ placeMarketOrder(amount: CurrencyAmount, buyOrSell: OrderBuyOrSell, marketName: string): Promise; /** * Place a stop limit order. * * @param allowTaker * @param amount * @param buyOrSell * @param cancellationPolicy * @param limitPrice * @param marketName * @param stopPrice * @param cancelAt * @returns * * Example * ```typescript * import { * createCurrencyAmount, * createCurrencyPrice, * OrderBuyOrSell, * OrderCancellationPolicy * } from '@neon-exchange/api-client-typescript' * * const order = await nash.placeStopLimitOrder( * false, * createCurrencyAmount('1', CryptoCurrency.NEO), * OrderBuyOrSell.BUY, * OrderCancellationPolicy.GOOD_TIL_CANCELLED, * createCurrencyPrice('0.01', CryptoCurrency.GAS, CryptoCurrency.NEO), * 'neo_gas' * createCurrencyPrice('0.02', CryptoCurrency.GAS, CryptoCurrency.NEO) * ) * console.log(order.status) * ``` */ placeStopLimitOrder(allowTaker: boolean, amount: CurrencyAmount, buyOrSell: OrderBuyOrSell, cancellationPolicy: OrderCancellationPolicy, limitPrice: CurrencyPrice, marketName: string, stopPrice: CurrencyPrice, cancelAt?: DateTime): Promise; /** * Place a stop market order. * * @param amount * @param buyOrSell * @param marketName * @param stopPrice * @returns * * Example * ```typescript * import { * createCurrencyAmount, * createCurrencyPrice, * OrderBuyOrSell, * } from '@neon-exchange/api-client-typescript' * * const order = await nash.placeStopLimitOrder( * createCurrencyAmount('1', CryptoCurrency.NEO), * OrderBuyOrSell.BUY, * 'neo_gas' * createCurrencyPrice('0.02', CryptoCurrency.GAS, CryptoCurrency.NEO) * ) * console.log(order.status) * ``` */ placeStopMarketOrder(amount: CurrencyAmount, buyOrSell: OrderBuyOrSell, marketName: string, stopPrice: CurrencyPrice): Promise; private handleOrderError; signDepositRequest(address: string, quantity: CurrencyAmount, nonce?: number): Promise; queryAllowance(assetData: AssetData): Promise; private validateTransactionCost; private approveERC20Transaction; private approveAndAwaitAllowance; transferToExternal(params: { quantity: CurrencyAmount; address: string; }): Promise<{ txId: string; gasUsed?: number; }>; private signNeoPayload; private signEthTransaction; depositToTradingContract(quantity: CurrencyAmount): Promise<{ txId: string; }>; withdrawFromTradingContract(quantity: CurrencyAmount): Promise<{ txId: string; }>; private prepareMovement; private transferToTradingContract; /** * Sign a withdraw request. * * @param address * @param quantity * @returns * * Example * ```typescript * import { createCurrencyAmount } from '@neon-exchange/api-client-ts' * * const address = 'd5480a0b20e2d056720709a9538b17119fbe9fd6'; * const amount = createCurrencyAmount('1.5', CryptoCurrency.ETH); * const signedMovement = await nash.signWithdrawRequest(address, amount); * console.log(signedMovement) * ``` */ signWithdrawRequest(address: string, quantity: CurrencyAmount, nonce?: number): Promise; /** * helper function that returns the correct types for the needed GQL queries * and mutations. * * @param [SigningPayloadID] * @param payload * @returns */ private signPayload; private fillPoolFn; private updateTradedAssetNonces; private createTimestamp32; private getNoncesForTrade; private fetchMarketData; private completeBtcTransactionSignatures; private sendBlockchainRawTransaction; private completePayloadSignature; private fetchAssetData; getNeoAddress(): string; getEthAddress(): string; getBtcAddress(): string; } export {};