freqtrade_origin/en/2020.7/sql_cheatsheet/index.html

1399 lines
44 KiB
HTML

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="prev" href="../plotting/">
<link rel="next" href="../advanced-setup/">
<link rel="icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.6.0, mkdocs-material-9.5.30">
<title>SQL Cheatsheet - Freqtrade</title>
<link rel="stylesheet" href="../assets/stylesheets/main.3cba04c6.min.css">
<link rel="stylesheet" href="../assets/stylesheets/palette.06af60db.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<link rel="stylesheet" href="../stylesheets/ft.extra.css">
<script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="blue-grey" data-md-color-accent="tear">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#sql-helper" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<div data-md-color-scheme="default" data-md-component="outdated" hidden>
</div>
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href=".." title="Freqtrade" class="md-header__button md-logo" aria-label="Freqtrade" data-md-component="logo">
<img src="../images/logo.png" alt="logo">
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
Freqtrade
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
SQL Cheatsheet
</span>
</div>
</div>
</div>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
</button>
</nav>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href=".." title="Freqtrade" class="md-nav__button md-logo" aria-label="Freqtrade" data-md-component="logo">
<img src="../images/logo.png" alt="logo">
</a>
Freqtrade
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href=".." class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../docker/" class="md-nav__link">
<span class="md-ellipsis">
Installation Docker
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../installation/" class="md-nav__link">
<span class="md-ellipsis">
Installation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../bot-basics/" class="md-nav__link">
<span class="md-ellipsis">
Freqtrade Basics
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../configuration/" class="md-nav__link">
<span class="md-ellipsis">
Configuration
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../strategy-customization/" class="md-nav__link">
<span class="md-ellipsis">
Strategy Customization
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../stoploss/" class="md-nav__link">
<span class="md-ellipsis">
Stoploss
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../bot-usage/" class="md-nav__link">
<span class="md-ellipsis">
Start the bot
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_9" >
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
<span class="md-ellipsis">
Control the bot
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_9_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_9">
<span class="md-nav__icon md-icon"></span>
Control the bot
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../telegram-usage/" class="md-nav__link">
<span class="md-ellipsis">
Telegram
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../webhook-config/" class="md-nav__link">
<span class="md-ellipsis">
Web Hook
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../rest-api/" class="md-nav__link">
<span class="md-ellipsis">
REST API
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../data-download/" class="md-nav__link">
<span class="md-ellipsis">
Data Downloading
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../backtesting/" class="md-nav__link">
<span class="md-ellipsis">
Backtesting
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../hyperopt/" class="md-nav__link">
<span class="md-ellipsis">
Hyperopt
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../edge/" class="md-nav__link">
<span class="md-ellipsis">
Edge Positioning
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../utils/" class="md-nav__link">
<span class="md-ellipsis">
Utility Subcommands
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../exchanges/" class="md-nav__link">
<span class="md-ellipsis">
Exchange-specific Notes
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../faq/" class="md-nav__link">
<span class="md-ellipsis">
FAQ
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_17" >
<label class="md-nav__link" for="__nav_17" id="__nav_17_label" tabindex="0">
<span class="md-ellipsis">
Data Analysis
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_17_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_17">
<span class="md-nav__icon md-icon"></span>
Data Analysis
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../data-analysis/" class="md-nav__link">
<span class="md-ellipsis">
Jupyter Notebooks
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../strategy_analysis_example/" class="md-nav__link">
<span class="md-ellipsis">
Strategy analysis
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../plotting/" class="md-nav__link">
<span class="md-ellipsis">
Plotting
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
SQL Cheatsheet
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
SQL Cheatsheet
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#install-sqlite3" class="md-nav__link">
<span class="md-ellipsis">
Install sqlite3
</span>
</a>
<nav class="md-nav" aria-label="Install sqlite3">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#ubuntudebian-installation" class="md-nav__link">
<span class="md-ellipsis">
Ubuntu/Debian installation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#using-sqlite3-via-docker-compose" class="md-nav__link">
<span class="md-ellipsis">
Using sqlite3 via docker-compose
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#open-the-db" class="md-nav__link">
<span class="md-ellipsis">
Open the DB
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#table-structure" class="md-nav__link">
<span class="md-ellipsis">
Table structure
</span>
</a>
<nav class="md-nav" aria-label="Table structure">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#list-tables" class="md-nav__link">
<span class="md-ellipsis">
List tables
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#display-table-structure" class="md-nav__link">
<span class="md-ellipsis">
Display table structure
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#trade-table-structure" class="md-nav__link">
<span class="md-ellipsis">
Trade table structure
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#get-all-trades-in-the-table" class="md-nav__link">
<span class="md-ellipsis">
Get all trades in the table
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#fix-trade-still-open-after-a-manual-sell-on-the-exchange" class="md-nav__link">
<span class="md-ellipsis">
Fix trade still open after a manual sell on the exchange
</span>
</a>
<nav class="md-nav" aria-label="Fix trade still open after a manual sell on the exchange">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#example" class="md-nav__link">
<span class="md-ellipsis">
Example
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#manually-insert-a-new-trade" class="md-nav__link">
<span class="md-ellipsis">
Manually insert a new trade
</span>
</a>
<nav class="md-nav" aria-label="Manually insert a new trade">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#insert-trade-example" class="md-nav__link">
<span class="md-ellipsis">
Insert trade example
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#remove-trade-from-the-database" class="md-nav__link">
<span class="md-ellipsis">
Remove trade from the database
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../advanced-setup/" class="md-nav__link">
<span class="md-ellipsis">
Advanced Post-installation Tasks
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../strategy-advanced/" class="md-nav__link">
<span class="md-ellipsis">
Advanced Strategy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../advanced-hyperopt/" class="md-nav__link">
<span class="md-ellipsis">
Advanced Hyperopt
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../sandbox-testing/" class="md-nav__link">
<span class="md-ellipsis">
Sandbox Testing
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../deprecated/" class="md-nav__link">
<span class="md-ellipsis">
Deprecated Features
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../developer/" class="md-nav__link">
<span class="md-ellipsis">
Contributors Guide
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#install-sqlite3" class="md-nav__link">
<span class="md-ellipsis">
Install sqlite3
</span>
</a>
<nav class="md-nav" aria-label="Install sqlite3">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#ubuntudebian-installation" class="md-nav__link">
<span class="md-ellipsis">
Ubuntu/Debian installation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#using-sqlite3-via-docker-compose" class="md-nav__link">
<span class="md-ellipsis">
Using sqlite3 via docker-compose
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#open-the-db" class="md-nav__link">
<span class="md-ellipsis">
Open the DB
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#table-structure" class="md-nav__link">
<span class="md-ellipsis">
Table structure
</span>
</a>
<nav class="md-nav" aria-label="Table structure">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#list-tables" class="md-nav__link">
<span class="md-ellipsis">
List tables
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#display-table-structure" class="md-nav__link">
<span class="md-ellipsis">
Display table structure
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#trade-table-structure" class="md-nav__link">
<span class="md-ellipsis">
Trade table structure
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#get-all-trades-in-the-table" class="md-nav__link">
<span class="md-ellipsis">
Get all trades in the table
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#fix-trade-still-open-after-a-manual-sell-on-the-exchange" class="md-nav__link">
<span class="md-ellipsis">
Fix trade still open after a manual sell on the exchange
</span>
</a>
<nav class="md-nav" aria-label="Fix trade still open after a manual sell on the exchange">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#example" class="md-nav__link">
<span class="md-ellipsis">
Example
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#manually-insert-a-new-trade" class="md-nav__link">
<span class="md-ellipsis">
Manually insert a new trade
</span>
</a>
<nav class="md-nav" aria-label="Manually insert a new trade">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#insert-trade-example" class="md-nav__link">
<span class="md-ellipsis">
Insert trade example
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#remove-trade-from-the-database" class="md-nav__link">
<span class="md-ellipsis">
Remove trade from the database
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="sql-helper">SQL Helper<a class="headerlink" href="#sql-helper" title="Permanent link">&para;</a></h1>
<p>This page contains some help if you want to edit your sqlite db.</p>
<h2 id="install-sqlite3">Install sqlite3<a class="headerlink" href="#install-sqlite3" title="Permanent link">&para;</a></h2>
<p>Sqlite3 is a terminal based sqlite application.
Feel free to use a visual Database editor like SqliteBrowser if you feel more comfortable with that.</p>
<h3 id="ubuntudebian-installation">Ubuntu/Debian installation<a class="headerlink" href="#ubuntudebian-installation" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code>sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>sqlite3
</code></pre></div>
<h3 id="using-sqlite3-via-docker-compose">Using sqlite3 via docker-compose<a class="headerlink" href="#using-sqlite3-via-docker-compose" title="Permanent link">&para;</a></h3>
<p>The freqtrade docker image does contain sqlite3, so you can edit the database without having to install anything on the host system.</p>
<div class="highlight"><pre><span></span><code>docker-compose<span class="w"> </span><span class="nb">exec</span><span class="w"> </span>freqtrade<span class="w"> </span>/bin/bash
sqlite3<span class="w"> </span>&lt;databasefile&gt;.sqlite
</code></pre></div>
<h2 id="open-the-db">Open the DB<a class="headerlink" href="#open-the-db" title="Permanent link">&para;</a></h2>
<div class="highlight"><pre><span></span><code>sqlite3
.open<span class="w"> </span>&lt;filepath&gt;
</code></pre></div>
<h2 id="table-structure">Table structure<a class="headerlink" href="#table-structure" title="Permanent link">&para;</a></h2>
<h3 id="list-tables">List tables<a class="headerlink" href="#list-tables" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code>.tables
</code></pre></div>
<h3 id="display-table-structure">Display table structure<a class="headerlink" href="#display-table-structure" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code>.schema<span class="w"> </span>&lt;table_name&gt;
</code></pre></div>
<h3 id="trade-table-structure">Trade table structure<a class="headerlink" href="#trade-table-structure" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code><span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">trades</span>
<span class="w"> </span><span class="n">id</span><span class="w"> </span><span class="nb">INTEGER</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="n">exchange</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="n">pair</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="n">is_open</span><span class="w"> </span><span class="nb">BOOLEAN</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="n">fee_open</span><span class="w"> </span><span class="nb">FLOAT</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="n">fee_open_cost</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">fee_open_currency</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">,</span>
<span class="w"> </span><span class="n">fee_close</span><span class="w"> </span><span class="nb">FLOAT</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="n">fee_close_cost</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">fee_close_currency</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">,</span>
<span class="w"> </span><span class="n">open_rate</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">open_rate_requested</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">open_trade_price</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_rate</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_rate_requested</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_profit</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_profit_abs</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">stake_amount</span><span class="w"> </span><span class="nb">FLOAT</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="n">amount</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">open_date</span><span class="w"> </span><span class="n">DATETIME</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_date</span><span class="w"> </span><span class="n">DATETIME</span><span class="p">,</span>
<span class="w"> </span><span class="n">open_order_id</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">,</span>
<span class="w"> </span><span class="n">stop_loss</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">stop_loss_pct</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">initial_stop_loss</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">initial_stop_loss_pct</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">stoploss_order_id</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">,</span>
<span class="w"> </span><span class="n">stoploss_last_update</span><span class="w"> </span><span class="n">DATETIME</span><span class="p">,</span>
<span class="w"> </span><span class="n">max_rate</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">min_rate</span><span class="w"> </span><span class="nb">FLOAT</span><span class="p">,</span>
<span class="w"> </span><span class="n">sell_reason</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">,</span>
<span class="w"> </span><span class="n">strategy</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">,</span>
<span class="w"> </span><span class="n">timeframe</span><span class="w"> </span><span class="nb">INTEGER</span><span class="p">,</span>
<span class="w"> </span><span class="k">PRIMARY</span><span class="w"> </span><span class="k">KEY</span><span class="w"> </span><span class="p">(</span><span class="n">id</span><span class="p">),</span>
<span class="w"> </span><span class="k">CHECK</span><span class="w"> </span><span class="p">(</span><span class="n">is_open</span><span class="w"> </span><span class="k">IN</span><span class="w"> </span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">))</span>
<span class="p">);</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">INDEX</span><span class="w"> </span><span class="n">ix_trades_stoploss_order_id</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="n">trades</span><span class="w"> </span><span class="p">(</span><span class="n">stoploss_order_id</span><span class="p">);</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">INDEX</span><span class="w"> </span><span class="n">ix_trades_pair</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="n">trades</span><span class="w"> </span><span class="p">(</span><span class="n">pair</span><span class="p">);</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">INDEX</span><span class="w"> </span><span class="n">ix_trades_is_open</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="n">trades</span><span class="w"> </span><span class="p">(</span><span class="n">is_open</span><span class="p">);</span>
</code></pre></div>
<h2 id="get-all-trades-in-the-table">Get all trades in the table<a class="headerlink" href="#get-all-trades-in-the-table" title="Permanent link">&para;</a></h2>
<div class="highlight"><pre><span></span><code><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">trades</span><span class="p">;</span>
</code></pre></div>
<h2 id="fix-trade-still-open-after-a-manual-sell-on-the-exchange">Fix trade still open after a manual sell on the exchange<a class="headerlink" href="#fix-trade-still-open-after-a-manual-sell-on-the-exchange" title="Permanent link">&para;</a></h2>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Manually selling a pair on the exchange will not be detected by the bot and it will try to sell anyway. Whenever possible, forcesell <tradeid> should be used to accomplish the same thing.<br />
It is strongly advised to backup your database file before making any manual changes.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This should not be necessary after /forcesell, as forcesell orders are closed automatically by the bot on the next iteration.</p>
</div>
<div class="highlight"><pre><span></span><code><span class="k">UPDATE</span><span class="w"> </span><span class="n">trades</span>
<span class="k">SET</span><span class="w"> </span><span class="n">is_open</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_date</span><span class="o">=&lt;</span><span class="n">close_date</span><span class="o">&gt;</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_rate</span><span class="o">=&lt;</span><span class="n">close_rate</span><span class="o">&gt;</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_profit</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">close_rate</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">open_rate</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_profit_abs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">amount</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="o">&lt;</span><span class="n">close_rate</span><span class="o">&gt;</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">fee_close</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="p">(</span><span class="n">amount</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="p">(</span><span class="n">open_rate</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">fee_open</span><span class="p">))),</span>
<span class="w"> </span><span class="n">sell_reason</span><span class="o">=&lt;</span><span class="n">sell_reason</span><span class="o">&gt;</span>
<span class="k">WHERE</span><span class="w"> </span><span class="n">id</span><span class="o">=&lt;</span><span class="n">trade_ID_to_update</span><span class="o">&gt;</span><span class="p">;</span>
</code></pre></div>
<h3 id="example">Example<a class="headerlink" href="#example" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code><span class="k">UPDATE</span><span class="w"> </span><span class="n">trades</span>
<span class="k">SET</span><span class="w"> </span><span class="n">is_open</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_date</span><span class="o">=</span><span class="s1">&#39;2020-06-20 03:08:45.103418&#39;</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_rate</span><span class="o">=</span><span class="mi">0</span><span class="p">.</span><span class="mi">19638016</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_profit</span><span class="o">=</span><span class="mi">0</span><span class="p">.</span><span class="mi">0496</span><span class="p">,</span>
<span class="w"> </span><span class="n">close_profit_abs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">amount</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">19638016</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">fee_close</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="p">(</span><span class="n">amount</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">open_rate</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">fee_open</span><span class="p">))),</span>
<span class="w"> </span><span class="n">sell_reason</span><span class="o">=</span><span class="s1">&#39;force_sell&#39;</span><span class="w"> </span>
<span class="k">WHERE</span><span class="w"> </span><span class="n">id</span><span class="o">=</span><span class="mi">31</span><span class="p">;</span>
</code></pre></div>
<h2 id="manually-insert-a-new-trade">Manually insert a new trade<a class="headerlink" href="#manually-insert-a-new-trade" title="Permanent link">&para;</a></h2>
<div class="highlight"><pre><span></span><code><span class="k">INSERT</span><span class="w"> </span><span class="k">INTO</span><span class="w"> </span><span class="n">trades</span><span class="w"> </span><span class="p">(</span><span class="n">exchange</span><span class="p">,</span><span class="w"> </span><span class="n">pair</span><span class="p">,</span><span class="w"> </span><span class="n">is_open</span><span class="p">,</span><span class="w"> </span><span class="n">fee_open</span><span class="p">,</span><span class="w"> </span><span class="n">fee_close</span><span class="p">,</span><span class="w"> </span><span class="n">open_rate</span><span class="p">,</span><span class="w"> </span><span class="n">stake_amount</span><span class="p">,</span><span class="w"> </span><span class="n">amount</span><span class="p">,</span><span class="w"> </span><span class="n">open_date</span><span class="p">)</span>
<span class="k">VALUES</span><span class="w"> </span><span class="p">(</span><span class="s1">&#39;binance&#39;</span><span class="p">,</span><span class="w"> </span><span class="s1">&#39;ETH/BTC&#39;</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">0025</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">0025</span><span class="p">,</span><span class="w"> </span><span class="o">&lt;</span><span class="n">open_rate</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="o">&lt;</span><span class="n">stake_amount</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="o">&lt;</span><span class="n">amount</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="s1">&#39;&lt;datetime&gt;&#39;</span><span class="p">)</span>
</code></pre></div>
<h3 id="insert-trade-example">Insert trade example<a class="headerlink" href="#insert-trade-example" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code><span class="k">INSERT</span><span class="w"> </span><span class="k">INTO</span><span class="w"> </span><span class="n">trades</span><span class="w"> </span><span class="p">(</span><span class="n">exchange</span><span class="p">,</span><span class="w"> </span><span class="n">pair</span><span class="p">,</span><span class="w"> </span><span class="n">is_open</span><span class="p">,</span><span class="w"> </span><span class="n">fee_open</span><span class="p">,</span><span class="w"> </span><span class="n">fee_close</span><span class="p">,</span><span class="w"> </span><span class="n">open_rate</span><span class="p">,</span><span class="w"> </span><span class="n">stake_amount</span><span class="p">,</span><span class="w"> </span><span class="n">amount</span><span class="p">,</span><span class="w"> </span><span class="n">open_date</span><span class="p">)</span>
<span class="k">VALUES</span><span class="w"> </span><span class="p">(</span><span class="s1">&#39;binance&#39;</span><span class="p">,</span><span class="w"> </span><span class="s1">&#39;ETH/BTC&#39;</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">0025</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">0025</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">00258580</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">002</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">7715262081</span><span class="p">,</span><span class="w"> </span><span class="s1">&#39;2020-06-28 12:44:24.000000&#39;</span><span class="p">)</span>
</code></pre></div>
<h2 id="remove-trade-from-the-database">Remove trade from the database<a class="headerlink" href="#remove-trade-from-the-database" title="Permanent link">&para;</a></h2>
<p>Maybe you'd like to remove a trade from the database, because something went wrong.</p>
<div class="highlight"><pre><span></span><code><span class="k">DELETE</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">trades</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&lt;</span><span class="n">tradeid</span><span class="o">&gt;</span><span class="p">;</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code><span class="k">DELETE</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">trades</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">31</span><span class="p">;</span>
</code></pre></div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>This will remove this trade from the database. Please make sure you got the correct id and <strong>NEVER</strong> run this query without the <code>where</code> clause.</p>
</div>
</article>
</div>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"base": "..", "features": [], "search": "../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": {"provider": "mike"}}</script>
<script src="../assets/javascripts/bundle.fe8b6f2b.min.js"></script>
</body>
</html>