{"id":348290,"date":"2023-06-02T09:01:42","date_gmt":"2023-06-02T09:01:42","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=348290"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=348290","title":{"rendered":"<span>Open source \u0431\u043e\u0442 \u0434\u043b\u044f \u0442\u043e\u0440\u0433\u043e\u0432 \u043d\u0430 Binance. \u0427\u0430\u0441\u0442\u044c 2<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5ac\/d3d\/c7b\/5acd3dc7bf47805238049ae63fd8c305.png\" width=\"744\" height=\"349\"><\/figure>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0438\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0438\u0440\u0436\u0435\u0439 \u043f\u043e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u044f  <br \/>\u041f\u043e\u043a\u0430 \u0438\u0434\u0443\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0431\u0440\u043e\u0441\u043a\u0438, \u0434\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u043c\u044b \u0438\u0434\u0435\u043c \u0441\u0435\u043c\u0438\u043c\u0438\u043b\u044c\u043d\u044b\u043c\u0438 \u0448\u0430\u0433\u0430\u043c\u0438, \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0441\u044f  \u0441 \u0432\u0430\u043c\u0438 \u043e\u0431\u0449\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0431\u043e\u0442\u0430 \u044d\u0442\u043e \u043e\u0431\u0437\u043e\u0440 \u0438 \u0441\u0431\u043e\u0440 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0432, \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u044b\u0445 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442 \u0447\u0442\u043e \u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0438\u0441\u043a\u043e\u0432.<\/p>\n<p><strong>1. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0431\u0438\u0440\u0436\u0438 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442<\/strong><\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0431\u0438\u0440\u0436\u0438 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 API binance. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u044e\u0447 API. <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a API binance \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442:  <\/p>\n<pre><code class=\"python\">import requests  url = 'https:\/\/api.binance.com\/api\/v3\/ticker\/price'  response = requests.get(url) data = response.json()  cryptocurrencies = [item['symbol'] for item in data]<\/code><\/pre>\n<p> \u0410\u043d\u0430\u043b\u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u0430\u043c<\/p>\n<p>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0446\u0435\u043d\u0430, \u043e\u0431\u044a\u0435\u043c \u0442\u043e\u0440\u0433\u043e\u0432, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0446\u0435\u043d\u044b \u0437\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0442.\u0434. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0446\u0435\u043d\u0435 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b:  <\/p>\n<pre><code class=\"python\">url = 'https:\/\/api.binance.com\/api\/v3\/ticker\/price'  params = {'symbol': 'BTCUSDT'}  response = requests.get(url, params=params) data = response.json()  price = float(data['price']) <\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u043e\u0439 \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b<\/p>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u043e\u0439 \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0441 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u0442\u043e\u0440\u0433\u043e\u0432, \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0446\u0435\u043d\u044b \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u043d\u0435\u0434\u0435\u043b\u044e \u0438 \u0442.\u0434.  <\/p>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435<\/p>\n<p>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0435\u0442\u0438, \u0444\u043e\u0440\u0443\u043c\u044b \u0438 \u0442.\u0434. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 API \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0439 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Google Trends, Brand24, Mention \u0438 \u0442.\u0434. <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Google Trends \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b:  <\/p>\n<pre><code class=\"python\">from pytrends.request import TrendReq  pytrends = TrendReq()  kw_list = ['Bitcoin'] pytrends.build_payload(kw_list, timeframe='today 5-y') data = pytrends.interest_over_time()  popularity = data['Bitcoin'].iloc[-1] <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Python Matplotlib. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0438\u0441\u0443\u0435\u0442 \u0433\u0440\u0430\u0444\u0438\u043a \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u044b \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 30 \u0434\u043d\u0435\u0439:  <\/p>\n<pre><code class=\"python\">import requests import matplotlib.pyplot as plt import pandas as pd from datetime import datetime, timedelta  # \u0417\u0430\u043f\u0440\u043e\u0441 \u0446\u0435\u043d \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 Binance symbol = 'BTCUSDT' interval = '1d' limit = 30 url = 'https:\/\/api.binance.com\/api\/v3\/klines' params = {'symbol': symbol, 'interval': interval, 'limit': limit} response = requests.get(url, params=params) data = response.json()  # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0434\u0430\u0442 \u0438 \u0446\u0435\u043d dates = [] prices = [] for item in data:     date = datetime.fromtimestamp(item[0] \/ 1000)     price = float(item[4])     dates.append(date)     prices.append(price)  # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DataFrame \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u0434\u0430\u0442 \u0438 \u0446\u0435\u043d df = pd.DataFrame({'date': dates, 'price': prices}) df.set_index('date', inplace=True)  # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 plt.figure(figsize=(12, 6)) plt.plot(df.index, df.price) plt.title('Price chart for ' + symbol) plt.xlabel('Date') plt.ylabel('Price') plt.show() <\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0446\u0435\u043d\u0435 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 30 \u0434\u043d\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e API \u0431\u0438\u0440\u0436\u0438 Binance, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u0430\u0442 \u0438 \u0446\u0435\u043d, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 DataFrame \u0438 \u0440\u0438\u0441\u0443\u0435\u0442 \u0433\u0440\u0430\u0444\u0438\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Matplotlib. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0432\u0430\u0448\u0438\u043c\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044f\u043c\u0438.  <\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0438\u0441\u043e\u043a\u0432<\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u044b \u0440\u0438\u0441\u043a\u043e\u0432, \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043e\u0440\u0434\u0435\u0440\u0430 \u0438 \u0440\u044b\u043d\u043e\u0447\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0438 \u0431\u0438\u0440\u0436\u0435\u0432\u0443\u044e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c, \u0438 \u0434\u043e\u043a\u0443\u043f\u0430\u0435\u0442 \u043c\u043e\u043d\u0435\u0442\u044b \u043f\u0440\u0438 \u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u0440\u044b\u043d\u043e\u0447\u043d\u043e\u0439 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u0430\u043a\u0442\u0438\u0432\u0430<\/p>\n<\/p>\n<pre><code class=\"python\">import time import requests  # \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 symbol = 'BTCUSDT' buy_amount = 100   # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043f\u0430\u0435\u043c\u044b\u0445 \u043c\u043e\u043d\u0435\u0442 buy_threshold = 0.05  # \u043f\u043e\u0440\u043e\u0433 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u044b, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u043e\u043a\u0443\u043f\u043a\u0430 (5%) sell_threshold = 0.1  # \u043f\u043e\u0440\u043e\u0433 \u0440\u043e\u0441\u0442\u0430 \u0446\u0435\u043d\u044b, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0434\u0430\u0436\u0430 (10%)  # \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 api_key = 'your_api_key' api_secret = 'your_api_secret'  # URL \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API \u0431\u0438\u0440\u0436\u0438 base_url = 'https:\/\/api.binance.com\/api\/v3'  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u043f\u043e \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u043f\u0430\u0440\u0435 def get_balance(symbol):     url = base_url + '\/account'     params = {'timestamp': int(time.time() * 1000)}     headers = {'X-MBX-APIKEY': api_key}     response = requests.get(url, params=params, headers=headers)     data = response.json()     for item in data['balances']:         if item['asset'] == symbol:             return float(item['free'])     return 0.0  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443 def place_buy_order(symbol, amount):     url = base_url + '\/order'     params = {'symbol': symbol, 'side': 'BUY', 'type': 'MARKET', 'quantity': amount, 'timestamp': int(time.time() * 1000)}     headers = {'X-MBX-APIKEY': api_key}     response = requests.post(url, params=params, headers=headers)     data = response.json()     if 'orderId' in data:         print('Buy order placed. Order ID:', data['orderId'])     else:         print('Buy order failed:', data['msg'])  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0443 def place_sell_order(symbol, amount):     url = base_url + '\/order'     params = {'symbol': symbol, 'side': 'SELL', 'type': 'MARKET', 'quantity': amount, 'timestamp': int(time.time() * 1000)}     headers = {'X-MBX-APIKEY': api_key}     response = requests.post(url, params=params, headers=headers)     data = response.json()     if 'orderId' in data:         print('Sell order placed. Order ID:', data['orderId'])     else:         print('Sell order failed:', data['msg'])  # \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b while True:     # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430     url = base_url + '\/ticker\/price'     params = {'symbol': symbol}     response = requests.get(url, params=params)     data = response.json()     price = float(data['price'])      # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u043f\u043e \u0430\u043a\u0442\u0438\u0432\u0443     balance = get_balance(symbol)      # \u0415\u0441\u043b\u0438 \u0446\u0435\u043d\u0430 \u0443\u043f\u0430\u043b\u0430 \u043d\u0430 buy_threshold (5%), \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c \u043e\u0440\u0434\u0435\u0440 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443     if price &lt; (1 - buy_threshold) * balance \/ buy_amount:         place_buy_order(symbol, buy_amount)         time.sleep(60)  # \u0436\u0434\u0435\u043c 1 \u043c\u0438\u043d\u0443\u0442\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u043e\u0440\u0434\u0435\u0440\u043e\u0432      # \u0415\u0441\u043b\u0438 \u0446\u0435\u043d\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u043d\u0430 sell_threshold (10%), \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c \u043e\u0440\u0434\u0435\u0440 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0443     elif price &gt; (1 + sell_threshold) * balance \/ buy_amount:         place_sell_order(symbol, balance)         time.sleep(60)  # \u0436\u0434\u0435\u043c 1 \u043c\u0438\u043d\u0443\u0442\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u043e\u0440\u0434\u0435\u0440\u043e\u0432      # \u0416\u0434\u0435\u043c 10 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0435\u0440\u0435\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439     time.sleep(10) <\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c API \u0431\u0438\u0440\u0436\u0438 Binance \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430 \u0438 \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u043f\u043e \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u043f\u0430\u0440\u0435, \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u043e\u0432 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443 \u0438 \u043f\u0440\u043e\u0434\u0430\u0436\u0443, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u0440\u043e\u0433\u0438 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0438 \u0440\u043e\u0441\u0442\u0430 \u0446\u0435\u043d\u044b \u0434\u043b\u044f \u0434\u043e\u043a\u0443\u043f\u043a\u0438 \u0438 \u043f\u0440\u043e\u0434\u0430\u0436\u0438. \u0421\u043a\u0440\u0438\u043f\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435, \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044f \u0446\u0435\u043d\u0443 \u0430\u043a\u0442\u0438\u0432\u0430 \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443 \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0430\u0436\u0443 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438.  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0434\u0435\u043b\u044c\u0442\u044b \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0440\u044b\u043d\u043a\u0430 \u0438 \u043f\u0430\u0443\u0437\u044b \u043f\u043e\u043a\u0443\u043f\u043e\u043a\/\u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0439<\/p>\n<pre><code class=\"python\">import time import requests  # \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 symbol = 'BTCUSDT' buy_amount = 100   # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043f\u0430\u0435\u043c\u044b\u0445 \u043c\u043e\u043d\u0435\u0442 delta_threshold = 0.05  # \u043f\u043e\u0440\u043e\u0433 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0434\u0435\u043b\u044c\u0442\u044b, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u043a\u0443\u043f\u043a\u0430 (5%) pause_duration = 60  # \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0430\u0443\u0437\u044b \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445  # \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 api_key = 'your_api_key' api_secret = 'your_api_secret'  # URL \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API \u0431\u0438\u0440\u0436\u0438 base_url = 'https:\/\/api.binance.com\/api\/v3'  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430 def get_price(symbol):     url = base_url + '\/ticker\/price'     params = {'symbol': symbol}     response = requests.get(url, params=params)     data = response.json()     return float(data['price'])  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0433\u043b\u0443\u0431\u0438\u043d\u044b \u0440\u044b\u043d\u043a\u0430 def get_depth(symbol):     url = base_url + '\/depth'     params = {'symbol': symbol}     response = requests.get(url, params=params)     data = response.json()     bids = [(float(item[0]), float(item[1])) for item in data['bids']]     asks = [(float(item[0]), float(item[1])) for item in data['asks']]     return bids, asks  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443 def place_buy_order(symbol, amount):     url = base_url + '\/order'     params = {'symbol': symbol, 'side': 'BUY', 'type': 'MARKET', 'quantity': amount, 'timestamp': int(time.time() * 1000)}     headers = {'X-MBX-APIKEY': api_key}     response = requests.post(url, params=params, headers=headers)     data = response.json()     if 'orderId' in data:         print('Buy order placed. Order ID:', data['orderId'])     else:         print('Buy order failed:', data['msg'])  # \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b while True:     # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430 \u0438 \u0433\u043b\u0443\u0431\u0438\u043d\u044b \u0440\u044b\u043d\u043a\u0430     price = get_price(symbol)     bids, asks = get_depth(symbol)      # \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0434\u0435\u043b\u044c\u0442\u044b     delta = bids[0][0] - price      # \u0415\u0441\u043b\u0438 \u0434\u0435\u043b\u044c\u0442\u0430 \u0443\u043f\u0430\u043b\u0430 \u043d\u0430 delta_threshold (5%), \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c \u043e\u0440\u0434\u0435\u0440 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443     if delta &lt; -delta_threshold * price:         place_buy_order(symbol, buy_amount)         time.sleep(pause_duration)      # \u0416\u0434\u0435\u043c 10 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0435\u0440\u0435\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439     time.sleep(10) <\/code><\/pre>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435, \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044f \u0434\u0435\u043b\u044c\u0442\u0443 \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044f \u043e\u0440\u0434\u0435\u0440 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443, \u0435\u0441\u043b\u0438 \u0434\u0435\u043b\u044c\u0442\u0430 \u0443\u043f\u0430\u043b\u0430 \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u043e\u0433. \u041f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0430\u0443\u0437\u0443 \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0447\u0430\u0441\u0442\u044b\u0445 \u043f\u043e\u043a\u0443\u043f\u043e\u043a\/\u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0439.  <\/p>\n<p>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0441\u0434\u0435\u043b\u043e\u043a \u0447\u0442\u043e \u0431\u044b \u043d\u0435 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0441\u0434\u0435\u043b\u043a\u0438, \u0435\u0441\u043b\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439 \u0431\u0430\u043b\u0430\u043d\u0441 \u043d\u0438\u0436\u0435, \u0447\u0435\u043c &#8212; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/p>\n<pre><code class=\"python\">import time import requests  # \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 symbol = 'BTCUSDT' quantity = 0.001  # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u043d\u0435\u0442 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0434\u0435\u043b\u043a\u0435 min_balance = 100  # \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439 \u0431\u0430\u043b\u0430\u043d\u0441  # \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 api_key = 'your_api_key' api_secret = 'your_api_secret'  # URL \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API \u0431\u0438\u0440\u0436\u0438 base_url = 'https:\/\/api.binance.com\/api\/v3'  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0430 def get_balance(symbol):     url = base_url + '\/account'     params = {'timestamp': int(time.time() * 1000)}     headers = {'X-MBX-APIKEY': api_key}     response = requests.get(url, params=params, headers=headers)     data = response.json()     for item in data['balances']:         if item['asset'] == symbol:             return float(item['free'])     return 0.0  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443 def place_buy_order(symbol, quantity):     url = base_url + '\/order'     params = {'symbol': symbol, 'side': 'BUY', 'type': 'MARKET', 'quantity': quantity, 'timestamp': int(time.time() * 1000)}     headers = {'X-MBX-APIKEY': api_key}     response = requests.post(url, params=params, headers=headers)     data = response.json()     if 'orderId' in data:         print('Buy order placed. Order ID:', data['orderId'])     else:         print('Buy order failed:', data['msg'])  # \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b while True:     # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0430     balance = get_balance(symbol)      # \u0415\u0441\u043b\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439 \u0431\u0430\u043b\u0430\u043d\u0441 \u043d\u0438\u0436\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0443\u043c\u043c\u044b, \u0436\u0434\u0435\u043c 10 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0435\u0440\u0435\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439     if balance &lt; min_balance:         print('Balance is too low:', balance)         time.sleep(10)         continue      # \u0420\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043e\u0440\u0434\u0435\u0440\u0430 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443     place_buy_order(symbol, quantity)      # \u0416\u0434\u0435\u043c 10 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0435\u0440\u0435\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439     time.sleep(10) <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439 \u0431\u0430\u043b\u0430\u043d\u0441 \u043d\u0438\u0436\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0443\u043c\u043c\u044b, \u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0436\u0434\u0435\u0442 10 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0435\u0440\u0435\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439.  <\/p>\n<\/p>\n<p>\u042d\u0442\u043e \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0447\u0430\u0441\u0442\u044c, \u044f \u0435\u0449\u0435 \u043e\u0447\u0435\u043d\u044c \u0434\u0430\u043b\u0435\u043a\u043e \u0434\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u0441\u0431\u043e\u0440\u043a\u0438, \u043d\u043e \u0441\u043a\u043e\u0440\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0430\u044f \u0441\u0431\u043e\u0440\u043a\u0430 \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/p>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \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\/articles\/739378\/\"> https:\/\/habr.com\/ru\/articles\/739378\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<figure class=\"full-width\"><\/figure>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0438\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0438\u0440\u0436\u0435\u0439 \u043f\u043e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u044f  <br \/>\u041f\u043e\u043a\u0430 \u0438\u0434\u0443\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0431\u0440\u043e\u0441\u043a\u0438, \u0434\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u043c\u044b \u0438\u0434\u0435\u043c \u0441\u0435\u043c\u0438\u043c\u0438\u043b\u044c\u043d\u044b\u043c\u0438 \u0448\u0430\u0433\u0430\u043c\u0438, \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0441\u044f  \u0441 \u0432\u0430\u043c\u0438 \u043e\u0431\u0449\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0431\u043e\u0442\u0430 \u044d\u0442\u043e \u043e\u0431\u0437\u043e\u0440 \u0438 \u0441\u0431\u043e\u0440 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0432, \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u044b\u0445 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442 \u0447\u0442\u043e \u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0438\u0441\u043a\u043e\u0432.<\/p>\n<p><strong>1. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0431\u0438\u0440\u0436\u0438 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442<\/strong><\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0431\u0438\u0440\u0436\u0438 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 API binance. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u044e\u0447 API. <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a API binance \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442:  <\/p>\n<pre><code class=\"python\">import requests  url = 'https:\/\/api.binance.com\/api\/v3\/ticker\/price'  response = requests.get(url) data = response.json()  cryptocurrencies = [item['symbol'] for item in data]<\/code><\/pre>\n<p> \u0410\u043d\u0430\u043b\u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u0430\u043c<\/p>\n<p>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0446\u0435\u043d\u0430, \u043e\u0431\u044a\u0435\u043c \u0442\u043e\u0440\u0433\u043e\u0432, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0446\u0435\u043d\u044b \u0437\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0442.\u0434. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0446\u0435\u043d\u0435 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b:  <\/p>\n<pre><code class=\"python\">url = 'https:\/\/api.binance.com\/api\/v3\/ticker\/price'  params = {'symbol': 'BTCUSDT'}  response = requests.get(url, params=params) data = response.json()  price = float(data['price']) <\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u043e\u0439 \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b<\/p>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u043e\u0439 \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0441 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u0442\u043e\u0440\u0433\u043e\u0432, \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0446\u0435\u043d\u044b \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u043d\u0435\u0434\u0435\u043b\u044e \u0438 \u0442.\u0434.  <\/p>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435<\/p>\n<p>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0435\u0442\u0438, \u0444\u043e\u0440\u0443\u043c\u044b \u0438 \u0442.\u0434. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 API \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0439 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Google Trends, Brand24, Mention \u0438 \u0442.\u0434. <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Google Trends \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b:  <\/p>\n<pre><code class=\"python\">from pytrends.request import TrendReq  pytrends = TrendReq()  kw_list = ['Bitcoin'] pytrends.build_payload(kw_list, timeframe='today 5-y') data = pytrends.interest_over_time()  popularity = data['Bitcoin'].iloc[-1] <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Python Matplotlib. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0438\u0441\u0443\u0435\u0442 \u0433\u0440\u0430\u0444\u0438\u043a \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u044b \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 30 \u0434\u043d\u0435\u0439:  <\/p>\n<pre><code class=\"python\">import requests import matplotlib.pyplot as plt import pandas as pd from datetime import datetime, timedelta  # \u0417\u0430\u043f\u0440\u043e\u0441 \u0446\u0435\u043d \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 Binance symbol = 'BTCUSDT' interval = '1d' limit = 30 url = 'https:\/\/api.binance.com\/api\/v3\/klines' params = {'symbol': symbol, 'interval': interval, 'limit': limit} response = requests.get(url, params=params) data = response.json()  # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0434\u0430\u0442 \u0438 \u0446\u0435\u043d dates = [] prices = [] for item in data:     date = datetime.fromtimestamp(item[0] \/ 1000)     price = float(item[4])     dates.append(date)     prices.append(price)  # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DataFrame \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u0434\u0430\u0442 \u0438 \u0446\u0435\u043d df = pd.DataFrame({'date': dates, 'price': prices}) df.set_index('date', inplace=True)  # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 plt.figure(figsize=(12, 6)) plt.plot(df.index, df.price) plt.title('Price chart for ' + symbol) plt.xlabel('Date') plt.ylabel('Price') plt.show() <\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0446\u0435\u043d\u0435 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 30 \u0434\u043d\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e API \u0431\u0438\u0440\u0436\u0438 Binance, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u0430\u0442 \u0438 \u0446\u0435\u043d, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 DataFrame \u0438 \u0440\u0438\u0441\u0443\u0435\u0442 \u0433\u0440\u0430\u0444\u0438\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Matplotlib. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0432\u0430\u0448\u0438\u043c\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044f\u043c\u0438.  <\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0438\u0441\u043e\u043a\u0432<\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u044b \u0440\u0438\u0441\u043a\u043e\u0432, \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043e\u0440\u0434\u0435\u0440\u0430 \u0438 \u0440\u044b\u043d\u043e\u0447\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0438 \u0431\u0438\u0440\u0436\u0435\u0432\u0443\u044e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c, \u0438 \u0434\u043e\u043a\u0443\u043f\u0430\u0435\u0442 \u043c\u043e\u043d\u0435\u0442\u044b \u043f\u0440\u0438 \u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u0440\u044b\u043d\u043e\u0447\u043d\u043e\u0439 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u0430\u043a\u0442\u0438\u0432\u0430<\/p>\n<\/p>\n<pre><code class=\"python\">import time import requests  # \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 symbol = 'BTCUSDT' buy_amount = 100   # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043f\u0430\u0435\u043c\u044b\u0445 \u043c\u043e\u043d\u0435\u0442 buy_threshold = 0.05  # \u043f\u043e\u0440\u043e\u0433 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u044b, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u043e\u043a\u0443\u043f\u043a\u0430 (5%) sell_threshold = 0.1  # \u043f\u043e\u0440\u043e\u0433 \u0440\u043e\u0441\u0442\u0430 \u0446\u0435\u043d\u044b, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0434\u0430\u0436\u0430 (10%)  # \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 api_key = 'your_api_key' api_secret = 'your_api_secret'  # URL \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API \u0431\u0438\u0440\u0436\u0438 base_url = 'https:\/\/api.binance.com\/api\/v3'  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u043f\u043e \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u043f\u0430\u0440\u0435 def get_balance(symbol):     url = base_url + '\/account'     params = {'timestamp': int(time.time() * 1000)}     headers = {'X-MBX-APIKEY': api_key}     response = requests.get(url, params=params, headers=headers)     data = response.json()     for item in data['balances']:         if item['asset'] == symbol:             return float(item['free'])     return 0.0  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443 def place_buy_order(symbol, amount):     url = base_url + '\/order'     params = {'symbol': symbol, 'side': 'BUY', 'type': 'MARKET', 'quantity': amount, 'timestamp': int(time.time() * 1000)}     headers = {'X-MBX-APIKEY': api_key}     response = requests.post(url, params=params, headers=headers)     data = response.json()     if 'orderId' in data:         print('Buy order placed. Order ID:', data['orderId'])     else:         print('Buy order failed:', data['msg'])  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0443 def place_sell_order(symbol, amount):     url = base_url + '\/order'     params = {'symbol': symbol, 'side': 'SELL', 'type': 'MARKET', 'quantity': amount, 'timestamp': int(time.time() * 1000)}     headers = {'X-MBX-APIKEY': api_key}     response = requests.post(url, params=params, headers=headers)     data = response.json()     if 'orderId' in data:         print('Sell order placed. Order ID:', data['orderId'])     else:         print('Sell order failed:', data['msg'])  # \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b while True:     # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430     url = base_url + '\/ticker\/price'     params = {'symbol': symbol}     response = requests.get(url, params=params)     data = response.json()     price = float(data['price'])      # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u043f\u043e \u0430\u043a\u0442\u0438\u0432\u0443     balance = get_balance(symbol)      # \u0415\u0441\u043b\u0438 \u0446\u0435\u043d\u0430 \u0443\u043f\u0430\u043b\u0430 \u043d\u0430 buy_threshold (5%), \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c \u043e\u0440\u0434\u0435\u0440 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443     if price &lt; (1 - buy_threshold) * balance \/ buy_amount:         place_buy_order(symbol, buy_amount)         time.sleep(60)  # \u0436\u0434\u0435\u043c 1 \u043c\u0438\u043d\u0443\u0442\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u043e\u0440\u0434\u0435\u0440\u043e\u0432      # \u0415\u0441\u043b\u0438 \u0446\u0435\u043d\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u043d\u0430 sell_threshold (10%), \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c \u043e\u0440\u0434\u0435\u0440 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0443     elif price &gt; (1 + sell_threshold) * balance \/ buy_amount:         place_sell_order(symbol, balance)         time.sleep(60)  # \u0436\u0434\u0435\u043c 1 \u043c\u0438\u043d\u0443\u0442\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u043e\u0440\u0434\u0435\u0440\u043e\u0432      # \u0416\u0434\u0435\u043c 10 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0435\u0440\u0435\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439     time.sleep(10) <\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c API \u0431\u0438\u0440\u0436\u0438 Binance \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430 \u0438 \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u043f\u043e \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u043f\u0430\u0440\u0435, \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u043e\u0432 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443 \u0438 \u043f\u0440\u043e\u0434\u0430\u0436\u0443, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u0440\u043e\u0433\u0438 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0438 \u0440\u043e\u0441\u0442\u0430 \u0446\u0435\u043d\u044b \u0434\u043b\u044f \u0434\u043e\u043a\u0443\u043f\u043a\u0438 \u0438 \u043f\u0440\u043e\u0434\u0430\u0436\u0438. \u0421\u043a\u0440\u0438\u043f\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435, \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044f \u0446\u0435\u043d\u0443 \u0430\u043a\u0442\u0438\u0432\u0430 \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443 \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0430\u0436\u0443 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438.  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0434\u0435\u043b\u044c\u0442\u044b \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0440\u044b\u043d\u043a\u0430 \u0438 \u043f\u0430\u0443\u0437\u044b \u043f\u043e\u043a\u0443\u043f\u043e\u043a\/\u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0439<\/p>\n<pre><code class=\"python\">import time import requests  # \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 symbol = 'BTCUSDT' buy_amount = 100   # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043f\u0430\u0435\u043c\u044b\u0445 \u043c\u043e\u043d\u0435\u0442 delta_threshold = 0.05  # \u043f\u043e\u0440\u043e\u0433 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0434\u0435\u043b\u044c\u0442\u044b, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u043a\u0443\u043f\u043a\u0430 (5%) pause_duration = 60  # \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0430\u0443\u0437\u044b \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445  # \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 api_key = 'your_api_key' api_secret = 'your_api_secret'  # URL \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API \u0431\u0438\u0440\u0436\u0438 base_url = 'https:\/\/api.binance.com\/api\/v3'  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430 def get_price(symbol):     url = base_url + '\/ticker\/price'     params = {'symbol': symbol}     response = requests.get(url, params=params)     data = response.json()     return float(data['price'])  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0433\u043b\u0443\u0431\u0438\u043d\u044b \u0440\u044b\u043d\u043a\u0430 def get_depth(symbol):     url = base_url + '\/depth'     params = {'symbol': symbol}     response = requests.get(url, params=params)     data = response.json()     bids = [(float(item[0]), float(item[1])) for item in data['bids']]     asks = [(float(item[0]), float(item[1])) for item in data['asks']]     return bids, asks  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443 def place_buy_order(symbol, amount):     url = base_url + '\/order'     params = {'symbol': symbol, 'side': 'BUY', 'type': 'MARKET', 'quantity': amount, 'timestamp': int(time.time() * 1000)}     headers = {'X-MBX-APIKEY': api_key}     response = requests.post(url, params=params, headers=headers)     data = response.json()     if 'orderId' in data:         print('Buy order placed. Order ID:', data['orderId'])     else:         print('Buy order failed:', data['msg'])  # \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b while True:     # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430 \u0438 \u0433\u043b\u0443\u0431\u0438\u043d\u044b \u0440\u044b\u043d\u043a\u0430     price = get_price(symbol)     bids, asks = get_depth(symbol)      # \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0434\u0435\u043b\u044c\u0442\u044b     delta = bids[0][0] - price      # \u0415\u0441\u043b\u0438 \u0434\u0435\u043b\u044c\u0442\u0430 \u0443\u043f\u0430\u043b\u0430 \u043d\u0430 delta_threshold (5%), \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c \u043e\u0440\u0434\u0435\u0440 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443     if delta &lt; -delta_threshold * price:         place_buy_order(symbol, buy_amount)         time.sleep(pause_duration)      # \u0416\u0434\u0435\u043c 10 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0435\u0440\u0435\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439     time.sleep(10) <\/code><\/pre>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435, \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044f \u0434\u0435\u043b\u044c\u0442\u0443 \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044f \u043e\u0440\u0434\u0435\u0440 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443, \u0435\u0441\u043b\u0438 \u0434\u0435\u043b\u044c\u0442\u0430 \u0443\u043f\u0430\u043b\u0430 \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u043e\u0433. \u041f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0440\u0434\u0435\u0440\u0430 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0430\u0443\u0437\u0443 \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0447\u0430\u0441\u0442\u044b\u0445 \u043f\u043e\u043a\u0443\u043f\u043e\u043a\/\u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0439.  <\/p>\n<p>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0441\u0434\u0435\u043b\u043e\u043a \u0447\u0442\u043e \u0431\u044b \u043d\u0435 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0441\u0434\u0435\u043b\u043a\u0438, \u0435\u0441\u043b\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439 \u0431\u0430\u043b\u0430\u043d\u0441 \u043d\u0438\u0436\u0435, \u0447\u0435\u043c &#8212; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/p>\n<pre><code class=\"python\">import time import requests  # \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 symbol = 'BTCUSDT' quantity = 0.001  # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u043d\u0435\u0442 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0434\u0435\u043b\u043a\u0435 min_balance = 100  # \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439 \u0431\u0430\u043b\u0430\u043d\u0441  # \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 api_key = 'your_api_key' api_secret = 'your_api_secret'  # URL \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API \u0431\u0438\u0440\u0436\u0438 base_url = 'https:\/\/api.binance.com\/api\/v3'  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e<\/code><\/pre>\n<p><\/br><\/br><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\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-348290","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348290","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=348290"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348290\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}