import OpenAPI , { MarketInstrument } from '@tinkoff/invest-openapi-js-sdk' ; const apiURL = 'https://api-invest.tinkoff.ru/openapi' ; const sandboxApiURL = 'https://api-invest.tinkoff.ru/openapi/sandbox/' ; const socketURL = 'wss://api-invest.tinkoff.ru/openapi/md/v1/md-openapi/ws' ; const secretToken = process . env . TOKEN ; const sandboxToken = process . env . SANDBOX_TOKEN ; const api = new OpenAPI ( { apiURL : sandboxApiURL , secretToken : sandboxToken as string , socketURL } ) ; ! ( async function run ( ) { await api . sandboxClear ( ) ; const marketInstrument = await api . searchOne ( { ticker : 'AAPL' } ) as MarketInstrument ; const { figi } = marketInstrument ; console . log ( await api . setCurrenciesBalance ( { currency : 'USD' , balance : 1000 } ) ) ; console . log ( await api . portfolioCurrencies ( ) ) ; console . log ( await api . instrumentPortfolio ( { figi } ) ) ; console . log ( await api . limitOrder ( { operation : 'Buy' , figi , lots : 1 , price : 100 } ) ) ; console . log ( await api . instrumentPortfolio ( { figi } ) ) ; console . log ( await api . orderbookGet ( { figi } ) ) ; console . log ( await api . candlesGet ( { from : '2019-08-19T18:38:33.131642+03:00' , to : '2019-08-19T18:48:33.131642+03:00' , figi , interval : '1min' , } ) ) ; api . orderbook ( { figi , depth : 10 } , ( x ) => { console . log ( x . bids ) ; } ) ; api . candle ( { figi } , ( x ) => { console . log ( x . h ) ; } ) ; } ) ( ) ;