{"id":324834,"date":"2021-06-12T21:00:23","date_gmt":"2021-06-12T21:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=324834"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=324834","title":{"rendered":"\u041a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0430\u0441\u0441\u0438\u0432\u043d\u044b\u0439 \u0434\u043e\u0445\u043e\u0434: \u041f\u0438\u0448\u0435\u043c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0440\u0435\u0439\u0434 \u0431\u043e\u0442\u0430 \u043d\u0430 JS (\u0447\u0430\u0441\u0442\u044c 1)"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0440\u0435\u0439\u0434\u0438\u043d\u0433 \u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u043a\u0440\u0438\u043f\u0442\u043e\u0431\u0438\u0440\u0436\u0435 Binance. \u0411\u043e\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u0435\u0442\u044c:<\/p>\n<ol>\n<li>\n<p>\u0442\u043e\u0440\u0433\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0438\u043d\u043e\u0441\u044f \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0434\u043e\u0445\u043e\u0434<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u0435\u043d \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043e\u0431\u043a\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439 \u0442\u043e\u0440\u0433\u043e\u0432\u043b\u0438<\/p>\n<\/li>\n<li>\n<p>\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u043d\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<\/ol>\n<h2>\u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b<\/h2>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u0438\u0440\u0436\u0430 Binance, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0435\u0441\u0442\u044c \u0448\u0438\u043a\u0430\u0440\u043d\u043e\u0435 api. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/928\/8de\/8b7\/9288de8b7925e86f7b77c19cb8022288.jpg\" width=\"629\" height=\"150\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u201c\u043a\u0443\u043f\u0438 \u0434\u0435\u0448\u0435\u0432\u043b\u0435\u201d \u0438 \u201c\u043f\u0440\u043e\u0434\u0430\u0439 \u0434\u043e\u0440\u043e\u0436\u0435\u201d. \u041d\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0434\u043b\u044f \u043d\u0430\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u043e\u0442\u0430, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442-\u0442\u0440\u0435\u0439\u0434\u0435\u0440 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u0431\u044b\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0442\u043e\u0440\u0433\u043e\u0432\u043b\u0438 \u043e\u0442 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0447\u0435\u0433\u043e. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0434\u0443\u043b\u044e \u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043a \u043a\u0430\u043a\u043e\u0439 \u0431\u0438\u0440\u0436\u0435 \u0435\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438: \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 API \u0438\u043b\u0438 \u043a \u043f\u0441\u0435\u0432\u0434\u043e-API (\u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f). \u0421 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cc8\/873\/d3a\/cc8873d3af9430e3b481328d67de6a3c.jpeg\" alt=\" \" title=\" \" width=\"748\" height=\"671\"><figcaption> <\/figcaption><\/figure>\n<p>\u0411\u0430\u0437\u0443 \u0432\u044b\u0431\u0440\u0430\u043b PostgreSQL. \u0422\u0443\u0442 \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0442\u0430\u0439\u043d\u043e\u0433\u043e \u0443\u043c\u044b\u0441\u043b\u0430. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u0443\u044e.&nbsp;<\/p>\n<p>\u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0441\u0442\u043e\u0438\u0442 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f, \u044d\u0442\u043e \u0432\u0441\u0435 \u043d\u0435 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0430\u0442\u044c\u044e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u043c\u0438\u043d\u0438-\u0441\u0435\u0440\u0438\u0430\u043b: &#171;\u041f\u0438\u0448\u0435\u043c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0440\u0435\u0439\u0434 \u0431\u043e\u0442\u0430 \u043d\u0430 JS&#187;. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c, \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043f\u043e\u0443\u0434\u043e\u0431\u043d\u0435\u0439 &#8212; \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c<\/p>\n<h2>\u0421\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u043b\u043e\u0433\u043e\u0432<\/h2>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043b\u0430\u0441\u0441,  \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <code>log<\/code> \u0438 <code>error<\/code>. \u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u0435\u0447\u0430\u0442\u0430\u044e\u0442 \u043b\u043e\u0433 \u0441 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0438 \u043f\u0435\u0440\u0444\u0438\u043a\u0441\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">class LoggerService {   constructor(prefix) {     this.logPrefix = prefix   }    log(...props) {     console.log(new Date().toISOString().substr(0, 19), this.logPrefix, ...props)   }    error(...props) {     console.error(new Date().toISOString().substr(0, 19), this.logPrefix, ...props)   } }<\/code><\/pre>\n<h2>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0438\u0440\u0436\u0443<\/h2>\n<pre><code class=\"bash\">yarn add node-binance-api<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 BaseApiService. \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0432 \u043d\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e Binance SDK, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441 LoggerService. \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u043c\u043e\u0439 \u043e\u043f\u044b\u0442 \u0441 Binance \u043c\u043e\u0433\u0443 \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u043f\u0430\u0440\u044b \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043b\u0430\u0442\u044c \u0446\u0435\u043d\u0443 \u0438 \u043e\u0431\u044c\u0435\u043c \u0441 \u0440\u0430\u0437\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439. \u0412\u0441\u0435 \u044d\u0442\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c, \u0441\u0434\u0435\u043b\u0430\u0432 \u0437\u0430\u043f\u0440\u043e\u0441 <code>futuresExchangeInfo()<\/code>. \u0418 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u043a\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439 \u0434\u043b\u044f \u0446\u0435\u043d\u044b <code>getAssetPricePrecision<\/code> \u0438 \u043e\u0431\u044a\u0435\u043c\u0430 <code>getAssetQuantityPrecision<\/code>.<\/p>\n<pre><code class=\"javascript\">class BaseApiService {   constructor({ client, secret }) {     const { log, error } = new Logger('BaseApiService')     this.log = log     this.error = error      this.api = new NodeBinanceApi().options({       APIKEY: client,       APISECRET: secret,       hedgeMode: true,     })     this.exchangeInfo = {}   }    async init() {     try {       this.exchangeInfo = await this.api.futuresExchangeInfo()     } catch (e) {       this.error('init error', e)     }   }    getAssetQuantityPrecision(symbol) {     const { symbols = [] } = this.exchangeInfo     const s = symbols.find(s =&gt; s.symbol === symbol) || { quantityPrecision: 3 }     return s.quantityPrecision   }    getAssetPricePrecision(symbol) {     const { symbols = [] } = this.exchangeInfo     const s = symbols.find(s =&gt; s.symbol === symbol) || { pricePrecision: 2 }     return s.pricePrecision   } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430, \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u043a\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439 \u0434\u043b\u044f \u0446\u0435\u043d\u044b \u0438 \u043e\u0431\u044c\u0435\u043c\u0430:<\/p>\n<pre><code class=\"javascript\">async futuresOrder(side, symbol, qty, price, params={}) {   try {     qty = Number(qty).toFixed(this.getAssetQuantityPrecision(symbol))     price = Number(price).toFixed(this.getAssetPricePrecision(symbol))     if (!params.type) {       params.type = ORDER.TYPE.MARKET     }     const res = await this.api.futuresOrder(side, symbol, qty, price || false, params)     this.log('futuresOrder', res)     return res   } catch (e) {     console.log('futuresOrder error', e)   } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0431\u043e\u0442 \u0443\u043c\u0435\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0440\u0434\u0435\u0440\u0430. \u041d\u0430\u0443\u0447\u0438\u043c \u0435\u0433\u043e \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437 \u0431\u0438\u0440\u0436\u044b \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431 \u043e\u043d \u043c\u043e\u0433 \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043e\u0440\u0434\u0435\u0440\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 TradeService.<\/p>\n<pre><code class=\"javascript\">class TradeService {   constructor({client, secret}) {     const { log, error } = new LoggerService('TradeService')     this.log = log     this.error = error     this.api = new NodeBinanceApi().options({       APIKEY: client,       APISECRET: secret,       hedgeMode: true,     })     this.events = new EventEmitter()   }    marginCallCallback = (data) =&gt; this.log('marginCallCallback', data)    accountUpdateCallback = (data) =&gt; this.log('accountUpdateCallback', data)    orderUpdateCallback = (data) =&gt; this.emit(data)    subscribedCallback = (data) =&gt; this.log('subscribedCallback', data)    accountConfigUpdateCallback = (data) =&gt; this.log('accountConfigUpdateCallback', data)    startListening() {     this.api.websockets.userFutureData(       this.marginCallCallback,       this.accountUpdateCallback,       this.orderUpdateCallback,       this.subscribedCallback,       this.accountConfigUpdateCallback,     )   }    subscribe(cb) {     this.events.on('trade', cb)   }    emit = (data) =&gt; {     this.events.emit('trade', data)   } }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437 SDK  <code>this.api.websockets.userFutureData<\/code> \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437 \u0431\u0438\u0440\u0436\u044b. \u0421\u0430\u043c\u043e\u0439 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043b\u0431\u0435\u043a \u0434\u043b\u044f \u043d\u0430\u0441 <code>this.orderUpdateCallback<\/code> . \u041e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u0443 \u043e\u0440\u0434\u0435\u0440\u0430. \u041b\u043e\u0432\u0438\u043c \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 <code>EventEmitter<\/code> \u0442\u043e\u043c\u0443, \u043a\u0442\u043e \u043d\u0430 \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043b\u0441\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>subscribe<\/code>.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <\/h2>\n<p>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d\u0430 \u043d\u0443\u0436\u043d\u0430? \u0412 \u0431\u0430\u0437\u0435 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043e\u0440\u0434\u0435\u0440\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0441\u044e \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u0442\u043e\u0440\u0433\u043e\u0432\u043b\u0438 \u0431\u043e\u0442\u0430. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u0438\u0445 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u043a \u0431\u0438\u0440\u0436\u0435 \u0438 \u0431\u0430\u043b\u0430\u043d\u0441\u0430\u043c\u0438. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0441\u043c\u043e\u0436\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u0442 \u043f\u0440\u0438\u043d\u0435\u0441 \u043f\u0440\u0438\u0431\u044b\u043b\u0438\/\u0443\u0431\u044b\u0442\u043a\u0430. \u0422\u0443\u0442 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043e\u043b\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0443. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e sequlize.&nbsp;<\/p>\n<pre><code>yarn add sequelize-cli -D yarn add sequelize npx sequelize-cli init<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c docker-compose.yml \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u044b:<\/p>\n<pre><code>version: '3.1'  services:   db:     image: 'postgres:12'     restart: unless-stopped     volumes:       - .\/volumes\/postgresql\/data:\/var\/lib\/postgresql\/data     environment:       POSTGRES_USER: root       POSTGRES_PASSWORD: example       POSTGRES_DB: bot     ports:       - 5432:5432     networks:       - postgres   networks:   postgres:     driver: bridge<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u043c\u043e\u0434\u0435\u043b\u0438. <code>User<\/code>, <code>Order<\/code><\/p>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442. <\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u044f\u0434\u0440\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0447\u0430\u0441\u0442\u0438 \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u0431\u043e\u0442\u0430 \u0442\u043e\u0440\u0433\u043e\u0432\u0430\u0442\u044c.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/562496\/\"> https:\/\/habr.com\/ru\/post\/562496\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0440\u0435\u0439\u0434\u0438\u043d\u0433 \u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u043a\u0440\u0438\u043f\u0442\u043e\u0431\u0438\u0440\u0436\u0435 Binance. \u0411\u043e\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u0435\u0442\u044c:<\/p>\n<ol>\n<li>\n<p>\u0442\u043e\u0440\u0433\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0438\u043d\u043e\u0441\u044f \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0434\u043e\u0445\u043e\u0434<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u0435\u043d \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043e\u0431\u043a\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439 \u0442\u043e\u0440\u0433\u043e\u0432\u043b\u0438<\/p>\n<\/li>\n<li>\n<p>\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u043d\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<\/ol>\n<h2>\u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b<\/h2>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u0438\u0440\u0436\u0430 Binance, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0435\u0441\u0442\u044c \u0448\u0438\u043a\u0430\u0440\u043d\u043e\u0435 api. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u201c\u043a\u0443\u043f\u0438 \u0434\u0435\u0448\u0435\u0432\u043b\u0435\u201d \u0438 \u201c\u043f\u0440\u043e\u0434\u0430\u0439 \u0434\u043e\u0440\u043e\u0436\u0435\u201d. \u041d\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0434\u043b\u044f \u043d\u0430\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u043e\u0442\u0430, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442-\u0442\u0440\u0435\u0439\u0434\u0435\u0440 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u0431\u044b\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0442\u043e\u0440\u0433\u043e\u0432\u043b\u0438 \u043e\u0442 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0447\u0435\u0433\u043e. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0434\u0443\u043b\u044e \u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043a \u043a\u0430\u043a\u043e\u0439 \u0431\u0438\u0440\u0436\u0435 \u0435\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438: \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 API \u0438\u043b\u0438 \u043a \u043f\u0441\u0435\u0432\u0434\u043e-API (\u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f). \u0421 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430:<\/p>\n<figure class=\"full-width\"><figcaption> <\/figcaption><\/figure>\n<p>\u0411\u0430\u0437\u0443 \u0432\u044b\u0431\u0440\u0430\u043b PostgreSQL. \u0422\u0443\u0442 \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0442\u0430\u0439\u043d\u043e\u0433\u043e \u0443\u043c\u044b\u0441\u043b\u0430. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u0443\u044e.&nbsp;<\/p>\n<p>\u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0441\u0442\u043e\u0438\u0442 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f, \u044d\u0442\u043e \u0432\u0441\u0435 \u043d\u0435 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0430\u0442\u044c\u044e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u043c\u0438\u043d\u0438-\u0441\u0435\u0440\u0438\u0430\u043b: &#171;\u041f\u0438\u0448\u0435\u043c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0440\u0435\u0439\u0434 \u0431\u043e\u0442\u0430 \u043d\u0430 JS&#187;. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c, \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043f\u043e\u0443\u0434\u043e\u0431\u043d\u0435\u0439 &#8212; \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c<\/p>\n<h2>\u0421\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u043b\u043e\u0433\u043e\u0432<\/h2>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043b\u0430\u0441\u0441,  \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <code>log<\/code> \u0438 <code>error<\/code>. \u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u0435\u0447\u0430\u0442\u0430\u044e\u0442 \u043b\u043e\u0433 \u0441 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0438 \u043f\u0435\u0440\u0444\u0438\u043a\u0441\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">class LoggerService {   constructor(prefix) {     this.logPrefix = prefix   }    log(...props) {     console.log(new Date().toISOString().substr(0, 19), this.logPrefix, ...props)   }    error(...props) {     console.error(new Date().toISOString().substr(0, 19), this.logPrefix, ...props)   } }<\/code><\/pre>\n<h2>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0438\u0440\u0436\u0443<\/h2>\n<pre><code class=\"bash\">yarn add node-binance-api<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 BaseApiService. \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0432 \u043d\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e Binance SDK, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441 LoggerService. \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u043c\u043e\u0439 \u043e\u043f\u044b\u0442 \u0441 Binance \u043c\u043e\u0433\u0443 \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u043f\u0430\u0440\u044b \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043b\u0430\u0442\u044c \u0446\u0435\u043d\u0443 \u0438 \u043e\u0431\u044c\u0435\u043c \u0441 \u0440\u0430\u0437\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439. \u0412\u0441\u0435 \u044d\u0442\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c, \u0441\u0434\u0435\u043b\u0430\u0432 \u0437\u0430\u043f\u0440\u043e\u0441 <code>futuresExchangeInfo()<\/code>. \u0418 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u043a\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439 \u0434\u043b\u044f \u0446\u0435\u043d\u044b <code>getAssetPricePrecision<\/code> \u0438 \u043e\u0431\u044a\u0435\u043c\u0430 <code>getAssetQuantityPrecision<\/code>.<\/p>\n<pre><code class=\"javascript\">class BaseApiService {   constructor({ client, secret }) {     const { log, error } = new Logger('BaseApiService')     this.log = log     this.error = error      this.api = new NodeBinanceApi().options({       APIKEY: client,       APISECRET: secret,       hedgeMode: true,     })     this.exchangeInfo = {}   }    async init() {     try {       this.exchangeInfo = await this.api.futuresExchangeInfo()     } catch (e) {       this.error('init error', e)     }   }    getAssetQuantityPrecision(symbol) {     const { symbols = [] } = this.exchangeInfo     const s = symbols.find(s =&gt; s.symbol === symbol) || { quantityPrecision: 3 }     return s.quantityPrecision   }    getAssetPricePrecision(symbol) {     const { symbols = [] } = this.exchangeInfo     const s = symbols.find(s =&gt; s.symbol === symbol) || { pricePrecision: 2 }     return s.pricePrecision   } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430, \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u043a\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439 \u0434\u043b\u044f \u0446\u0435\u043d\u044b \u0438 \u043e\u0431\u044c\u0435\u043c\u0430:<\/p>\n<pre><code class=\"javascript\">async futuresOrder(side, symbol, qty, price, params={}) {   try {     qty = Number(qty).toFixed(this.getAssetQuantityPrecision(symbol))     price = Number(price).toFixed(this.getAssetPricePrecision(symbol))     if (!params.type) {       params.type = ORDER.TYPE.MARKET     }     const res = await this.api.futuresOrder(side, symbol, qty, price || false, params)     this.log('futuresOrder', res)     return res   } catch (e) {     console.log('futuresOrder error', e)   } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0431\u043e\u0442 \u0443\u043c\u0435\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0440\u0434\u0435\u0440\u0430. \u041d\u0430\u0443\u0447\u0438\u043c \u0435\u0433\u043e \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437 \u0431\u0438\u0440\u0436\u044b \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431 \u043e\u043d \u043c\u043e\u0433 \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043e\u0440\u0434\u0435\u0440\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 TradeService.<\/p>\n<pre><code class=\"javascript\">class TradeService {   constructor({client, secret}) {     const { log, error } = new LoggerService('TradeService')     this.log = log     this.error = error     this.api = new NodeBinanceApi().options({       APIKEY: client,       APISECRET: secret,       hedgeMode: true,     })     this.events = new EventEmitter()   }    marginCallCallback = (data) =&gt; this.log('marginCallCallback', data)    accountUpdateCallback = (data) =&gt; this.log('accountUpdateCallback', data)    orderUpdateCallback = (data) =&gt; this.emit(data)    subscribedCallback = (data) =&gt; this.log('subscribedCallback', data)    accountConfigUpdateCallback = (data) =&gt; this.log('accountConfigUpdateCallback', data)    startListening() {     this.api.websockets.userFutureData(       this.marginCallCallback,       this.accountUpdateCallback,       this.orderUpdateCallback,       this.subscribedCallback,       this.accountConfigUpdateCallback,     )   }    subscribe(cb) {     this.events.on('trade', cb)   }    emit = (data) =&gt; {     this.events.emit('trade', data)   } }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437 SDK  <code>this.api.websockets.userFutureData<\/code> \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437 \u0431\u0438\u0440\u0436\u044b. \u0421\u0430\u043c\u043e\u0439 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043b\u0431\u0435\u043a \u0434\u043b\u044f \u043d\u0430\u0441 <code>this.orderUpdateCallback<\/code> . \u041e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u0443 \u043e\u0440\u0434\u0435\u0440\u0430. \u041b\u043e\u0432\u0438\u043c \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 <code>EventEmitter<\/code> \u0442\u043e\u043c\u0443, \u043a\u0442\u043e \u043d\u0430 \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043b\u0441\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>subscribe<\/code>.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <\/h2>\n<p>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d\u0430 \u043d\u0443\u0436\u043d\u0430? \u0412 \u0431\u0430\u0437\u0435 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043e\u0440\u0434\u0435\u0440\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0441\u044e \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u0442\u043e\u0440\u0433\u043e\u0432\u043b\u0438 \u0431\u043e\u0442\u0430. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u0438\u0445 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u043a \u0431\u0438\u0440\u0436\u0435 \u0438 \u0431\u0430\u043b\u0430\u043d\u0441\u0430\u043c\u0438. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0441\u043c\u043e\u0436\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u0442 \u043f\u0440\u0438\u043d\u0435\u0441 \u043f\u0440\u0438\u0431\u044b\u043b\u0438\/\u0443\u0431\u044b\u0442\u043a\u0430. \u0422\u0443\u0442 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043e\u043b\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0443. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e sequlize.&nbsp;<\/p>\n<pre><code>yarn add sequelize-cli -D yarn add sequelize npx sequelize-cli init<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c docker-compose.yml \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u044b:<\/p>\n<pre><code>version: '3.1'  services:   db:     image: 'postgres:12'     restart: unless-stopped     volumes:       - .\/volumes\/postgresql\/data:\/var\/lib\/postgresql\/data     environment:       POSTGRES_USER: root       POSTGRES_PASSWORD: example       POSTGRES_DB: bot     ports:       - 5432:5432     networks:       - postgres   networks:   postgres:     driver: bridge<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u043c\u043e\u0434\u0435\u043b\u0438. <code>User<\/code>, <code>Order<\/code><\/p>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442. <\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u044f\u0434\u0440\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0447\u0430\u0441\u0442\u0438 \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u0431\u043e\u0442\u0430 \u0442\u043e\u0440\u0433\u043e\u0432\u0430\u0442\u044c.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/562496\/\"> https:\/\/habr.com\/ru\/post\/562496\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-324834","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=324834"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324834\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}