Coder Social home page Coder Social logo

invest-openapi-js-sdk's Introduction

Trading Open API - JS SDK

SDK для работы с OpenAPI Тинькофф Инвестиции, который можно использовать для создания торговых роботов.

npm i @tinkoff/invest-openapi-js-sdk --save

Документация

Доступна по ссылке

Swagger

Авторизация

Более полную информацию можно просмотреть в документации

  1. Перейдите в настройки блок "Токен для OpenAPI"
  2. Функция "Подтверждение сделок кодом" должна быть отключена
  3. Выпустите токен OpenApi для биржи и Sandbox. Возможно система попросит вас авторизоваться еще раз, не беспокойтесь, это необходимо для подключения робота к торговой платформе.
  4. Скопируйте токен и сохраните, токен отображается только один раз, просмотреть его позже не получится, тем не менее вы можете выпускать неограниченное количество токенов.

Пример

см. более сложный пример в example

import OpenAPI from '@tinkoff/invest-openapi-js-sdk';

const apiURL = 'https://api-invest.tinkoff.ru/openapi';
const socketURL = 'wss://api-invest.tinkoff.ru/openapi/md/v1/md-openapi/ws';
const secretToken = 'xxx'; // токен для сандбокса
const api = new OpenAPI({ apiURL, secretToken, socketURL });

!(async function run() {
  const { figi } = await api.searchOne({ ticker: 'AAPL' });
  const { commission, orderId } = await api.limitOrder({
    operation: 'Buy',
    figi,
    lots: 1,
    price: 100,
  }); // Покупаем AAPL
  console.log(commission); // Комиссия за сделку
  await api.cancelOrder({ orderId }); // Отменяем заявку
})();

Sandbox

Для использования Sandbox необходимо передать в apiURL и в secretToken url эндпоинта с апи sandbox'а и токен для песочницы. Более подробнов документации

await api.sandboxClear(); // очищаем песочницу 
const { figi } = await api.searchOne({ ticker: 'AAPL' });
await api.setCurrenciesBalance({ currency: 'USD', balance: 1000 }); // 1000$ на счет
await api.instrumentPortfolio({ figi }); // В портфеле ничего нет
await api.limitOrder({ operation: 'Buy', figi, lots: 1, price: 100 }); // Покупаем AAPL
await api.instrumentPortfolio({ figi }); // Сделка прошла моментально

invest-openapi-js-sdk's People

Contributors

avz avatar businessduck avatar letitcode avatar ovr avatar ziggreen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.