Compare commits

..

138 Commits

Author SHA1 Message Date
a2848481eb pnl, tax, transactions 2025-03-01 15:28:50 +01:00
06bfc85485 pnl, tax, transactions 2025-02-28 17:22:42 +01:00
6aec58b05e pnl, tax, transactions 2025-02-27 10:44:55 +01:00
412d09cbe1 added caching 2025-02-22 16:49:50 +01:00
b0c7d0192a fix DXY only 2024-12-25 13:44:11 +01:00
0652ef3a7e fix -delete 2024-12-25 13:31:36 +01:00
0181800430 cleanup 2024-12-23 22:31:12 +01:00
2fb220ccfb first calc indicators only last for the last 810 lines to speed up things 2024-12-23 16:28:38 +01:00
c70713356d fix empty level var 2024-12-20 14:55:10 +01:00
4a02ad0e51 performance improvements; fixes 2024-12-20 14:27:40 +01:00
b2bf0ad683 fix: array reference 2024-12-20 14:22:48 +01:00
af1497c1c2 performance improvements; fixes 2024-12-20 13:05:04 +01:00
099a42d214 fix: array reference 2024-12-19 22:50:39 +01:00
c728795a9a reverse array 2024-12-19 21:50:21 +01:00
78f9b15413 fixes 2024-12-19 17:03:48 +01:00
29e04d9533 yahoo finance 2024-12-19 15:13:04 +01:00
4dc63bd6ab autoupdate 2024-12-18 15:14:39 +01:00
58c2895238 fixes/additional infos 2024-12-18 13:07:01 +01:00
adb75b4e22 fixes/additional infos 2024-12-18 12:43:04 +01:00
3415280a33 fixes/additional infos 2024-12-18 12:03:31 +01:00
3cd119dda1 fixes/additional infos 2024-12-18 11:35:55 +01:00
0ca094d353 fixes adjust sl on short position 2024-12-17 17:21:45 +01:00
6c0c786c70 fixes if no EMA200 data available 2024-12-17 13:03:59 +01:00
a8132e3992 fixes 2024-12-17 11:39:38 +01:00
705df375c9 fixes 2024-12-17 11:37:32 +01:00
5326e3f5bc fixes tp/sl 2024-12-17 11:07:40 +01:00
9f72619f51 fixes tp/sl 2024-12-16 22:30:51 +01:00
b279735ae8 fixes tp/sl 2024-12-16 18:04:39 +01:00
76f556b1ad fixes tp/sl 2024-12-16 17:38:39 +01:00
21125e84e5 fix typo 2024-12-16 16:40:29 +01:00
0109799a4c fix typo 2024-12-16 16:24:05 +01:00
8b83d450d0 fix asset_amount: 2024-12-16 16:12:17 +01:00
6b51e610ff sl/tp 2024-12-15 15:26:03 +01:00
4328807975 added contracts/asset-amount 2024-12-13 10:15:43 +01:00
8f307438cf fix 2024-12-12 16:27:27 +01:00
b79313d1e4 example manage positions 2024-12-12 16:24:19 +01:00
694184a25f update fpr ccxt triggers, stoploss-change 2024-12-12 16:23:47 +01:00
0a6d7264cb functions: cancel order(s) 2024-12-12 16:23:15 +01:00
f66f1934a1 fix score, example trade balance inn % from complete balance, small fixes - thanks to andrius for hint(s) 2024-12-04 15:23:51 +01:00
f0c3303246 fix score, example trade balance inn % from complete balance, small fixes - thanks to andrius for hint(s) 2024-12-04 15:22:31 +01:00
4935a317a6 obsolete 2024-12-03 20:59:43 +01:00
5adfc2920f fix 2024-12-03 20:35:20 +01:00
c835b51245 fix memory leak 2024-12-03 12:06:10 +01:00
e2be72b43b return 0 fix 2024-11-28 14:42:07 +01:00
4122d60f34 fix market 2024-11-28 10:05:54 +01:00
544fdb2a7a fix market 2024-11-28 00:24:53 +01:00
e1a4bb4a46 fix marketCC 2024-11-27 23:49:09 +01:00
cd55084d54 market order fix 2024-11-27 14:50:30 +01:00
4e2c90fe0b limits 2024-11-26 11:56:47 +01:00
afe83c4811 use defauölt traefik pw 2024-11-25 16:53:48 +01:00
a7a94fdd18 doc sources 2024-11-05 14:03:15 +01:00
bae56de644 fix no num data 2024-11-05 13:54:49 +01:00
5536abbd0b cleanup 2024-11-05 13:44:20 +01:00
fb0c346e2f added MARKETDATA 2024-11-05 13:43:27 +01:00
d3352c4d28 speedup with less lines 2024-11-05 12:46:00 +01:00
c9cc555b42 cleanup marketdata download: FEAR_AND_GREED_ALTERNATIVEME FEAR_AND_GREED_CNN US_CONSUMER_PRICE_INDEX_CPI US_UNEMPLOYMENT_RATE US_FED_FUNDS_RATE BINANCE_LONG_SHORT_RATIO_ACCOUNT BINANCE_LONG_SHORT_RATIO_TAKER BINANCE_OPEN_INTEREST 2024-11-05 12:45:16 +01:00
fa4fec677b percentage change year for specific values like CPI, added calc OHLCV, speed ptimization, fixes 2024-11-05 12:43:24 +01:00
092bf62581 fix EMA/SMA 2024-11-05 12:38:12 +01:00
4f3f7fdbec error reporting and added get_marketdata_all 2024-11-05 12:37:29 +01:00
8b17a7053b less frequent 2024-11-05 12:36:32 +01:00
2cea87bce7 rm error msg fix 2024-11-05 12:35:35 +01:00
bf0bb1e77e fix . not in printf 2024-11-02 17:16:19 +01:00
98d185067b fix 1st day in month 2024-11-01 13:40:30 +01:00
655c3b4032 fix exponential number notation 2024-10-21 21:11:27 +02:00
edfa828c2a day fetches 1 minute later 2024-10-21 21:08:36 +02:00
c0a3e85888 fix, calculating amount and leverage 2024-10-21 21:08:12 +02:00
f69d75b1b7 fix 2024-10-18 23:07:25 +02:00
c3e0060347 optimations and fixes 2024-10-18 23:00:15 +02:00
d71f344777 optimations and fixes 2024-10-18 23:00:11 +02:00
dcf5336a75 speed optimations 2024-10-17 22:39:31 +02:00
f36485f1eb sort multiple matches 2024-10-17 17:16:59 +02:00
16bb308c4b add marketcap to ID-file ; if multiple items use the one with largest marketcap 2024-10-17 17:04:45 +02:00
d1805e5fc4 comment 2024-10-17 17:03:22 +02:00
a274818463 typo fix 2024-10-17 17:02:57 +02:00
5338017760 less verbose; fix timeframes 2024-10-17 17:01:50 +02:00
26cc075984 example strategy 2024-10-14 21:48:52 +02:00
7e21738be2 fixes error handling and coinmarketcap ids 2024-10-04 11:58:40 +02:00
d6cefa56d1 fixes error handling and coinmarketcap ids 2024-10-02 18:09:53 +02:00
ae70ddfb48 fix 2024-09-29 21:58:43 +02:00
ed92ab87af ccxt update 2024-09-29 21:52:45 +02:00
a3b1387022 fix phemex doku 2024-09-29 21:18:26 +02:00
8123deb54c fix 2024-09-29 21:02:48 +02:00
2261635fb5 fix 2024-09-29 20:57:41 +02:00
a2c90f47e3 fix 2024-09-27 12:23:21 +02:00
6b9c31bf2b fix weekends 2024-09-27 11:51:32 +02:00
335c1ee349 fix 2024-09-26 09:09:36 +02:00
53861b2a8e fix 2024-09-24 20:36:53 +02:00
21cddf372b fix 2024-09-24 17:44:28 +02:00
55a27389a2 fix 2024-09-24 17:43:09 +02:00
7680e1fca8 refresh orders 2024-09-24 17:15:35 +02:00
4cbff23680 multiple orders in array 2024-09-24 17:07:11 +02:00
a45b4e5f51 multiple orders in array 2024-09-24 16:43:38 +02:00
ee77fa4522 telegram group, community 2024-09-23 11:57:44 +02:00
d7087c738d install documentation/playbooks 2024-09-23 11:33:20 +02:00
ec677cc41c install documentation/playbooks 2024-09-23 11:26:18 +02:00
cab4d7e0df fix 2024-09-23 10:05:49 +02:00
62ad7ce2da fix 2024-09-19 23:31:42 +02:00
244667d11a yahoo disables free history api - using coinmarketcap api now 2024-09-18 21:23:40 +02:00
71ff0b28a8 update 2024-09-05 22:35:54 +02:00
f34c5ddf89 fixes 2024-09-05 18:02:25 +02:00
e991042eaa stoploss and takeprofit 2024-09-05 18:02:00 +02:00
d3714630b2 fixed and nicer output, added charts 2024-09-05 18:01:31 +02:00
170ad50652 fixed and nicer output, added charts 2024-09-05 18:01:25 +02:00
e15740900a examples 2024-09-05 14:55:59 +02:00
e3602cc7b8 fix 2024-09-04 18:04:06 +02:00
0dcdc33e7b update 2024-09-04 18:03:53 +02:00
a1c60d1696 update 2024-09-04 18:03:45 +02:00
ff46ae8e8a assoziative array 2024-09-04 18:03:28 +02:00
61c805ebfd assoziative array 2024-09-04 18:03:20 +02:00
3e412615b9 values 2024-09-02 15:22:31 +02:00
06fc9f7cc2 values 2024-09-02 14:52:42 +02:00
e5fd834a9d values 2024-09-02 14:51:46 +02:00
563c63b57b example-values 2024-09-02 14:50:15 +02:00
33f71bb4f6 reset ccxt 2024-09-01 14:42:50 +02:00
cc413f69a1 fix 2024-09-01 14:25:38 +02:00
b0dfda6c9b fix 2024-08-31 20:08:49 +02:00
173f7c1b97 fix 2024-08-31 17:47:23 +02:00
5e07b0450b price precision 2024-08-31 17:45:54 +02:00
fdc3013501 fix 2024-08-31 17:06:08 +02:00
10493f4bcd fix 2024-08-31 15:34:34 +02:00
6725fcb0a3 takeprofit and stoploss option 2024-08-31 14:57:50 +02:00
0f62e2ffbd fix 2024-08-30 17:33:12 +02:00
051798ed00 array and vars 2024-08-30 17:32:54 +02:00
fa6dd07417 cancel orders 2024-08-30 17:32:27 +02:00
91763326e1 fix ccxt.base.errors.BadRequest: binance fetchConvertTradeHistory() the max interval between startTime and endTime is 30 days. 2024-08-27 22:23:49 +02:00
d9a82b2844 fix levels array 2024-08-27 20:47:24 +02:00
492d9babfa fix IFS 2024-08-27 16:28:34 +02:00
ab06193f07 fix no .* files 2024-08-26 17:51:22 +02:00
ab1c3551f9 fix path 2024-08-26 13:51:34 +02:00
20e8ddc2c9 fix 2024-08-25 17:11:39 +02:00
7e5a95aafc values, run strategies, fixes 2024-08-25 13:58:33 +02:00
6cf5d8502f doc update vars 2024-08-25 11:49:02 +02:00
29b8c29bda ARTY 2024-08-24 14:09:39 +02:00
8871c66902 fix ccxt.base.errors.BadRequest: binance fetchConvertTradeHistory() the max interval between startTime and endTime is 30 days. 2024-08-24 13:48:11 +02:00
f0c565aaf7 copyright, license, fixes 2024-08-21 22:54:55 +02:00
88ea5bbb5b copyright, license, fixes 2024-08-21 22:47:35 +02:00
07ef55bcd2 fixes 2024-07-30 14:23:00 +02:00
5be7a95869 testnet 2024-07-30 14:22:54 +02:00
74 changed files with 11879 additions and 1051 deletions

7
.gitignore vendored
View File

@@ -9,10 +9,13 @@
/dabo/.*-secrets /dabo/.*-secrets
/home/.ssh /home/.ssh
/home/.viminfo /home/.viminfo
/home/.bash_history .*history
/home/.dabo-bot.sh.lock .wget-hsts
/analyze-* /analyze-*
*.del *.del
*.tmp
*local*
test*.sh
/env /env
/genpw.sh /genpw.sh
/watch-assets.csv* /watch-assets.csv*

674
COPYING Normal file
View File

@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

531
README.md
View File

@@ -1,25 +1,66 @@
# Warning / Disclaimer # Dabo (crypto bot)
The software provided here is called dabo (crypto bot).
## Warning / Disclaimer
The software provided here does not guarantee any profits or function as well as sufficient security. Use at your own risk!!! The software provided here does not guarantee any profits or function as well as sufficient security. Use at your own risk!!!
This is a private project, which is based on amateur knowledge. Trading cryptocurrencies involves an enormous amount of risks and is considered highly speculative. This is a private project, which is based on amateur knowledge. Trading cryptocurrencies involves an enormous amount of risks and is considered highly speculative.
It is strongly recommended to deal intensively with the subject and this bot before using it. Also, when using the possibility should be considered that due to an unfavorable market development, technical errors, bugs or other reasons, the entire invested capital can be lost. This software should therefore only be used if it is justifiable to lose the entire invested capital! It is strongly recommended to deal intensively with the subject and this bot before using it. Also, when using the possibility should be considered that due to an unfavorable market development, technical errors, bugs or other reasons, the entire invested capital can be lost. This software should therefore only be used if it is justifiable to lose the entire invested capital!
# Objective THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
It is still under development and is currently only partially functional.
## Copyright / License
Copyright (c) 2022-2024 Oliver Bohlen (aka olli/egabosh)
The software provided here is called dabo (crypto bot)
dabo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
dabo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with dabo (see COPYING file). If not, see <http://www.gnu.org/licenses/>.
## Data sources
Various data sources such as finance.yahoo.com and crypto exchanges available via ccxt are used. Please check whether this is legal in your region before use.
- https://query1.finance.yahoo.com (economic data,...)
- https://api.coinmarketcap.com (crypto data)
- https://api.bls.gov (CPI, unemployment rate)
- https://fred.stlouisfed.org (fed funds rate)
- https://30rates.com (forecast)
- https://fapi.binance.com (OpenInterest,...)
- https://api.alternative.me (Fear and Greed)
- https://production.dataviz.cnn.io (Fear and Greed CNN)
- https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js (TradingView Lightweitgt Charts)
- ...
## dependencies to other software
- CCXT (https://www.ccxt.com | https://github.com/ccxt/ccxt)
- TradingView Lightweitgt Charts (https://www.tradingview.com/lightweight-charts/ | https://github.com/tradingview/lightweight-charts)
- bash, python
- several default linux programs like bc, wget,...
- gaboshlib (https://github.com/egabosh/gaboshlib)
- ...
## Objective
The dabo-bot is intended to help make and execute timely buy and sell decisions automatically in the fast-paced crypto environment. The dabo-bot is intended to help make and execute timely buy and sell decisions automatically in the fast-paced crypto environment.
These decisions are made using one or more self-definable strategies. These decisions are made using one or more self-definable strategies.
Various market data are available as a basis for decision-making, such as price trends, RSI, MACD and EMA indicators of various time intervals, Fear and Greed Index, S&P500 data,... Various market data are available as a basis for decision-making, such as price trends, RSI, MACD and EMA indicators of various time intervals, Fear and Greed Index, S&P500 data,...
# Naming ## Naming
The name Dabo comes from the Star Trek universe. The name Dabo comes from the Star Trek universe.
Dabo was a roulette-style game of chance developed by the Ferengi. Dabo was a roulette-style game of chance developed by the Ferengi.
More information here: More information here:
https://memory-alpha.fandom.com/wiki/Dabo https://memory-alpha.fandom.com/wiki/Dabo
I thought this fits quite well to the cryptotrading world and that's why I chose this name ;-) I thought this fits quite well to the cryptotrading world and that's why I chose this name ;-)
# Structure ## Structure
The Bot is splitted in the following parts: The Bot is splitted in the following parts/containers:
- dabo-bot: Basic Bot woth buy and sell decisions based on self-definable strategies - dabo-bot: Basic Bot with buy and sell decisions based on self-definable strategies
- dabo-symbols_ticker: Ticker for current symbols and prices - dabo-symbols_ticker: Ticker for current symbols and prices
- dabo-ohlcv-candles: Continuously collect OHLCV data - dabo-ohlcv-candles: Continuously collect OHLCV data
- dabo-indicators: Continuously calculate indicators and other data - dabo-indicators: Continuously calculate indicators and other data
@@ -28,74 +69,53 @@ The Bot is splitted in the following parts:
- dabo-webpage: Continuously creates webpage overview (readonly) - dabo-webpage: Continuously creates webpage overview (readonly)
- dabo-web: Webserver for webpage overview - dabo-web: Webserver for webpage overview
For cummunicating with the exchange APIs CCXT is used: https://github.com/ccxt/ccxt
gaboishlib
Each part runs parallel to the others in its own docker-container. Each part runs parallel to the others in its own docker-container.
# Features ## Features
## General: ### General:
- theoretically compatible to supported CCXT exchanges. Tested with Phemex. Please let me know if there are problems with other exchanges. - theoretically compatible to supported CCXT exchanges. Tested with Phemex Contract trading. Please let me know your experiences with other exchanges.
- parallel processing in separate docker containers - parallel processing in separate non-root docker containers
- Notifications via Matrix Messenger to groups
## Dabo Bot ### Dabo Bot
- place limit and market orders and supports ... - place limit and market orders and supports ...
- ... leverage trading - ... leverage trading
- ... short trades - ... short trades
- ... margins cross and isolated - ... margins cross and isolated
## Dabo Symbol Ticker - ... stoploss and takeprofit
- multiple different strategies possible at the same time
### Dabo Symbol Ticker
- automatically finds all supported tokens and pairs and fetches continiously ... - automatically finds all supported tokens and pairs and fetches continiously ...
- ... symbols - ... symbols
- ... and prices - ... and prices
## Dabo OHLCV Candle data ### Dabo OHLCV Candle data
OHLCV = Open, High, Low, Close and Volume of a time unit OHLCV = Open, High, Low, Close and Volume of a time unit
- time units 1w, 1d, 4h, 1h, 15m and 5m - time units 1w, 1d, 4h, 1h, 15m and 5m
- 4h, 1h, 15m and 5m from the respective stock exchange - 4h, 1h, 15m and 5m from the respective stock exchange
- 1d and 1w data from yahoo finace to have longer terms - 1d and 1w data from coinmarketcap to have longer terms
## Dabo Indicators - economic data from yahoo finance
### Dabo Indicators
- data per time unit - data per time unit
- time units 1w, 1d, 4h, 1h, 15m and 5m - time units 1w, 1d, 4h, 1h, 15m and 5m
- self-calculated EMA12, 26 ,50, 100, 200, 400 and 800 - self-calculated EMA12, 26 ,50, 100, 200, 400 and 800
- self-calculated RSI5, 14, 21 - self-calculated RSI5, 14, 21
- self-calculated MACD - self-calculated MACD
## Dabo Market Data - self-calculated significant levels (support/resist)
### Dabo Market Data
- Yahoo Finance - Yahoo Finance
## Dabo Orders - CoinMarketCap
## Dabo Transaction History - BLS.gov
- alternative.me
- CNN
- Fed
### Dabo Orders
### Dabo Transaction History
- Support of additional Exchnages/Brokers JustTrade (CSV-Import) and Bitpanda (API+CSV-Import) - Support of additional Exchnages/Brokers JustTrade (CSV-Import) and Bitpanda (API+CSV-Import)
## Dabo Webpage - German tax calculation
### Dabo Webpage
- ReadOnly Overview - ReadOnly Overview
- Consideration of trading fees ## Why bash?
- Automatic selection of cryptocurrencies to invest in
- Filtering of cryptocurrencies by market capitalization (data via coingecko API) e.g. only trade the 50 largest by market capitalization if available on the exchange
- Notifications via Signal Messenger to groups
- Individually selectable percentage of available capital per trade
- automatic definition of time intervals (e.g. every minute / every five minutes) based on the change of the rates
- Monitoring of overall market performance via own market performance index based for example on the MSCI World, leading currencies like BTC and ETH and their forecasts.
- Emergency stop if balance falls below defined value
- Recording of available price values incl. RSI and MACD indicators of available cryptocurrencies
- Analysis tool for collected historical values to try out buy or sell conditions based on them
- ReadOnly web interface for overview
- Runnable in a non-root docker containe
- multiple different buy and sell strategies possible at the same time
- Hedge mode (long and short positions the same time) not supported
## Buy conditions
- definable RSI Indicator signals min/max (RSI5, 14 and 21)
- definable MACD signals min/max
- definable minimum growth in a definable time period
## Sell conditions
- sell at defined loss limit
- hold if the result would be negative
- sell after certain time even if loss exists
- definable RSI Indicator signals min/max
- definable MACD signals min/max
# Why bash?
Yes, bash is not a language in which you write something like this in a normal way. Yes, bash is not a language in which you write something like this in a normal way.
To be honest, I'm more of a Linux admin than a programmer, so I do a lot of my work using bash. To be honest, I'm more of a Linux admin than a programmer, so I do a lot of my work using bash.
@@ -106,28 +126,88 @@ Originally this project was supposed to be a simple script to monitor prices of
Finally, it's a hobby project and I have to see how and when I can find time for it, because there also has to be time for family, friends, work and other hobbies. Finally, it's a hobby project and I have to see how and when I can find time for it, because there also has to be time for family, friends, work and other hobbies.
If there is someone who would like to rewrite this bot in e.g. Python, I would be happy to support them as best I can with this task. Just let me know. If there is someone who would like to rewrite this bot in e.g. Python, I would be happy to support them as best I can with this task. Just let me know.
# How to use/install ## How to install (basic Linux knowledge required!)
Linux knowledge required!
Needed a running Docker install. Traefik suggested, see Should run on every system with docker.
https://gitea.ds9.dedyn.io/olli/debian.ansible.docker ### 1: Operating System
Tested and running with Debian 12 (Bookworm).
https://www.debian.org/download
https://www.raspberrypi.com/software/operating-systems/
https://gitea.ds9.dedyn.io/olli/debian.ansible.traefik.server ### 2: Way 1: Istall via anssible playbooks
On a fresh Debian 12 system you can run my Ansible Playbooks to use the same environment the bot is developed and running.
Please have a look what exactly the playbooks are doing if you are unsure.
If the web interface (or matrix/turn) should be accessible via the internet, the server must be accessible on port 80/tcp (acme/letsencrypt) and 443/tcp.
For private/home internet access, this may require port forwarding on your router and registration with a dyndns (DDNS) service. The DDNS service should allow subdomains.
## Download When using my playbooks and the services should be available to the internet, the hostname must correspond to the ddns name.
Here is an example for the dynu-DDNS service:
- DDNS name: myhost.mywire.com
- dabo-bot-name: dabo.myhost.mywire.com
- matrix-name: matrix.myhost.mywire.com
You also can use IPv6 if your ISP and router supports this and if you have multiple servers/services on Ports (80/443) but only one IPv4 address to the internet.
#### 2.1 Download basic install script
``` ```
git clone https://gitea.ds9.dedyn.io/olli/dabo.git wget https://raw.githubusercontent.com/egabosh/linux-setups/refs/heads/main/debian/install.sh -O install.sh
```
#### 2.2 define Playbooks
- debian/basics/basics.yml (https://github.com/egabosh/linux-setups/tree/main/debian/basics) - Basic Debian configuration
- Optional: debian/firewall/firewall.yml (https://github.com/egabosh/linux-setups/tree/main/debian/firewall) - Firewall for the server based on ufw
- Optional: debian/runchecks/runchecks.yml (https://github.com/egabosh/linux-setups/tree/main/debian/runchecks) - System checks and notification
- Optional: debian/backup/backup.yml (https://github.com/egabosh/linux-setups/tree/main/debian/backup) - Backup framework
- Optional: debian/autoupdate/autoupdate.yml (https://github.com/egabosh/linux-setups/tree/main/debian/autoupdate) - Automatic System Updates
- debian/docker/docker.yml (https://github.com/egabosh/linux-setups/tree/main/debian/docker) - Docker Installation
- debian/traefik.server/traefik.yml (https://github.com/egabosh/linux-setups/tree/main/debian/traefik.server) - Traefik Reverse Proxy for Web UI and Letsencrypt Certs
- Optional: debian/turn.server/turn.yml (https://github.com/egabosh/linux-setups/tree/main/debian/turn.server) - Turn Server fpr Audio/Video conferences in Matrix
- Optional: debian/matrix.server/matrix.yml (https://github.com/egabosh/linux-setups/tree/main/debian/matrix.server) - Notifications with own Martix Server
- https://github.com/egabosh/dabo/raw/refs/heads/main/dabo-ansible.yml: The Bot itself
for example:
```
PLAYBOOKS="debian/basics/basics.yml
debian/firewall/firewall.yml
debian/runchecks/runchecks.yml
debian/backup/backup.yml
debian/autoupdate/autoupdate.yml
debian/docker/docker.yml
debian/traefik.server/traefik.yml
https://github.com/egabosh/dabo/raw/refs/heads/main/dabo-ansible.yml"
export PLAYBOOKS
```
#### 2.3 Install ansible and run Playbooks
If you run this as user and not as root, the script will install sudo and enable the user to execute commands as root via sudo. To do this, the root password is requested (several times).
```
bash install.sh
```
### 3. Manual installation without ansible playbooks
Not necessary if you use the dabo Playbook
#### Install docker
See: https://docs.docker.com/engine/install/debian/
You can also use other containerizations like podman or kubernetes. But here I stick with docker
#### Download
Not necessary if you use the dabo Playbook
```
git clone https://github.com/egabosh/dabo.git
cd dabo cd dabo
``` ```
## Build container #### Build container
Not necessary if you use the dabo Playbook
``` ```
docker -l warn compose --ansi never build --progress=plain --pull --no-cache --force-rm docker -l warn compose --ansi never build --progress=plain --pull --no-cache --force-rm
``` ```
## Configure ### 3. Make Webinterface available
Not necessary if you use the dabo Playbook with traefik and letsencrypt
Edit docker-compose.yml or create docker-compose.override.yml to fit yout needs e.g. domain and network settings or basic auth, e.g. for traefik and letsencrypt: Edit docker-compose.yml or create docker-compose.override.yml to fit yout needs e.g. domain and network settings or basic auth, e.g. for traefik and letsencrypt:
``` ```
echo ' echo '
@@ -169,87 +249,63 @@ networks:
' >docker-compose.override.yml ' >docker-compose.override.yml
``` ```
If you use the ansible Playbook but don't want to use traefik/letsencrypt or availability over the internet you can add the following to `docker-compose.override.yml` below "# END ANSIBLE MANAGED BLOCK".
ATTENTION: ACCESS IS UNENCRYPTED!!!
```
ports:
- 8080:80
```
You have to restart the container(s) to apply changes. See operational commands.
Optional: If you use signal-cli (https://gitea.ds9.dedyn.io/olli/debian.ansible.signal-cli.client) and want do receive Signal-Messages from the bot you can create an SSH-Key to allow sending Signal-Messages e.g.: ### 4. Optional: Matrix connection
Optional: If you use matrix/matrix-commander (https://github.com/egabosh/linux-setups/tree/main/debian/matrix.server) and want do receive Matrix-Messages from the bot you can create an SSH-Key to allow sending Matrix-Messages e.g.:
Automatically done by playbooks.
``` ```
mkdir -p home/.ssh mkdir -p home/.ssh
ssh-keygen -f home/.ssh/id_ed25519 -N "" -t ed25519 ssh-keygen -f home/.ssh/id_ed25519 -N "" -t ed25519
chmod 700 home/.ssh chmod 700 home/.ssh
cat home/.ssh/id_ed25519.pub cat home/.ssh/id_ed25519.pub
``` ```
and add Key on your signal-cli-Server to the authorized_keys of the signal-User and add Key on your matrix-Server to the authorized_keys of the matrix-User
### 5. Add Exchange
Create Secrets file for your API Key(s) Create Secrets file for your API Key(s)
```
# for OneTrading.com (ex BitpandaPro)
echo 'local API_TOKEN=YOUR_VERY_LOOOOOOONNNNGGGG_API_TOKEN_FROM_BITPANDA' >dabo/.bitpanda-secrets
chmod 400 dabo/.bitpanda-secrets
# or for Binance - file: dabo/.CCXT-ID-secrets
echo 'local API_SECRET="YOUR_LONG_API_SECRET_FROM_BINANCE" CCXI-ID see: https://github.com/ccxt/ccxt
local API_KEY="YOUR_LONG_API_KEY_FROM_BINANCE" '>dabo/.binance-secrets
Examples:
```
# for Phemex
echo 'local API_SECRET="YOUR_API_SECRET_FROM_PHEMEX"
local API_KEY="YOUR_API_KEY_FROM_PHEMEX"' >dabo/.phemex-secrets
chmod 400 dabo/.phemex-secrets
# for Binance
echo 'local API_SECRET="YOUR_API_SECRET_FROM_BINANCE"
local API_KEY="YOUR_API_KEY_FROM_BINANCE"' >dabo/.binance-secrets
chmod 400 dabo/.binance-secrets chmod 400 dabo/.binance-secrets
``` ```
Create Config Create Config
Especially set URL, STOCK_EXCHANGE, FEE, CURRENCY,... to fit your needs. Especially set URL, STOCK_EXCHANGE, FEE, CURRENCY,... to fit your needs.
If you want to use the a testnet of an exchnage if available use TESTNET=true which is the default
``` ```
vim dabo-bot.conf vim dabo-bot.conf
``` ```
Defaults in dabo/dabo-bot.conf Defaults in dabo/dabo-bot.conf
## How to use
## Prepare/Create a stretegy ### Operational commands
IMPORTANT!!!
THE DEFAULT STRATEGY MAY NOT FIT YOUR NEEDS OR WORK PROPERLY. SO YOU CAN LOOSE ALL YOUR MONEY!!! USE ON YOUR OWN RISK!!!
TEST YOUR OWN STRATEGY COMPREHENSIVELY AND OVER A LOGNER PERIOD OF TIME WITH analyze.sh!!! USE ON YOUR OWN RISK!!!
Strategie files can be put in the "strategies"-directory the defaults
There is an example for a buy and a sell strategy file (deactivated by "return 0" in the forst line):
```
ls strategies/buy.example.conf
ls strategies/sell.example.conf
```
Aditional strategies can be created with Name
```
strategies/buy.<name>.conf
strategies/sell.<name>.conf
```
e.g named "mannover-sulu-1" for buy strategy and "command-kirk-3" for sell strategy
```
strategies/buy.mannover-sulu-1.conf
strategies/sell.command-kirk-3.conf
```
## Create individual watch-assets.csv
```
cp dabo/watch-assets.csv watch-assets.csv
```
Optional:
You can edit this file if you want do generate warnings or track your asstes/trades.
```
nano watch-assets.csv
```
## Set Rights
Set Rights (UID 10000 for non-root-User in running container):
```
chown -R 10000:10000 dabo data home strategies dabo-bot.conf watch-assets.csv
```
## Operational commands
Run/Restart: Run/Restart:
``` ```
docker compose down # if an old instance is running docker compose down # if an old instance is running
docker compose up -d docker compose up -d
``` ```
Check List and state of containers:
``` ```
docker compose ps docker compose ps
``` ```
@@ -258,132 +314,167 @@ Logs/Output:
``` ```
docker compose logs -f docker compose logs -f
``` ```
Logs/Oputput of a specific container for example dabo-bot:
Update:
``` ```
# Optinal: Remove local data docker compose logs -f dabo-bot
```
### Update
Not necessary if you use the playbooks
```
# Optional: Remove local data
git reset --hard HEAD^ # Remove local commits git reset --hard HEAD^ # Remove local commits
git clean -fd # Remove local uncommited files git clean -fd # Remove local uncommited files
# Update and restart # Update and restart
git pull https://gitea.ds9.dedyn.io/olli/dabo.git main -f git pull https://github.com/egabosh/dabo.git main -f
docker compose down docker compose down
docker compose up -d docker compose up -d
``` ```
### Strategies
dabo-bot.sh is the bot that trades and collects the quotes and analyze.sh is the tool with which you can try out strategies with the historical data. IMPORTANT!!!
The configuration files are called dabo-bot.conf and analyze.conf. analyze.sh also uses bot.conf but its variables are overwritten by analyze.conf if duplicated.
A Binance or OneTrading.com (ex BitpandaPro) account must exist and the API must be enabled. THE EXAMPLE STRATEGIES MAY NOT FIT YOUR NEEDS OR WORK PROPERLY. SO YOU CAN LOOSE ALL YOUR MONEY!!! USE ON YOUR OWN RISK!!!
The access data is stored in the file .binance-secrets in the project directory in the variables API_SECRET and API_KEY.
The access rights to this file should be set to the minimum necessary for security reasons.
# Strategies TEST YOUR OWN STRATEGY COMPREHENSIVELY AND OVER A LOGNER PERIOD OF TIME BEST RISK-FREE IN A TESTNET!!! USE ON YOUR OWN RISK!!!
You can put your own code into the strateghies it will be sourced by the bot. Strategies are needed for the bot to trade.
You can use available variables to set and read things. Strategies are located in die stretegies subdir.
## Variables to set You can put your own code into the strategies it will be sourced by the bot.
If you want, you can also use other programming languages or binary code as a strategy and simply start it using your own strategy.
You can simply use the following varaibles to define things: #### Example strategies
There are examples for strategy files (deactivated by "return 0" in the beginning):
```
cat strategies/example.strategy.sh
cat strategies/example_manage_positions.strategy.sh
```
"example.strategy.sh" creates a score by defined tests and opens a long or short order with stoploss and takeprofit if the score has a defined value.
"example_manage_positions.strategy.sh" watches open positions and switches the stoploss into profit if position is in profit to secure it.
You can use them and change them to fit your needs. To avoid resets on updates copy them to your own strategies for example:
``` ```
local GOOD_MARKET_PERFORMANCE_INDEX cp -p strategies/example.strategy.sh strategies/my-own-trading.strategy.sh
cp -p strategies/example_manage_positions.strategy.sh strategies/my-own-position.strategy.sh
local BUY_RSI5_SIGNAL_UNTIL
local BUY_RSI14_SIGNAL_UNTIL
local BUY_RSI21_SIGNAL_UNTIL
local BUY_RSI60_SIGNAL_UNTIL
local BUY_RSI120_SIGNAL_UNTIL
local BUY_RSI240_SIGNAL_UNTIL
local BUY_RSI420_SIGNAL_UNTIL
local BUY_RSI720_SIGNAL_UNTIL
local BUY_RSI5_SIGNAL_FROM
local BUY_RSI14_SIGNAL_FROM
local BUY_RSI21_SIGNAL_FROM
local BUY_RSI60_SIGNAL_FROM
local BUY_RSI120_SIGNAL_FROM
local BUY_RSI240_SIGNAL_FROM
local BUY_RSI420_SIGNAL_FROM
local BUY_RSI720_SIGNAL_FROM
local BUY_MACD_RELATION_FROM
local BUY_MACD_RELATION_TO
local BUY_MIN_PRICE_CHANGE_LAST_1_DAY
local BUY_MIN_PRICE_CHANGE_LAST_7_DAY
local BUY_MIN_PRICE_CHANGE_LAST_14_DAY
local BUY_MIN_PRICE_CHANGE_LAST_30_DAY
local BUY_MINGROWTH_PERIOD
local BUY_MINGROWTH
``` ```
## Variables with current values from the CSV files #### Own strategies
Aditional strategies can be created with naming convention *.strategy.sh
``` ```
# date from current timeframe strategies/my-new.strategy.sh
${f_date} strategies/yet-another-new.strategy.sh
# current price
${f_price}
# price change percentage from timeframe before
${f_price_change}
# EMA
${f_ema12}
${f_ema26}
${f_ema50}
${f_ema100}
${f_ema200}
${f_ema800}
# MACD with EMA 12/16/9
${f_macd_histogram}
${f_macd_signal_relation}
${f_macd_histogram_relation}
${f_macd_histogram_signal}
# RSI from last ?? timeframes
${f_rsi5}
${f_rsi14}
${f_rsi21}
${f_rsi720}
${f_rsi60}
${f_rsi120}
${f_rsi240}
${f_rsi420}
# Price change from coingecko.com
${f_price_change_1_day}
${f_price_change_7_day}
${f_price_change_14_day}
${f_price_change_30_day}
${f_price_change_1_year}
# Market Capitalization change from coingecko.com
${f_marketcap_change_1_day}
# Ranges, Pivpot Point and Fibonacci based support and resist levels support/resist2 aka as "Golden Pocket"
${f_range_periods}
${f_lowest_in_range}
${f_highest_in_range}
${f_pivot_point}
${f_support1}
${f_resist1}
${f_golden_pocket_support}
${f_golden_pocket_resist}
${f_golden_pocket65_support}
${f_golden_pocket65_resist}
${f_support3}
${f_resist3}
``` ```
# Future ideas/featrues Strategy files should have specific rights - must be readable by the bot:
- Crypto preferences (While/Blacklist for certain currencies) ```
- Overview trades/profits/losses for tax declaration chown -R 10000:10000 strategies
- Support for decentralized exchanges like uniswap to gain more "security" chmod -R 640 strategies
```
#### Variables during runtime of the strategies
You can use available variables/arrays during runtime to read (and set) values.
This arrays are available to runtime in the strategies
##### Large associative arrays v and vr (reverse)
${v[SYMBOL_TIMEFRAME_ITEM_NUMBER]}
- SYMBOL: Crypto-Symbol for examle ETHUSDT or ECONOMY_DXY ECONOMY_DOWJONES ECONOMY_SP500 ECONOMY_NASDAQ ECONOMY_MSCIEAFE ECONOMY_10YRTREASURY ECONOMY_OIL ECONOMY_GOLD ECONOMY_MSCIWORLD ECONOMY_OILGAS ECONOMY_KRE ECONOMY_EUR-USD
- TIMEFRAME: 5m,15m,1h,4h,1d,1w
- ITEM: date,open,high,low,close,volume,change,ath,ema12,ema26,ema50,ema100,ema200,ema400,ema800,rsi5,rsi14,rsi21,macd,macd_ema9_signal,macd_histogram,macd_histogram_signal,macd_histogram_max,macd_histogram_strength
- NUMBER: 0=latest; 1=second latest
Examples:
```
${v[ECONOMY_NASDAQ_1h_close_0]}
${v[ECONOMY_SP500_rsi14_0]}
${v[ETHUSDT_1w_ema200_0]}
${v[ETHUSDT_1w_macd_histogram_signal_1]}
${v[SOLUSDT_levels_1d]}
${v[$[SOLUSDT_levels_1d_next_up]}
${v[$[ETHUSDT_levels_1w_next_down]}
```
You can find a complete list of available values in the file `data/botdata/values` which is created in the runtime of the bot.
An long example list you can find in example-values. https://github.com/egabosh/dabo/blob/main/example-values
##### Current price from exchange
${f_tickers_array[SYMBOL]}
```
${f_tickers_array[SOLUSDT]}
${f_tickers_array[ETH${CURRENCY}]}
```
##### Open Orders
```
${o[ETHUSDT_present]}=sl_close_long tp_close_long
${o[ETHUSDT_sl_close_long_amount]}=0
${o[ETHUSDT_sl_close_long_entry_price]}=null
${o[ETHUSDT_sl_close_long_id]}=36b2f404-0b20-4806-bdcc-0dad0daf57e9
${o[ETHUSDT_sl_close_long_side]}=sell
${o[ETHUSDT_sl_close_long_stoplossprice]}=0
${o[ETHUSDT_sl_close_long_stopprice]}=3305.98
${o[ETHUSDT_sl_close_long_takeprofitprice]}=0
${o[ETHUSDT_sl_close_long_type]}=Stop
${o[ETHUSDT_tp_close_long_amount]}=0
${o[ETHUSDT_tp_close_long_entry_price]}=null
${o[ETHUSDT_tp_close_long_id]}=850dd169-7387-4be3-ac68-bfce73cfa47d
${o[ETHUSDT_tp_close_long_side]}=sell
${o[ETHUSDT_tp_close_long_stoplossprice]}=0
${o[ETHUSDT_tp_close_long_stopprice]}=3710.04
${o[ETHUSDT_tp_close_long_takeprofitprice]}=0
${o[ETHUSDT_tp_close_long_type]}=MarketIfTouched
```
You can find a complete list of available values in the file `data/botdata/values-orders` which is created in the runtime of the bot.
##### Open Positions
```
${p[ETHUSDT_currency_amount]}=9509.25
${p[ETHUSDT_current_price]}=3573.79
${p[ETHUSDT_entry_price]}=3673.31
${p[ETHUSDT_leverage]}=5
${p[ETHUSDT_liquidation_price]}=2953.43
${p[ETHUSDT_pnl]}=-1288.50
${p[ETHUSDT_pnl_percentage]}=-13.55
${p[ETHUSDT_side]}=long
${p[ETHUSDT_stoploss_price]}=3305.98
${p[ETHUSDT_takeprofit_price]}=3710.04
```
You can find a complete list of available values in the file `data/botdata/values-positions` which is created in the runtime of the bot.
## Support/Community
New Telegram group for the dabo community.
https://t.me/dabobotcrypto
## Future ideas/featrues and todos
- PSR Indicator https://de.tradingview.com/script/w4U2xUN7-Pivot-Support-Resistance/
- public order data if there is such a thing. At what price do people want to enter (limit order)? Where do they want to exit (TakePofit/StopLoss)? Maybe free Binance data helps (https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Order-Book)? https://www.coinglass.com/de/mergev2/BTC-USDT
- AI implementation. What data can be prepared for training?
- example Grid trading strategy (user specific)
- Fibonacci Levels (which timeframe(s)?)
- Forecasts
- Chart improvements
- Volumeindicator and for example RSI on volume values
- Support for decentralized exchanges like uniswap
- Archive/compress old or large CSV-History-files - Archive/compress old or large CSV-History-files
- Hedge mode (long and short positions the same time)
- Emergency stop if balance falls below defined value
- Analysis tool for collected historical values to try out buy or sell conditions based on them
- Consideration of trading and funding fees
- Liquidation Heatmap (https://www.coinglass.com/pro/futures/LiquidationHeatMap)

Binary file not shown.

View File

@@ -13,14 +13,14 @@
- name: Git checkout - name: Git checkout
ansible.builtin.git: ansible.builtin.git:
repo: 'https://gitea.ds9.dedyn.io/olli/dabo.git' repo: 'https://github.com/egabosh/dabo.git'
dest: /home/docker/dabo.{{inventory_hostname}} dest: /home/docker/dabo.{{inventory_hostname}}
force: true force: true
notify: Restart dabo notify: Restart dabo
- name: /home/docker/dabo.{{inventory_hostname}}/genpw.sh (generate Random PW) - name: /home/docker/dabo.{{inventory_hostname}}/initiate.sh
blockinfile: blockinfile:
path: /home/docker/dabo.{{inventory_hostname}}/genpw.sh path: /home/docker/dabo.{{inventory_hostname}}/initiate.sh
create: yes create: yes
mode: 0550 mode: 0550
owner: root owner: root
@@ -29,41 +29,22 @@
block: | block: |
cd /home/docker/dabo.{{inventory_hostname}} cd /home/docker/dabo.{{inventory_hostname}}
if [ -f env ]
then
. ./env
echo "${WEBPASSWDCRYPT}"
else
webpassword=$(pwgen -s 32 1)
webuser=bot
webpasswordcrypted=$(htpasswd -nb ${webuser} ${webpassword})
echo "WEBUSER=${webuser}
WEBPASSWD=${webpassword}
WEBPASSWDCRYPT=${webpasswordcrypted}
" >env
chmod 440 env
chown root:docker env
echo "${webpasswordcrypted}"
fi
if ! [ -d home/.ssh ] if ! [ -d home/.ssh ]
then then
mkdir -p home/.ssh mkdir -p home/.ssh
ssh-keygen -f home/.ssh/id_ed25519 -N "" -t ed25519 >/dev/null ssh-keygen -f home/.ssh/id_ed25519 -N "" -t ed25519 >/dev/null
chmod 700 home/.ssh chmod 700 home/.ssh
fi fi
mkdir -p data/botdata strategies
[ -f watch-assets.csv ] || cp dabo/watch-assets.csv watch-assets.csv chown -R 10000:10000 dabo data home strategies dabo-bot.conf
chown -R 10000:10000 dabo data home strategies dabo-bot.conf watch-assets.csv
backup: yes backup: yes
validate: /bin/bash -n %s validate: /bin/bash -n %s
notify: run initiate.sh
- name: /home/docker/dabo.{{inventory_hostname}}/genpw.sh shebang - name: /home/docker/dabo.{{inventory_hostname}}/initiate.sh shebang
lineinfile: lineinfile:
path: /home/docker/dabo.{{inventory_hostname}}/genpw.sh path: /home/docker/dabo.{{inventory_hostname}}/initiate.sh
insertbefore: BOF insertbefore: BOF
line: "#!/bin/bash -e" line: "#!/bin/bash -e"
@@ -84,10 +65,10 @@
- Restart dabo - Restart dabo
- name: Get crypted PW #- name: Get crypted PW
shell: bash /home/docker/dabo.{{inventory_hostname}}/genpw.sh # shell: bash /home/docker/dabo.{{inventory_hostname}}/initiate.sh
register: cryptpw # register: cryptpw
changed_when: false # changed_when: false
- name: /home/docker/dabo.{{inventory_hostname}}/docker-compose.override.yml Container Configuration - name: /home/docker/dabo.{{inventory_hostname}}/docker-compose.override.yml Container Configuration
blockinfile: blockinfile:
@@ -98,7 +79,13 @@
group: docker group: docker
marker: "# {mark} ANSIBLE MANAGED BLOCK" marker: "# {mark} ANSIBLE MANAGED BLOCK"
block: | block: |
version: '3.6' networks:
dabo-network:
driver: bridge
driver_opts:
com.docker.network.bridge.name: br-dabo
traefik:
external: true
services: services:
@@ -120,21 +107,11 @@
# cert via letsencrypt # cert via letsencrypt
- traefik.http.routers.dabo.tls.certresolver=letsencrypt - traefik.http.routers.dabo.tls.certresolver=letsencrypt
# activate secHeaders@file # activate secHeaders@file
- traefik.http.routers.dabo.middlewares=secHeaders@file,dabo-basicauth - traefik.http.routers.dabo.middlewares=secHeaders@file,default-basic-auth@file
- traefik.http.middlewares.dabo-basicauth.basicauth.users={{ cryptpw.stdout }}
# Traefik network # Traefik network
- traefik.docker.network=traefik - traefik.docker.network=traefik
networks: networks:
- traefik - traefik
networks:
dabo-network:
driver: bridge
driver_opts:
com.docker.network.bridge.name: br-dabo
traefik:
external: true
backup: yes backup: yes
notify: Restart dabo notify: Restart dabo
@@ -144,11 +121,26 @@
chdir: /home/docker/dabo.{{inventory_hostname}} chdir: /home/docker/dabo.{{inventory_hostname}}
creates: /home/docker/dabo.{{inventory_hostname}}/data/botdata/MARKET_PERFORMANCE creates: /home/docker/dabo.{{inventory_hostname}}/data/botdata/MARKET_PERFORMANCE
- name: autoupdate dabo-bot
blockinfile:
path: /usr/local/sbin/autoupdate.d/dabo.update
create: yes
mode: 0550
owner: root
group: root
marker: "# {mark} ANSIBLE MANAGED BLOCK"
block: |
g_echo_ok "Dabo update"
rm -f /tmp/dabo-ansible.yml
wget https://raw.githubusercontent.com/egabosh/dabo/refs/heads/main/dabo-ansible.yml -O /tmp/dabo-ansible.yml
ansible-playbook --connection=local --inventory $(hostname), --limit $(hostname) /tmp/dabo-ansible.yml
backup: yes
validate: /bin/bash -n %s
handlers: handlers:
- name: run genpw.sh - name: run initiate.sh
ansible.builtin.shell: ./genpw.sh ansible.builtin.shell: ./initiate.sh
args: args:
chdir: /home/docker/dabo.{{inventory_hostname}} chdir: /home/docker/dabo.{{inventory_hostname}}
notify: Restart dabo notify: Restart dabo
@@ -157,3 +149,4 @@
ansible.builtin.shell: docker compose up -d --force-recreate ansible.builtin.shell: docker compose up -d --force-recreate
args: args:
chdir: /home/docker/dabo.{{inventory_hostname}} chdir: /home/docker/dabo.{{inventory_hostname}}

View File

@@ -1,5 +1,24 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
# cleanup # cleanup
rm -r /tmp/parallel-* /tmp/overall-result-* /tmp/g_analyze.sh-* rm -r /tmp/parallel-* /tmp/overall-result-* /tmp/g_analyze.sh-*

View File

@@ -1,5 +1,24 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /dabo/dabo-prep.sh . /dabo/dabo-prep.sh
rm -f asset-histories/*.history.*.csv.indicators-calculating rm -f asset-histories/*.history.*.csv.indicators-calculating
@@ -11,8 +30,9 @@ do
# Reload Config # Reload Config
. ../../dabo-bot.conf . ../../dabo-bot.conf
. ../../dabo-bot.override.conf . ../../dabo-bot.override.conf
# get orders # get all indicators first only latest until EMA800
get_indicators_all 810
get_indicators_all get_indicators_all
rm asset-histories/*.history.*.csv.indicators-calculating rm -f asset-histories/*.history.*.csv.indicators-calculating
done done

View File

@@ -1,9 +1,28 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /dabo/dabo-prep.sh . /dabo/dabo-prep.sh
rm -f asset-histories/*.history.*.csv.levels-calculating rm -f asset-histories/*.history.*.csv.levels-calculating
sleep 12 sleep 120
while true while true
do do
@@ -14,6 +33,7 @@ do
# get levels # get levels
get_levels_all get_levels_all
rm -f asset-histories/*.history.*.csv.levels-calculating rm -f asset-histories/*.history.*.csv.levels-calculating
sleep 900 # recalc every 6 hours
sleep 21600
done done

View File

@@ -1,5 +1,24 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /dabo/dabo-prep.sh . /dabo/dabo-prep.sh
while true while true

View File

@@ -2,39 +2,31 @@
# Webpage URL # Webpage URL
URL="mydabobot.mydomain" URL="mydabobot.mydomain"
URL="dabo.$(hostname)"
# The exchange we use for using the correct API (BINANCE or ONETRADING) # The exchange we use for using the correct API (CCXI-ID see: https://github.com/ccxt/ccxt)
# for Phemex it is "phemex" for example
STOCK_EXCHANGE="NONE" STOCK_EXCHANGE="NONE"
# fee per trade in percentage on exchange (taker and maker added) # Interval in seconds - Should not be lower then 300 seconds (5m is the lowest timeframe
FEE="0.5" INTERVAL="300"
# Interval in seconds - Should not be lower then 300
INTERVAL="900"
## Currency used for trading ## Currency used for trading
CURRENCY="USDT" CURRENCY="USDT"
TRANSFER_CURRENCY="USD" TRANSFER_CURRENCY="EUR"
# Only use currencies under the first X currencies sorted by market capitalization
LARGEST_MARKETCAP="250"
# symbols that should be traded # symbols that should be traded
SYMBOLS="ETH SOL" SYMBOLS="ETH SOL"
## Signal Group for Notifications ## Signal Group for Notifications
SIGNAL_GROUP="Krypto-Bot" NOTIFICATION_GROUP="Dabo-Bot"
## Percent from balance per invest.
# Overwritten by MIN_NOTIONAL+X% from stock if lower
INVEST="5"
# Stop all trading and sell everything if the complete balance shrinks under this value in ${CURRENCY}
EMERGENCY_STOP="1000"
# Leverage # Leverage
LEVERAGE="" LEVERAGE="2"
# margin mode (isolated or cross) # margin mode (isolated or cross)
MARGIN_MODE="isolated" MARGIN_MODE="isolated"
# testnet of exchange if available (true or false). false for trades with real money
TESTNET=true

View File

@@ -1 +1 @@
keep #keep

View File

@@ -1,5 +1,22 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /dabo/dabo-prep.sh . /dabo/dabo-prep.sh
### MAIN ### ### MAIN ###
@@ -12,12 +29,12 @@ export FULL_LOOP=1
echo $0 | grep -q "dabo-bot\.sh" && BOT=1 echo $0 | grep -q "dabo-bot\.sh" && BOT=1
# cleanup trashlines in asset-histories (possibly generated by kill further of this progress) # cleanup trashlines in asset-histories (possibly generated by kill further of this progress)
find asset-histories -name "*.csv" -type f | while read csv_file #find asset-histories -name "*.csv" -type f | while read csv_file
do #do
csv_timestamp=$(ls --time-style='+%Y%m%d%H%M' -l "${csv_file}" | cut -d" " -f6) # csv_timestamp=$(ls --time-style='+%Y%m%d%H%M' -l "${csv_file}" | cut -d" " -f6)
sed -i "/[0-9]$(date +%Y)-/d" "${csv_file}" # sed -i "/[0-9]$(date +%Y)-/d" "${csv_file}"
touch -t ${csv_timestamp} "${csv_file}" # touch -t ${csv_timestamp} "${csv_file}"
done #done
# run endless loop # run endless loop
@@ -28,7 +45,7 @@ do
then then
rm -f firstloop rm -f firstloop
else else
LOOP_INTERVAL=30 # 60s max free coingecko API interval + 30s puffer LOOP_INTERVAL=30
time_to_interval=$((${LOOP_INTERVAL} - $(date +%s) % ${LOOP_INTERVAL})) time_to_interval=$((${LOOP_INTERVAL} - $(date +%s) % ${LOOP_INTERVAL}))
time_to_full_interval=$((${INTERVAL} - $(date +%s) % ${INTERVAL})) time_to_full_interval=$((${INTERVAL} - $(date +%s) % ${INTERVAL}))
# Check for next general interval # Check for next general interval
@@ -54,38 +71,14 @@ do
# Timestamp # Timestamp
export f_timestamp=$(g_date_print) export f_timestamp=$(g_date_print)
# get minute interval for find -mmin
INTERVAL_MIN=$(echo "${INTERVAL}/60-1" | bc -l | sed -r 's/^(-?)\./\10./' | cut -d\. -f1)
[ -z "${INTERVAL_MIN}" ] && INTERVAL_MIN=1
### get general market data
# Get coingecko data
get_coingecko_data
# Get current MarketData
get_marketdata
# Check the situation on the market
if ! market_performance
then
f_market_performance=$(cat MARKET_PERFORMANCE_LATEST)
fi
## watch some manual defined assets
#watch_assets
if [ "${STOCK_EXCHANGE}" = "NONE" ] if [ "${STOCK_EXCHANGE}" = "NONE" ]
then then
## stop here if STOCK_EXCHANGE not present ## stop here if STOCK_EXCHANGE not present
continue continue
fi fi
# Get current symbols # clean old data
[ ${FULL_LOOP} = 1 ] && get_symbols_ticker [ ${FULL_LOOP} = 1 ] && find asset-histories -maxdepth 1 ! -type d ! -name "*.csv" ! -name "*.levels" ! -name "*.zones" ! -name "*.indicators-calculated" -mtime +1 -delete
# Sell something?
#check_for_sell
# Get current balance # Get current balance
[ ${FULL_LOOP} = 1 ] && get_balance || continue [ ${FULL_LOOP} = 1 ] && get_balance || continue
@@ -93,8 +86,11 @@ do
# Get current positions # Get current positions
[ ${FULL_LOOP} = 1 ] && get_positions || continue [ ${FULL_LOOP} = 1 ] && get_positions || continue
## Buy something? # Get current orders
#[ ${FULL_LOOP} = 1 ] && check_for_buy [ ${FULL_LOOP} = 1 ] && get_orders || continue
## Run strategies
[ ${FULL_LOOP} = 1 ] && run_strategies
done done

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
# functions # functions
BASEPATH=/dabo/htdocs BASEPATH=/dabo/htdocs
@@ -21,6 +41,8 @@ set +a
mkdir -p ${BASEPATH}/botdata/asset-histories mkdir -p ${BASEPATH}/botdata/asset-histories
cd ${BASEPATH}/botdata cd ${BASEPATH}/botdata
ECO_ASSETS="DXY DOWJONES SP500 NASDAQ MSCIEAFE 10YRTREASURY GOLD MSCIWORLD OILGAS KRE EUR-USD"
. ../../dabo-bot.conf . ../../dabo-bot.conf
. ../../dabo-bot.override.conf . ../../dabo-bot.override.conf

34
dabo/fetch-coinmarketcapids.sh Executable file
View File

@@ -0,0 +1,34 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /dabo/dabo-prep.sh
while true
do
g_echo_note "Next loop"
[ -s COINMARKETCAPIDS ] || get_marketdata_coinmarketcap_ids
sleeptime=$(($(TZ=UTC date +%s -d "next monday 0:00") - $(date +%s) +2 ))
g_echo_note "Waiting $sleeptime seconds until next run"
sleep $sleeptime
get_marketdata_coinmarketcap_ids
done

View File

@@ -1,9 +1,28 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /dabo/dabo-prep.sh . /dabo/dabo-prep.sh
interval=$1 interval=$1
[ -z "$interval" ] && return 1 [ -z "$interval" ] && exit 1
seconds=$2 seconds=$2
while true while true
@@ -12,14 +31,25 @@ do
# Reload Config # Reload Config
. ../../dabo-bot.conf . ../../dabo-bot.conf
. ../../dabo-bot.override.conf . ../../dabo-bot.override.conf
# notify failed downloads
if [ "$interval" = "1h" ]
then
cat FAILED_*/* 2>/dev/null | notify.sh -s "Failed downloads"
mkdir -p REPORTED_FAILED
mv FAILED_*/* REPORTED_FAILED/ 2>/dev/null
fi
# Timestamp # Timestamp
export f_timestamp=$(g_date_print) export f_timestamp=$(g_date_print)
# get candles and indicators # get candles and indicators
get_ohlcv-candles $interval get_ohlcv-candles $interval
[[ $interval != 1w ]] && get_marketdata_all $interval
[ -n "$seconds" ] && sleeptime=$(( ( ($seconds - $(TZ=UTC printf "%(%s)T") % $seconds) % $seconds + 2 ))) [ -n "$seconds" ] && sleeptime=$(( ( ($seconds - $(TZ=UTC printf "%(%s)T") % $seconds) % $seconds + 2 )))
#[[ $interval = 4h ]] && #[[ $interval = 4h ]] && sleeptime=??
[ "$interval" = "1d" ] && sleeptime=$(($(TZ=UTC date +%s -d "tomorrow 0:00") - $(date +%s) +2 )) if [ "$interval" = "1d" ]
[ "$interval" = "1w" ] && sleeptime=$(($(TZ=UTC date +%s -d "next monday 0:00") - $(date +%s) +2 )) then
sleeptime=$(($(TZ=UTC date +%s -d "tomorrow 0:01") - $(date +%s) +2 ))
fi
[ "$interval" = "1w" ] && sleeptime=$(($(TZ=UTC date +%s -d "next monday 0:01") - $(date +%s) +2 ))
g_echo_note "Waiting $sleeptime seconds until next run" g_echo_note "Waiting $sleeptime seconds until next run"
sleep $sleeptime sleep $sleeptime
done done

View File

@@ -1,5 +1,24 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /dabo/dabo-prep.sh . /dabo/dabo-prep.sh
while true while true

View File

@@ -1,5 +1,24 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /dabo/dabo-prep.sh . /dabo/dabo-prep.sh
while true while true

View File

@@ -1,12 +1,42 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /dabo/dabo-prep.sh . /dabo/dabo-prep.sh
sleep 1800 sleep 1800
while true while true
do do
>ALL_TRANSACTIONS_OVERVIEW.csv.tmp
g_echo_note "Next loop" g_echo_note "Next loop"
transactions_overview get_bitpanda_api_transactions
get_justtrade_csv_transactions
get_onetrading_csv_transactions
get_phemex_csv_transactions
get_transactions
for transaction_csv in TRANSACTIONS-*.csv
do
calc_fifo_pnl "$transaction_csv"
done
mv ALL_TRANSACTIONS_OVERVIEW.csv.tmp ALL_TRANSACTIONS_OVERVIEW.csv
webpage_transactions
sleep 3600 sleep 3600
done done

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function calc_ema { function calc_ema {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -20,23 +40,26 @@ function calc_ema {
# check if there is a column (i from loop through array) # check if there is a column (i from loop through array)
[ -z "$f_column" ] && return 3 [ -z "$f_column" ] && return 3
# check for enough positions/values to calculate (enough values)
[ $f_position -ge $f_period ] || return 0
# get ema column # get ema column
[ -z "$f_target_column" ] && local f_target_column="ema$f_period" [ -z "$f_target_column" ] && local f_target_column="ema$f_period"
local f_last_value=${v_csv_array_associative[${f_column}_${f_position}]} local f_last_value=${v_csv_array_associative[${f_column}_${f_position}]}
[ -z "$f_target_column" ] && return 4 [ -z "$f_target_column" ] && return 4
local v local f_v
# reset old ema var # reset old ema var
unset f_ema unset f_ema
# find last EMA # find last EMA
local f_last_ema_position=$((f_position-1)) local f_last_ema_position=$((f_position-1))
local f_last_ema=${v_csv_array_associative[${f_target_column}_${f_last_ema_pos}]} local f_last_ema=${v_csv_array_associative[${f_target_column}_${f_last_ema_position}]}
# check for enough positions/values to calculate (enough values) if SMA needed
if [ -z "$f_last_ema" ]
then
[ $f_position -ge $f_period ] || return 5
fi
# check if last EMA is given # check if last EMA is given
if [ -n "$f_last_ema" ] if [ -n "$f_last_ema" ]
@@ -46,15 +69,17 @@ function calc_ema {
else else
## calc SMA if previous EMA is not given (only needed on first EMA calc) ## calc SMA if previous EMA is not given (only needed on first EMA calc)
# get last $f_period values # get last $f_period values
g_echo_note "calc SMA - previous EMA is not given"
local f_last_period_values_from=$((f_position-$f_period+1)) local f_last_period_values_from=$((f_position-$f_period+1))
local f_last_period_values local f_last_period_values
for ((v=$f_last_period_values_from; v<=${f_position}; v++)) for ((f_v=$f_last_period_values_from; f_v<=${f_position}; f_v++))
do do
if [ -z ${f_last_period_values} ] if [ -z ${f_last_period_values} ]
then then
f_last_period_values=${v_csv_array_associative[${f_column}_${v}]} f_last_period_values=${v_csv_array_associative[${f_column}_${f_v}]}
else else
f_last_period_values="$f_last_period_values+${v_csv_array_associative[${f_column}_${v}]}" g_calc "${f_last_period_values}+${v_csv_array_associative[${f_column}_${f_v}]}"
f_last_period_values=$g_calc_result
fi fi
done done
# calc SMA (EMA=SMA in this special first case) # calc SMA (EMA=SMA in this special first case)
@@ -62,9 +87,16 @@ function calc_ema {
fi fi
# write back EMA # write back EMA
if [[ $g_calc_result =~ ^- ]]
then
if ! [[ $f_period = 9 ]]
then
g_echo_warn "${FUNCNAME} $@: EMA can not be negative ($g_calc_result)"
return 1
fi
fi
v_csv_array_associative[${f_target_column}_${f_position}]=$g_calc_result v_csv_array_associative[${f_target_column}_${f_position}]=$g_calc_result
f_ema=$g_calc_result f_ema=$g_calc_result
return 0 return 0
} }

View File

@@ -0,0 +1,525 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function calc_fifo_pnl {
# Initialize variables
local f_csv_file="$1"
local f_current_year=$(date +%Y)
declare -A f_holdings
local f_date f_action f_symbol f_crypto_amount f_fiat_currency f_fiat_amount f_exchange f_fee_currency f_fee_amount f_note f_fiat_amount_tax_currency
# Read CSV file line by line
while IFS=',' read -r f_date f_action f_symbol f_crypto_amount f_fiat_currency f_fiat_amount f_exchange f_fee_currency f_fee_amount f_note
do
## Debug
#[ "$f_symbol" == "ETH" ] || continue
#[ "$f_note" == "short" ] && continue
# ignore stable coins
[[ $f_symbol == USDT || $f_symbol == EUR ]] && continue
# Extract year from date
local f_year=${f_date:0:4}
## Debug
#[ "$f_year" == "2024" ] || continue
#[ "$f_action" == "fundingfee" ] && continue
# add exchange
[[ "$f_exchanges" != *"$f_exchange "* ]] && f_exchanges+="$f_exchange "
# prevent exponential numbers
g_num_exponential2normal $f_crypto_amount
f_crypto_amount=$g_num_exponential2normal_result
g_num_exponential2normal $f_fiat_amount
f_fiat_amount=$g_num_exponential2normal_result
g_num_exponential2normal $f_fee_amount
f_fee_amount=$g_num_exponential2normal_result
## Debug
#echo "f_fiat_amount=$f_fiat_amount"
# convert f_fiat_currency/f_fiat_amount to TRANSFER_CURRENCY/f_fiat_amount_tax_currency if they are not equal
if ! [ "$f_fiat_currency" == "$TRANSFER_CURRENCY" ] && [ "$f_fiat_amount" != "0" ]
then
currency_converter $f_fiat_amount "$f_fiat_currency" $TRANSFER_CURRENCY "$f_date" >/dev/null
f_fiat_amount_tax_currency=$f_currency_converter_result
else
f_fiat_amount_tax_currency=$f_fiat_amount
fi
## Debug
#echo "f_fiat_amount_tax_currency=$f_fiat_amount_tax_currency"
# convert f_fee_currency/f_fee_amount to TRANSFER_CURRENCY/f_fiat_amount_tax_currency if present
if [ -n "$f_fee_amount" ]
then
currency_converter $f_fee_amount $f_fee_currency $TRANSFER_CURRENCY "$f_date" >/dev/null
f_fee_amount=$f_currency_converter_result
[[ $f_action == "buy" || $f_action == "leverage-buy" ]] && g_calc "$f_fiat_amount_tax_currency + $f_fee_amount"
[[ $f_action == "sell" || $f_action == "leverage-sell" || $f_action == "liquidation" ]] && g_calc "$f_fiat_amount_tax_currency - $f_fee_amount"
f_fiat_amount_tax_currency=$g_calc_result
fi
## Debug
#echo "f_fiat_amount_tax_currency=$f_fiat_amount_tax_currency"
# no space in date (prevent problems mit $f_holdings)
f_date="${f_date/ /T}"
# get current holfings for determining if this is a long or short trade (f_holdings_amount)
get_holdings_amount
## Debug
#echo "f_crypto_amount=$f_crypto_amount"
# Process fundingfee action
if [[ $f_action == "fundingfee" ]]
then
process_fundingfee "$f_symbol" "$f_crypto_amount" "$f_fee_amount" "$f_date" "$f_year"
# Process buy actions
elif [[ $f_action == "buy" || $f_action == "leverage-buy" || $f_action == "reward-staking" || $f_action == "giveaway" || $f_action == "instant_trade_bonus" ]]
then
if g_num_is_higher_equal $f_holdings_amount 0
then
# long
## Debug
#echo process_buy "$f_symbol" "$f_crypto_amount" "$f_fiat_amount_tax_currency" "$f_date"
process_buy "$f_symbol" "$f_crypto_amount" "$f_fiat_amount_tax_currency" "$f_date"
elif g_num_is_lower_equal "$f_holdings_amount" "-$f_crypto_amount"
then
# short
## Debug
#echo process_sell "$f_symbol" "$f_crypto_amount" "$f_fiat_amount_tax_currency" "$f_date" "$f_year" short
process_sell "$f_symbol" "$f_crypto_amount" "$f_fiat_amount_tax_currency" "$f_date" "$f_year" short
else
# long+short (partial)
# calc long/short parts
g_percentage-diff "-$f_crypto_amount" "$f_holdings_amount"
g_calc "$f_fiat_amount_tax_currency/100*($g_percentage_diff_result+100)"
f_fiat_amount_tax_currency_long=$g_calc_result
g_calc "$f_fiat_amount_tax_currency/100*(($g_percentage_diff_result*-1))"
f_fiat_amount_tax_currency_short=$g_calc_result
g_calc "$f_crypto_amount/100*($g_percentage_diff_result+100)"
f_crypto_amount_long=$g_calc_result
g_calc "$f_crypto_amount/100*($g_percentage_diff_result*-1)"
f_crypto_amount_short=$g_calc_result
# part short-sell
# part long-sell
## Debug
#echo PART: process_sell process_sell "$f_symbol" "$f_crypto_amount_long" "$f_fiat_amount_tax_currency_long" "$f_date" "$f_year"
process_sell "$f_symbol" "$f_crypto_amount_long" "$f_fiat_amount_tax_currency_long" "$f_date" "$f_year"
## Debug
#echo PART: process_buy "$f_symbol" "$f_crypto_amount_long" "$f_fiat_amount_tax_currency_long" "$f_date" "$f_year"
process_buy "$f_symbol" "$f_crypto_amount_long" "$f_fiat_amount_tax_currency_long" "$f_date" "$f_year"
fi
# Process sell actions
elif [[ $f_action == "sell" || $f_action == "leverage-sell" || $f_action == "liquidation" ]]
then
# check for long or short or log+short
if g_num_is_higher_equal "$f_holdings_amount" "$f_crypto_amount"
then
# long
## Debug
#echo process_sell "$f_symbol" "$f_crypto_amount" "$f_fiat_amount_tax_currency" "$f_date" "$f_year"
process_sell "$f_symbol" "$f_crypto_amount" "$f_fiat_amount_tax_currency" "$f_date" "$f_year"
elif g_num_is_higher "$f_holdings_amount" 0
then
# long+short (partial)
# calc long/short parts
g_percentage-diff "$f_crypto_amount" "$f_holdings_amount"
g_calc "$f_fiat_amount_tax_currency/100*($g_percentage_diff_result+100)"
f_fiat_amount_tax_currency_long=$g_calc_result
g_calc "$f_fiat_amount_tax_currency/100*(($g_percentage_diff_result*-1))"
f_fiat_amount_tax_currency_short=$g_calc_result
g_calc "$f_crypto_amount/100*($g_percentage_diff_result+100)"
f_crypto_amount_long=$g_calc_result
g_calc "$f_crypto_amount/100*($g_percentage_diff_result*-1)"
f_crypto_amount_short=$g_calc_result
# part long-sell
## Debug
#echo PART: process_sell "$f_symbol" "$f_crypto_amount_long" "$f_fiat_amount_tax_currency_long" "$f_date" "$f_year"
process_sell "$f_symbol" "$f_crypto_amount_long" "$f_fiat_amount_tax_currency_long" "$f_date" "$f_year"
# part short-sell
## Debug
#echo PART: process_buy "$f_symbol" "$f_crypto_amount_short" "$f_fiat_amount_tax_currency_short" "$f_date" short
process_buy "$f_symbol" "$f_crypto_amount_short" "$f_fiat_amount_tax_currency_short" "$f_date" short
elif [[ $f_action == "liquidation" ]]
then
# short sell/liquidation
## Debug
#echo process_sell "$f_symbol" "$f_crypto_amount" "$f_fiat_amount_tax_currency" "$f_date" $f_year short
process_sell "$f_symbol" "$f_crypto_amount" "$f_fiat_amount_tax_currency" "$f_date" $f_year short
else
# short buy
## Debug
#echo process_buy "$f_symbol" "$f_crypto_amount" "$f_fiat_amount_tax_currency" "$f_date" short
process_buy "$f_symbol" "$f_crypto_amount" "$f_fiat_amount_tax_currency" "$f_date" short
fi
fi
## DEBUG output
#get_holdings_amount
#echo "f_holdings_amount=$f_holdings_amount"
#echo "============================"
done < "$f_csv_file"
}
function process_buy {
local f_symbol="$1" f_amount="$2" f_price="$3" f_date="$4" f_short="$5"
local f_tax_type f_trade_tax
# Add to holdings
# long
[ -z "$f_short" ] && f_holdings[$f_symbol]+="$f_amount:$f_price:$f_date "
# short
if [ -n "$f_short" ]
then
f_holdings[$f_symbol]+="-$f_amount:$f_price:$f_date "
f_action="${f_action}-short"
## Debug
#echo ACTION:$f_action
elif [[ $f_action == "reward-staking" ]]
then
f_tax_type="Sonst-Einkünfte-Staking"
elif [[ $f_action == "giveaway" ]]
then
f_tax_type="Sonst-Einkünfte-Giveaway"
elif [[ $f_action == "instant_trade_bonus" ]]
then
f_tax_type="Kapitalertrag-Instant-Trade-Bonus"
fi
if [ -n "$f_tax_type" ]
then
f_trade_tax=$f_price
f_fiat_amount=0
f_fiat_amount_tax_currency=0
fi
echo "$f_date,$f_exchange,$f_action,$f_symbol,$f_amount,$f_fiat_currency,-$f_price,,,,,,$f_tax_type,$f_trade_tax,-$f_price,,,,,,,,," >>ALL_TRANSACTIONS_OVERVIEW.csv.tmp
}
function process_sell {
local f_symbol="$1" f_sell_amount="$2" f_sell_price="$3" f_sell_date="$4" f_year="$5" f_short="$6"
f_remaining_sell=$f_sell_amount
local f_profit=0 f_loss=0 f_profit_tax=0 f_loss_tax=0 f_trade_tax=0
local f_pnl
# define tax type
local f_tax_type="Kapitalertrag-Derivat"
local f_trade_result
[[ $f_action == "sell" ]] && f_tax_type="Veräußerungsgeschäft"
local f_buy_amount f_buy_price f_buy_date
# Process each holding using FIFO
while [[ $f_remaining_sell > 0 && -n "${f_holdings[$f_symbol]}" ]]
do
IFS=':' read -r f_buy_amount f_buy_price f_buy_date < <(echo "${f_holdings[$f_symbol]%% *}")
# Calculate amount to sell from this holding
f_sell_from_holding=$f_buy_amount
[ -n "$f_short" ] && f_remaining_sell=-${f_remaining_sell#-}
[ -z "$f_short" ] && g_num_is_lower $f_remaining_sell $f_buy_amount && f_sell_from_holding=$f_remaining_sell
[ -n "$f_short" ] && g_num_is_higher $f_remaining_sell $f_buy_amount && f_sell_from_holding=$f_remaining_sell
# calculate sell percentage of buy trade
## Debug
#echo "f_sell_from_holding=$f_sell_from_holding"
[ -z "$f_short" ] && g_percentage-diff $f_buy_amount $f_sell_from_holding
[ -n "$f_short" ] && g_percentage-diff $f_buy_amount $f_sell_from_holding
g_calc "100+$g_percentage_diff_result"
f_percentage_of_buy=${g_calc_result#-}
## Debug
#echo "f_percentage_of_buy=$f_percentage_of_buy"
# Calculate profit/loss (pnl)
## Debug
#echo "f_sell_price=$f_sell_price"
#echo "f_buy_price=$f_buy_price"
# if not first iteration (f_pnl is already set from previous iteration) and partial sell
if [ -n "$f_pnl" ]
then
# on multiple iteration partial sell
g_calc "$f_pnl - ($f_buy_price/100*$f_percentage_of_buy)"
else
# on first interation partial sell
g_calc "$f_sell_price - ($f_buy_price/100*$f_percentage_of_buy)"
fi
local f_pnl=$g_calc_result
## Debug
#echo "f_pnl=$f_pnl"
# Check if trade is tax-free (held for more than a year)
local f_is_taxable=true
if [ "$f_tax_type" == "Veräußerungsgeschäft" ]
then
local f_days_held=$(( ($(date -d "$f_sell_date" +%s) - $(date -d "$f_buy_date" +%s)) / 86400 ))
[[ $f_days_held -gt 365 && ${f_tax_type} == "Veräußerungsgeschäft" ]] && f_is_taxable=false
fi
# Update remaining sell amount and holdings
g_calc "$f_remaining_sell - $f_sell_from_holding"
f_remaining_sell=$g_calc_result
## Debug
#echo "f_remaining_sell=$f_remaining_sell"
#echo "HOLDINGS1: ${f_holdings[$f_symbol]}"
f_holdings[$f_symbol]="${f_holdings[$f_symbol]#* }"
# If there's remaining amount in the holding, add it back
[ -z "$f_short" ] && g_calc "$f_buy_amount - $f_sell_from_holding"
[ -n "$f_short" ] && g_calc "$f_buy_amount + $f_sell_from_holding"
g_calc "$f_buy_amount - $f_sell_from_holding"
local f_remaining_buy_amount=$g_calc_result
## Debug
#echo "f_remaining_buy_amount=$g_calc_result"
#if g_num_is_higher $f_remaining_buy_amount 0
if [ "$f_remaining_buy_amount" != "0" ]
then
g_calc "$f_buy_price/100*(100-$f_percentage_of_buy)"
f_remaining_buy_price=$g_calc_result
f_holdings[$f_symbol]="$f_remaining_buy_amount:$f_remaining_buy_price:$f_buy_date ${f_holdings[$f_symbol]}"
fi
## Debug
#echo "HOLDINGS2: ${f_holdings[$f_symbol]}"
done
# Update profit/loss
[ -n "$f_short" ] && g_calc "$f_pnl * -1" && f_pnl=$g_calc_result
if g_num_is_higher $f_pnl 0
then
g_calc "$f_profit + $f_pnl"
f_profit=$g_calc_result
else
g_calc "$f_loss - $f_pnl"
f_loss=$g_calc_result
fi
# calculate result of trade
g_calc "$f_profit - $f_loss"
f_trade_result=$g_calc_result
# calculate taxable part of trade
if [[ $f_is_taxable == true ]]
then
g_calc "$f_trade_tax + $f_pnl"
f_trade_tax=$g_calc_result
fi
## DEBUG output
#get_holdings_amount
#echo "f_holdings_amount=$f_holdings_amount"
#echo "Result: $f_trade_result ; taxable=$f_is_taxable ; REMAINING: $f_holdings_amount"
# write to csv
if [ -n "$f_short" ]
then
f_action="${f_action}-short"
## Debug
#echo ACTION:$f_action
fi
[ "$f_trade_tax" == "0" ] && [ "$f_tax_type" == "Veräußerungsgeschäft" ] && f_tax_type="Veräußerungsgeschäft Spekulationsfrist > 1 Jahr"
echo "$f_date,$f_exchange,$f_action,$f_symbol,-$f_sell_amount,$f_fiat_currency,$f_sell_price,,,,,,$f_tax_type,$f_trade_tax,$f_sell_price,,$f_trade_result,,,,,,," >>ALL_TRANSACTIONS_OVERVIEW.csv.tmp
[ -z "$f_trade_result" ] && g_echo_error "No trade result!!! Someting wrong $f_date,$f_symbol,$f_action $f_short"
}
function get_holdings_amount {
local block first_value
f_holdings_amount=0
# Durch jeden Block iterieren
IFS=" "
for block in ${f_holdings[$f_symbol]}
do
IFS=$origIFS
# Den ersten Wert vor dem Doppelpunkt extrahieren
first_value=${block%%:*}
# Zum Gesamtwert addieren
g_calc "$f_holdings_amount + $first_value"
f_holdings_amount=$g_calc_result
done
IFS=$origIFS
}
function process_fundingfee {
local f_symbol="$1" f_amount="$2" f_fiat_amount_tax_currency="$3" f_date="$4" f_year="$5"
## Debug
#echo "adding fundingfee: $f_fiat_amount_tax_currency"
## add fundingfee
[[ $f_fiat_amount_tax_currency == -* ]] && f_tax="${f_fiat_amount_tax_currency#-}"
[[ $f_fiat_amount_tax_currency == -* ]] || f_tax="-${f_fiat_amount_tax_currency}"
echo "$f_date,$f_exchange,$f_action,$f_symbol,$f_amount,,,,,,,,Kapitalertrag-Derivat,$f_tax,$f_tax,,$f_tax,,,,,,," >>ALL_TRANSACTIONS_OVERVIEW.csv.tmp
}
#function transaction_csv_validity_ckecks {
# local f_buy f_sell f_liquidation f_liquidation_short
# local f_complete_result=0
# declare -A transaction_csv_validity_ckeck_buy_sell_diff
#
# f_symbols=$(cut -d, -f3 $f_csv_file | sort -u)
# local f_buy_amount f_sell_amount f_tax_type
#
# # go through symbols and male some pre-checks
# for f_symbol in $f_symbols
# do
#
# ## check asset amount
# g_echo_note "Initial checks for $f_symbol"
# # add all buys and sells of a symbols amount
# f_buy=$(\
# egrep "buy,${f_symbol},|,reward-staking,${f_symbol}|,giveaway,${f_symbol},instant_trade_bonus,${f_symbol}" "$f_csv_file" | \
# cut -d, -f4 | \
# awk '{ SUM += $1} END { printf("%.12f\n", SUM) }' \
# )
# f_sell=$(\
# egrep "sell,${f_symbol}," "$f_csv_file" | \
# cut -d, -f4 | \
# awk '{ SUM += $1} END { printf("%.12f\n", SUM) }' \
# )
# f_liquidation=$(\
# egrep "liquidation,${f_symbol}," "$f_csv_file" | \
# grep -v ",short" | \
# cut -d, -f4 | \
# awk '{ SUM += $1} END { printf("%.12f\n", SUM) }' \
# )
# f_liquidation_short=$(\
# egrep "liquidation,${f_symbol},.+,short" "$f_csv_file" | \
# cut -d, -f4 | \
# awk '{ SUM += $1} END { printf("%.12f\n", SUM) }' \
# )
#
# # add liquidations to sell
# # long
# g_calc "$f_sell + $f_liquidation - $f_liquidation_short"
# f_sell=$g_calc_result
#
# # buy should be same as sell sum to be fine - if not:
# g_calc "$f_buy == $f_sell"
# if ! [[ $g_calc_result == 1 ]]
# then
# g_echo_note "buy ($f_buy) and sell ($f_sell) amount sums are different for ${f_symbol}. Open Positions!?"
# g_calc "$f_sell - ($f_buy)"
# transaction_csv_validity_ckecks[$f_symbol]=$g_calc_result
# else
# transaction_csv_validity_ckeck_buy_sell_diff[$f_symbol]=0
# fi
#
# done
#}
function print_results {
local f_csv=ALL_TRANSACTIONS_OVERVIEW.csv
local f_exchange_symbol f_exchange_symbol_year_tax f_amount f_result
#transaction_csv_validity_ckecks
echo ""
echo "Open Positions:"
echo "==============="
local f_exchanges_symbols=$(cut -d, -f 2,4 "$f_csv" | sort -u)
for f_exchange_symbol in $f_exchanges_symbols
do
f_exchange=${f_exchange_symbol%%,*}
f_symbol=${f_exchange_symbol#*,}
f_amount=$(\
egrep ",${f_exchange},.+,$f_symbol" "$f_csv" | \
cut -d, -f5 | \
awk '{ SUM += $1} END { printf("%.12f\n", SUM) }' \
)
f_result=$(\
egrep ",${f_exchange},.*sell,$f_symbol|,${f_exchange},.*buy,$f_symbol" "$f_csv" | \
#egrep "${f_exchange},.+,$f_symbol" "$f_csv" \
cut -d, -f17 | \
awk '{ SUM += $1} END { printf("%.2f\n", SUM) }' \
)
g_calc "$f_amount == 0"
if ! [[ $g_calc_result == 1 ]]
then
echo "$f_exchange/$f_symbol: $f_amount"
fi
done
echo ""
echo "Profit and Loss (Tax):"
echo "======================"
declare -A f_taxes f_pnls
local f_total_tax
local f_exchanges_symbols_years_tax=$(sed 's/-/,/' "$f_csv" | cut -d, -f 1,3,5,14 | sort -u)
for f_exchange_symbol_year_tax in $f_exchanges_symbols_years_tax
do
IFS=',' read -r f_year f_exchange f_symbol f_tax_type < <(echo "$f_exchange_symbol_year_tax")
[ -z "$f_tax_type" ] && continue
f_tax=$(\
egrep "^$f_year-.+,${f_exchange},.+,${f_symbol},.+,$f_tax_type" "$f_csv" | \
cut -d, -f14 | \
awk '{ SUM += $1} END { printf("%.2f\n", SUM) }' \
)
f_pnl=$(\
egrep "^$f_year-.+,${f_exchange},.+,${f_symbol},.+,$f_tax_type" "$f_csv" | \
cut -d, -f17 | \
awk '{ SUM += $1} END { printf("%.2f\n", SUM) }' \
)
echo "$f_year/$f_exchange/$f_symbol/$f_tax_type: $f_tax $TRANSFER_CURRENCY"
[ -z "${f_taxes[${f_year}_${f_exchange}_${f_tax_type}]}" ] && f_taxes[${f_year}_${f_exchange}_${f_tax_type}]=0
[ -z "${f_pnls[${f_year}_${f_exchange}]}" ] && f_pnls[${f_year}_${f_exchange}]=0
g_calc "${f_taxes[${f_year}_${f_exchange}_${f_tax_type}]} + ($f_tax)"
f_taxes[${f_year}_${f_exchange}_${f_tax_type}]=$g_calc_result
g_calc "${f_pnls[${f_year}_${f_exchange}]} + ($f_pnl)"
f_pnls[${f_year}_${f_exchange}]=$g_calc_result
done
echo ""
echo "Profit and Loss (Tax per exchange):"
echo "==================================="
for f_tax_year in "${!f_taxes[@]}"
do
echo "$f_tax_year: ${f_taxes[$f_tax_year]} $TRANSFER_CURRENCY"
done | sort
echo ""
echo "Profit and Loss:"
echo "================"
for f_pnl_year in "${!f_pnls[@]}"
do
echo "$f_pnl_year: ${f_pnls[$f_pnl_year]} $TRANSFER_CURRENCY"
done | sort
}

View File

@@ -1,4 +1,23 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function calc_macd { function calc_macd {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function calc_rsi { function calc_rsi {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function f_ccxt { function f_ccxt {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -34,6 +54,11 @@ function f_ccxt {
local f_exchange_type="swap" local f_exchange_type="swap"
[ -z "$LEVERAGE" ] && f_exchange_type="spot" [ -z "$LEVERAGE" ] && f_exchange_type="spot"
g_python "${STOCK_EXCHANGE} = ccxt.${STOCK_EXCHANGE}({'apiKey': '${API_KEY}','secret': '${API_SECRET}','enableRateLimit': True,'options': {'defaultType': '${f_exchange_type}',},})" || return 1 g_python "${STOCK_EXCHANGE} = ccxt.${STOCK_EXCHANGE}({'apiKey': '${API_KEY}','secret': '${API_SECRET}','enableRateLimit': True,'options': {'defaultType': '${f_exchange_type}',},})" || return 1
if [[ $TESTNET = true ]]
then
g_echo_note "ATTENTION: RUNNING IN TESTNET/SIMULATION/MOCK MODE OF EXCHANGE ${STOCK_EXCHANGE}!!!"
g_python "${STOCK_EXCHANGE}.set_sandbox_mode(True)" || return 1
fi
g_python "${STOCK_EXCHANGE}markets=${STOCK_EXCHANGE}.load_markets()" || return 1 g_python "${STOCK_EXCHANGE}markets=${STOCK_EXCHANGE}.load_markets()" || return 1
f_ccxt_initialized="${f_ccxt_initialized}${STOCK_EXCHANGE}," f_ccxt_initialized="${f_ccxt_initialized}${STOCK_EXCHANGE},"
fi fi
@@ -65,7 +90,7 @@ function f_ccxt {
# make the output jq-conform if json poutput # make the output jq-conform if json poutput
# avoids errors like: "parse error: Invalid numeric literal at" # avoids errors like: "parse error: Invalid numeric literal at"
f_ccxt_result=$(echo $f_ccxt_result | sed "s/'/\"/g; s/ None/ null/g; s/ True/ true/g; s/ False/ false/g; s/,,/,/g") f_ccxt_result=$(echo $f_ccxt_result | sed "s/'/\"/g; s/ None/ null/g; s/ True/ true/g; s/ False/ false/g; s/,,/,/g")
# sed is needed here because bash parameter substitution like down here hands with 100% cpu usage if the variable is large. Noticed with output about ~2.5M # sed is needed here because bash parameter substitution like down here hangs with 100% cpu usage if the variable is large. Noticed with output about ~2.5M
#f_ccxt_result=${f_ccxt_result//\'/\"} #f_ccxt_result=${f_ccxt_result//\'/\"}
#f_ccxt_result=${f_ccxt_result// None/ null} #f_ccxt_result=${f_ccxt_result// None/ null}
#f_ccxt_result=${f_ccxt_result// True/ true} #f_ccxt_result=${f_ccxt_result// True/ true}

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function charts { function charts {
if ! find ../lightweight-charts.standalone.production.js -mtime -1 2>/dev/null | grep -q "lightweight-charts.standalone.production.js" if ! find ../lightweight-charts.standalone.production.js -mtime -1 2>/dev/null | grep -q "lightweight-charts.standalone.production.js"
then then

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function check_buy_conditions { function check_buy_conditions {
local f_ASSET_HIST_FILE="$1" local f_ASSET_HIST_FILE="$1"

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function check_for_buy { function check_for_buy {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function check_for_sell { function check_for_sell {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function check_sell_conditions { function check_sell_conditions {
local f_ASSET_HIST_FILE="$1" local f_ASSET_HIST_FILE="$1"

View File

@@ -1,15 +1,48 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function currency_converter { function currency_converter {
#g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_currency_amount=$1 local f_currency_amount=$1
local f_currency=$2 local f_currency=$2
local f_currency_target=$3 local f_currency_target=$3
local f_currency_date=$4 local f_currency_date=$4
local f_return
unset f_currency_converter_result unset f_currency_converter_result
local f_line f_rate f_histfile f_date_array f_stablecoin f_reverse # check for cached result
local f_args=$@
[ -f CACHE_CURRENCY_CONVERTER ] && f_currency_converter_result=$(egrep "^${f_args}=" CACHE_CURRENCY_CONVERTER | cut -d= -f2)
[[ -n $f_currency_converter_result ]] && g_num_valid_number "$f_currency_converter_result" && return 0
local f_line f_rate f_histfile f_date_array f_stablecoin f_reverse f_file f_link_file f_timeframe
if [[ $f_currency_target =~ ^20.*-.*: ]]
then
g_echo_warn "${FUNCNAME} $@: Invalid target"
g_traceback
return 1
fi
# get current date if none given # get current date if none given
[ -z "$f_currency_date" ] && printf -v f_currency_date '%(%Y-%m-%d %H:%M:%S)T' [ -z "$f_currency_date" ] && printf -v f_currency_date '%(%Y-%m-%d %H:%M:%S)T'
@@ -24,27 +57,30 @@ function currency_converter {
f_currency_date_day=$(date -d "${f_currency_date}" "+%Y-%m-%d") f_currency_date_day=$(date -d "${f_currency_date}" "+%Y-%m-%d")
# month failback # month failback
f_currency_date_month=$(date -d "${f_currency_date}" "+%Y-%m") if [ $(date -d "${f_currency_date}" "+%d") = "01" ]
then
# on first day in month use month before because no date from current month
f_currency_date_month=$(date -d "${f_currency_date} yesterday" "+%Y-%m")
else
f_currency_date_month=$(date -d "${f_currency_date}" "+%Y-%m")
fi
# path to history files for the converting rate # path to history files for the converting rate
[ -d asset-histories ] && f_asset_histories="asset-histories/" [ -d asset-histories ] || mkdir asset-histories
f_asset_histories="asset-histories/"
# map USD-Stablecoins to USD # map USD-Stablecoins to USD
local f_stablecoins="USDT BUSD" local f_stablecoins="USDT BUSD"
for f_stablecoin in $f_stablecoins for f_stablecoin in $f_stablecoins
do do
# Link USD Stablecoin files to USD # Link USD Stablecoin files to USD
if [ -s ${f_asset_histories}${f_currency}${f_stablecoin}.history-raw.csv ] cd "$f_asset_histories"
then find . -maxdepth 1 -mindepth 1 -name "*${f_stablecoin}.history.*.csv" | while read f_file
[ -e ${f_asset_histories}${f_currency}USD.history-raw.csv ] || \ do
ln ${f_asset_histories}${f_currency}${f_stablecoin}.history-raw.csv ${f_asset_histories}${f_currency}USD.history-raw.csv f_link_file=${f_file/${f_stablecoin}/USD}
fi ln -sf "$f_file" "$f_link_file"
done
if [ -s ${f_asset_histories}${f_currency_target}${f_stablecoin}.history-raw.csv ] cd - >/dev/null
then
[ -e ${f_asset_histories}USD${f_currency_target}.history-raw.csv ] || \
ln ${f_asset_histories}${f_currency_target}${f_stablecoin}.history-raw.csv ${f_asset_histories}USD${f_currency_target}.history-raw.csv
fi
# use USD # use USD
if [[ $f_currency_target = $f_stablecoin ]] if [[ $f_currency_target = $f_stablecoin ]]
then then
@@ -55,6 +91,29 @@ function currency_converter {
f_currency=USD f_currency=USD
fi fi
done done
# map EUR-Stablecoins to EUR
local f_stablecoins="EURC"
for f_stablecoin in $f_stablecoins
do
# Link EUR Stablecoin files to EUR
cd "$f_asset_histories"
find . -maxdepth 1 -mindepth 1 -name "*${f_stablecoin}.history.*.csv" | while read f_file
do
f_link_file=${f_file/${f_stablecoin}/EUR}
ln -sf "$f_file" "$f_link_file"
done
cd - >/dev/null
# use USD
if [[ $f_currency_target = $f_stablecoin ]]
then
f_currency_target=EUR
fi
if [[ $f_currency = $f_stablecoin ]]
then
f_currency=EUR
fi
done
# if there is no currency change (USD USD or USDT USD) # if there is no currency change (USD USD or USDT USD)
if [[ $f_currency == $f_currency_target ]] if [[ $f_currency == $f_currency_target ]]
@@ -62,54 +121,72 @@ function currency_converter {
f_currency_converter_result=$f_currency_amount f_currency_converter_result=$f_currency_amount
return 0 return 0
fi fi
# try direct pair
get_marketdata_yahoo "${f_currency_target}-${f_currency}" "${f_currency_target}${f_currency}" || get_marketdata_yahoo "${f_currency}-${f_currency_target}" "${f_currency}${f_currency_target}"
local f_histfile_default="${f_asset_histories}${f_currency_target}${f_currency}.history"
local f_histfile_yahoo="${f_asset_histories}${f_currency_target}${f_currency}.history"
# reverse as backup
local f_histfile_default_reverse="${f_asset_histories}${f_currency}${f_currency_target}.history"
local f_histfile_yahoo_reverse="${f_asset_histories}${f_currency}${f_currency_target}.history"
# search for rate by date # define possiblefiles
for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse" "$f_histfile_yahoo" "$f_histfile_yahoo_reverse" local f_histfile_default="${f_asset_histories}${f_currency_target}${f_currency}.history"
local f_histfile_default_reverse="${f_asset_histories}${f_currency}${f_currency_target}.history"
for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse"
do do
# histfile has to exist # search for most precise date
#if [ -s "${f_histfile}*.csv" ] f_line=$(egrep "^$f_currency_date_minute" "$f_histfile"*m.csv 2>/dev/null | sort | tail -n1)
#then [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_hour" "$f_histfile"*m.csv 2>/dev/null | sort | tail -n1)
# search for most precise date [ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_day" "$f_histfile"*h.csv 2>/dev/null | sort | tail -n1)
f_line=$(egrep "^$f_currency_date_minute" "$f_histfile".*m.csv 2>/dev/null | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_hour" "$f_histfile".*h.csv 2>/dev/null | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_day" "$f_histfile".*d.csv 2>/dev/null | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_month" "$f_histfile"*.csv 2>/dev/null | tail -n1)
[ -n "$f_line" ] && f_rate=$(echo "$f_line" | cut -d, -f2)
f_reverse=false
if [ -n "$f_rate" ]
then
[[ $f_histfile =~ ${f_currency}${f_currency_target} ]] && f_reverse=true
[ $f_currency_target = "USD" ] && f_reverse=true
[ $f_currency = "USD" ] && f_reverse=false
[ $f_currency_target = "EUR" ] && [ $f_currency = "USD" ] && f_reverse=true
[[ $f_line =~ ^$f_currency_date_hour ]] && break
fi
#fi
done done
# end if no rate found # download from coinmarketcap if nothing found
[ -z "$f_line" ] && for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse"
do
# download data from coinmarketcap
for f_timeframe in 1d 1w
do
[ "${f_currency}" = "USD" ] && get_marketdata_coinmarketcap "${f_currency_target}-${f_currency}" "${f_currency_target}${f_currency}" $f_timeframe
[ "${f_currency_target}" = "USD" ] && get_marketdata_coinmarketcap "${f_currency}-${f_currency_target}" "${f_currency}${f_currency_target}" $f_timeframe
done
f_line=$(egrep "^$f_currency_date_minute" "$f_histfile"*m.csv 2>/dev/null | sort | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_hour" "$f_histfile"*m.csv 2>/dev/null | sort | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_day" "$f_histfile"*h.csv 2>/dev/null | sort | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_month" "$f_histfile"*.csv 2>/dev/null | sort | tail -n1)
[ -n "$f_line" ] && break
done
# extract rate/price
[ -n "$f_line" ] && f_rate=$(echo "$f_line" | cut -d, -f2)
f_reverse=false
if [ -n "$f_rate" ]
then
[[ $f_histfile =~ ${f_currency}${f_currency_target} ]] && f_reverse=true
[ $f_currency_target = "USD" ] && f_reverse=true
[ $f_currency = "USD" ] && f_reverse=false
[ $f_currency_target = "EUR" ] && [ $f_currency = "USD" ] && f_reverse=false
[[ $f_line =~ ^$f_currency_date_hour ]] && break
fi
# if no rate found
if [ -z "$f_rate" ] if [ -z "$f_rate" ]
then then
# try workaround over USD if EUR # if EUR source or traget try way over USD as workaround
if [[ ${f_currency_target} = EUR ]] && [[ $f_currency != USD ]] if [[ ${f_currency_target} = EUR ]] && [[ $f_currency != USD ]] && [[ $f_currency != EUR ]]
then then
#g_echo_note "trying way over USD (workaround)" g_echo_note "trying way over USD (workaround) Target EUR"
if currency_converter $f_currency_amount $f_currency USD $f_currency_date if currency_converter $f_currency_amount $f_currency USD "$f_currency_date"
then then
f_currency_amount=$f_currency_converter_result currency_converter $f_currency_converter_result USD EUR "$f_currency_date" && f_return=$?
currency_converter $f_currency_amount USD EUR $f_currency_date [[ $f_return == 0 ]] && echo "$@=$f_currency_converter_result" >>CACHE_CURRENCY_CONVERTER
return $? return $f_return
fi
elif [[ ${f_currency_target} != USD ]] && [[ ${f_currency_target} != EUR ]] && [[ $f_currency = EUR ]]
then
g_echo_note "trying way over USD (workaround) Source EUR"
if currency_converter $f_currency_amount EUR USD "$f_currency_date"
then
currency_converter $f_currency_converter_result USD ${f_currency_target} "$f_currency_date" && f_return=$?
[[ $f_return == 0 ]] && echo "$@=$f_currency_converter_result" >>CACHE_CURRENCY_CONVERTER
return $f_return
fi fi
fi fi
g_echo_warn "didn't find rate for ${f_currency}-${f_currency_target} - '${FUNCNAME} $@'" # end if no rate found
g_echo_error "didn't find rate for ${f_currency}-${f_currency_target} - '${FUNCNAME} $@'"
return 1 return 1
fi fi
@@ -118,5 +195,6 @@ function currency_converter {
[[ $f_reverse = false ]] && g_calc "1/${f_rate}*${f_currency_amount}" [[ $f_reverse = false ]] && g_calc "1/${f_rate}*${f_currency_amount}"
f_currency_converter_result=$g_calc_result f_currency_converter_result=$g_calc_result
} echo "$@=$f_currency_converter_result" >>CACHE_CURRENCY_CONVERTER
}

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function genchart { function genchart {
# generate css chart (line diagram) from csv file or simple file with number per line - needed charts.css included in webppage # generate css chart (line diagram) from csv file or simple file with number per line - needed charts.css included in webppage
local mark local mark

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_asset { function get_asset {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_balance { function get_balance {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -12,6 +32,7 @@ function get_balance {
printf -v CURRENCY_BALANCE %.2f ${f_CURRENCY_BALANCE} printf -v CURRENCY_BALANCE %.2f ${f_CURRENCY_BALANCE}
else else
g_echo_warn "Could not determine CURRENCY_BALANCE (${f_CURRENCY_BALANCE} ${CURRENCY}) from file CCXT_BALANCE $(tail -n 10 CCXT_BALANCE)" g_echo_warn "Could not determine CURRENCY_BALANCE (${f_CURRENCY_BALANCE} ${CURRENCY}) from file CCXT_BALANCE $(tail -n 10 CCXT_BALANCE)"
unset f_ccxt_initialized
return 3 return 3
fi fi

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_bitpanda_api_transactions { function get_bitpanda_api_transactions {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -38,7 +58,7 @@ function get_bitpanda_api_transactions {
select(.effective_leverage!= null) | select(.effective_leverage!= null) |
.time.date_iso8601 + ",leverage-" + .type + "," + .cryptocoin_symbol + "," + .amount_cryptocoin + ",EUR," + .amount_fiat + ",Bitpanda" .time.date_iso8601 + ",leverage-" + .type + "," + .cryptocoin_symbol + "," + .amount_cryptocoin + ",EUR," + .amount_fiat + ",Bitpanda"
' BITPANDA_trades.json >>BITPANDA.csv.tmp ' BITPANDA_trades.json >>BITPANDA.csv.tmp
# Workaround fpr staking-rewards (not availabpe per API yet (https://help.blockpit.io/hc/de-at/articles/360011790820-Wie-importiere-ich-Daten-mittels-Bitpanda-API-Key) # Workaround for staking-rewards (not availabpe per API yet (https://help.blockpit.io/hc/de-at/articles/360011790820-Wie-importiere-ich-Daten-mittels-Bitpanda-API-Key)
[ -s bitpanda-export.csv ] && cat bitpanda-export.csv | grep reward,incoming | awk -F, '{print $2",reward-staking,"$8","$7",EUR,"$5",Bitpanda"}' >>BITPANDA.csv.tmp [ -s bitpanda-export.csv ] && cat bitpanda-export.csv | grep reward,incoming | awk -F, '{print $2",reward-staking,"$8","$7",EUR,"$5",Bitpanda"}' >>BITPANDA.csv.tmp
cat BITPANDA.csv.tmp | grep -v ",reward.best," | sort >TRANSACTIONS-BITPANDA.csv cat BITPANDA.csv.tmp | grep -v ",reward.best," | sort >TRANSACTIONS-BITPANDA.csv

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_coingecko_data { function get_coingecko_data {
# get data from coingecko # get data from coingecko
local f_gecko_currencies="usd eur" local f_gecko_currencies="usd eur"

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_ema { function get_ema {
local f_hist_file="$1" local f_hist_file="$1"

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_indicators_all { function get_indicators_all {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -6,7 +26,8 @@ function get_indicators_all {
local f_histfile f_symbol local f_histfile f_symbol
find asset-histories -maxdepth 1 -name "ECONOMY-*.history.[0-5][5dhwm]*.csv" | sort | while read f_histfile # ECONOMY and MARKETDATA
find asset-histories -maxdepth 1 -name "ECONOMY-*.history.[0-5][5dhwm]*.csv" -o -name "MARKETDATA_*.history.[0-5][5dhwm]*.csv" | sort | while read f_histfile
do do
if [ -s "${f_histfile}.fetching" ] || [ -s "${f_histfile}.indicators-calculating" ] if [ -s "${f_histfile}.fetching" ] || [ -s "${f_histfile}.indicators-calculating" ]
then then
@@ -15,10 +36,10 @@ function get_indicators_all {
fi fi
# do the job # do the job
printf '%(%Y-%m-%d %H:%M:%S)T' >"${f_histfile}.indicators-calculating" printf "$0 %(%Y-%m-%d %H:%M:%S)T" >"${f_histfile}.indicators-calculating"
get_indicators "${f_histfile}" ${f_last_intervals} && printf '%(%Y-%m-%d %H:%M:%S)T' >>"$f_histfile.indicators-calculated" get_indicators "${f_histfile}" ${f_last_intervals} && printf "$0 %(%Y-%m-%d %H:%M:%S)T\n" >>"$f_histfile.indicators-calculated"
# add missing intervals for example from weekends from non-24h-assets like economic data - interval from filename # add missing intervals for example from weekends from non-24h-assets like economic data - interval from filename
f_add_missing_ohlcv_intervals "${f_histfile}" #f_add_missing_ohlcv_intervals "${f_histfile}"
rm -f "${f_histfile}.indicators-calculating" rm -f "${f_histfile}.indicators-calculating"
done done
@@ -42,14 +63,14 @@ function get_indicators_all {
fi fi
# do the job # do the job
printf '%(%Y-%m-%d %H:%M:%S)T' >"${f_histfile}.indicators-calculating" printf "$0 %(%Y-%m-%d %H:%M:%S)T" >"${f_histfile}.indicators-calculating"
get_indicators "${f_histfile}" ${f_last_intervals} && printf '%(%Y-%m-%d %H:%M:%S)T' >>"$f_histfile.indicators-calculated" get_indicators "${f_histfile}" ${f_last_intervals} && printf "$0 %(%Y-%m-%d %H:%M:%S)T\n" >>"$f_histfile.indicators-calculated"
rm -f "${f_histfile}.indicators-calculating" rm -f "${f_histfile}.indicators-calculating"
fi fi
done done
done done
shopt +s nullglob shopt -u nullglob
} }
@@ -62,17 +83,27 @@ function get_indicators {
local f_fill_missing_ohlcv_intervals=$3 local f_fill_missing_ohlcv_intervals=$3
local f_line local f_line
# check if the job is already done
if [ $(wc -l <"${f_histfile}") -gt 801 ]
then
if ! tail +801 "${f_histfile}" | egrep -vq "^....-..-..*,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.\-]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.]+,[0-9\.\-]+,[0-9\.\-]+,[0-9\.\-]+,[a-z]*,[0-9\.\-]+,[0-9\.\-]+"
then
g_echo_note "${f_histfile} seems to be indicator-complete"
return 0
fi
fi
# history # history
local f_columns="date,open,high,low,close,volume,change,ath,ema12,ema26,ema50,ema100,ema200,ema400,ema800,rsi5,rsi14,rsi21,macd,macd_ema9_signal,macd_histogram,macd_histogram_signal,macd_histogram_max,macd_histogram_strength" local f_columns="date,open,high,low,close,volume,change,ath,ema12,ema26,ema50,ema100,ema200,ema400,ema800,rsi5,rsi14,rsi21,macd,macd_ema9_signal,macd_histogram,macd_histogram_signal,macd_histogram_max,macd_histogram_strength"
local f_emas="12 26 50 100 200 400 800" local f_emas="12 26 50 100 200 400 800"
local f_rsis="5 14 21" local f_rsis="5 14 21"
local f_ema f_change f_changed f_line f_valid_data f_ath local f_ema f_change f_changed f_line f_valid_data f_ath f_last_year
local f_columns_space="${f_columns//,/ }" local f_columns_space="${f_columns//,/ }"
g_read_csv "${f_histfile}" "${f_last_intervals}" "$f_columns" g_read_csv "${f_histfile}" "${f_last_intervals}" "$f_columns"
for ((i=0; i<=${#g_csv_array[@]}-1; i++)) for ((i=0; i<=${#g_csv_array[@]}-1; i++))
do do
if [ -z "${v_csv_array_associative[date_${i}]}" ] if [ -z "${v_csv_array_associative[date_${i}]}" ] || [ -z "${v_csv_array_associative[open_${i}]}" ]
then then
g_echo_note "No data $f_histfile:${v_csv_array_associative[date_${i}]}" g_echo_note "No data $f_histfile:${v_csv_array_associative[date_${i}]}"
return 0 return 0
@@ -85,16 +116,42 @@ function get_indicators {
### check for unfilled fields ### check for unfilled fields
f_change="" f_change=""
# check olhc data
if [ -z "${v_csv_array_associative[high_${i}]}" ] && [ -z "${v_csv_array_associative[low_${i}]}" ] && [ -z "${v_csv_array_associative[close_${i}]}" ]
then
g_echo_note "fixing OHLC Data"
# open is close
v_csv_array_associative[close_${i}]=${v_csv_array_associative[open_${i}]}
# open is previous close
[ -n "${v_csv_array_associative[close_${p}]}" ] && v_csv_array_associative[open_${i}]="${v_csv_array_associative[close_${p}]}"
# calc high/low from open/close
if g_num_is_higher_equal ${v_csv_array_associative[open_${i}]} ${v_csv_array_associative[close_${i}]}
then
v_csv_array_associative[high_${i}]=${v_csv_array_associative[open_${i}]}
v_csv_array_associative[low_${i}]=${v_csv_array_associative[close_${i}]}
else
v_csv_array_associative[high_${i}]=${v_csv_array_associative[close_${i}]}
v_csv_array_associative[low_${i}]=${v_csv_array_associative[open_${i}]}
fi
f_change=1
fi
# check for missing percentage change # check for missing percentage change
if [ -z "${v_csv_array_associative[change_${i}]}" ] if [ -z "${v_csv_array_associative[change_${i}]}" ]
then then
#if ! [ $p -lt 0 ] # special for changes watched per year like CPI,...
#then if [[ $f_histfile = "asset-histories/MARKETDATA_US_CONSUMER_PRICE_INDEX_CPI.history.1d.csv" ]] || \
#echo "g_percentage-diff ${v_csv_array_associative[close_${p}]} ${v_csv_array_associative[close_${i}]}" [[ $f_histfile = "asset-histories/MARKETDATA_US_UNEMPLOYMENT_RATE.history.1d.csv" ]]
#g_percentage-diff ${v_csv_array_associative[close_${p}]} ${v_csv_array_associative[close_${i}]} && f_change=1 then
g_percentage-diff ${v_csv_array_associative[open_${i}]} ${v_csv_array_associative[close_${i}]} && f_change=1 if [ $i -ge 12 ]
v_csv_array_associative[change_${i}]=${g_percentage_diff_result} then
#fi f_last_year=$((i-12))
g_percentage-diff ${v_csv_array_associative[open_${f_last_year}]} ${v_csv_array_associative[close_${i}]}
v_csv_array_associative[year_change_${i}]=${g_percentage_diff_result}
fi
fi
g_percentage-diff ${v_csv_array_associative[open_${i}]} ${v_csv_array_associative[close_${i}]} && f_change=1
v_csv_array_associative[change_${i}]=${g_percentage_diff_result}
fi fi
# ath (all-time-high) of present data # ath (all-time-high) of present data
@@ -115,10 +172,20 @@ function get_indicators {
# check for missing EMAs # check for missing EMAs
for f_ema_column in $f_emas for f_ema_column in $f_emas
do do
# check for enough values/lines to calculate EMA # check for enough values/lines to calculate EMA if no previous EMA given
[ $i -ge $f_ema_column ] || continue if [ -z "${v_csv_array_associative[ema${f_ema_column}_${p}]}" ]
then
if ! [ $i -ge $f_ema_column ]
then
#echo "not enough lines $i -ge $f_ema_column"
continue
fi
fi
# calculate EMA # calculate EMA
[ -z "${v_csv_array_associative[ema${f_ema_column}_${i}]}" ] && calc_ema ${f_ema_column} close && f_change=1 if [ -z "${v_csv_array_associative[ema${f_ema_column}_${i}]}" ]
then
calc_ema ${f_ema_column} close && f_change=1
fi
done done
# check for missing RSI # check for missing RSI
@@ -144,6 +211,11 @@ function get_indicators {
# build line # build line
for f_column in $f_columns for f_column in $f_columns
do do
# special for changes watched per year like CPI,...
if [[ $f_column = change ]]
then
[ -n "${v_csv_array_associative[year_change_${i}]}" ] && v_csv_array_associative[change_${i}]=${v_csv_array_associative[year_change_${i}]}
fi
if [ -z "$f_line" ] if [ -z "$f_line" ]
then then
f_line="${v_csv_array_associative[${f_column}_${i}]}" f_line="${v_csv_array_associative[${f_column}_${i}]}"
@@ -158,6 +230,8 @@ function get_indicators {
fi fi
done done
# cleanup large arrays
unset v vr v_csv_array_associative v_csv_array_associative_reverse
} }

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_justtrade_csv_transactions { function get_justtrade_csv_transactions {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -1,9 +1,28 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_levels_all { function get_levels_all {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_levelsfile f_level f_symbol f_symbol_in_array f_price local f_levelsfile f_level f_symbol f_symbol_in_array t_timeframe f_lines $f_relevant_lines
get_symbols_ticker get_symbols_ticker
for f_symbol in "${f_symbols_array_trade[@]}" for f_symbol in "${f_symbols_array_trade[@]}"
@@ -11,56 +30,73 @@ function get_levels_all {
f_symbol=${f_symbol%%:*} f_symbol=${f_symbol%%:*}
f_symbol=${f_symbol//\/} f_symbol=${f_symbol//\/}
# check for data files
for f_levelsfile in "asset-histories/${f_symbol}.history.1d.csv" "asset-histories/${f_symbol}.history.4h.csv" "asset-histories/${f_symbol}.history.15m.csv"
do
[ -s "$f_levelsfile" ] || continue 2
done
# define target file
f_levelsfile="asset-histories/${f_symbol}.history.csv"
printf '%(%Y-%m-%d %H:%M:%S)T' >"${f_levelsfile}.levels-calculating"
g_echo_note "Estimating relevant levels of $f_symbol"
# get current price to reduce the range, save cpu-power and time # get current price to reduce the range, save cpu-power and time
f_symbol_in_array=${f_symbol/ /} f_symbol_in_array=${f_symbol/ /}
f_price=${f_tickers_array[$f_symbol_in_array]} f_price=${f_tickers_array[$f_symbol_in_array]}
# get relevant data max 30000 (+-15000) prices from current price for f_timeframe in 1w 1d #4h 1h 15m
#mapfile -t f_prices < <((cut -d, -f3,4,5 "asset-histories/${f_symbol}.history.1d.csv" "asset-histories/${f_symbol}.history.4h.csv" "asset-histories/${f_symbol}.history.15m.csv" ; echo $f_price) | sed 's/,/\n/g' | sort -rnu | grep -C 15000 "^${f_price}$")
mapfile -t f_prices < <((cut -d, -f5 "asset-histories/${f_symbol}.history.1d.csv" "asset-histories/${f_symbol}.history.4h.csv" "asset-histories/${f_symbol}.history.15m.csv" ; echo $f_price) | sed 's/,/\n/g' | sort -rnu | grep -C 15000 "^${f_price}$")
# calculate levels
get_levels && printf '%(%Y-%m-%d %H:%M:%S)T' >"${f_levelsfile}.levels-calculated"
rm -f "${f_levelsfile}.levels-calculating"
# write new levels file
for f_level in "${f_levels[@]}"
do do
echo $f_level
done >"${f_levelsfile}.levels.new" f_levelsfile="asset-histories/${f_symbol}.history.$f_timeframe.csv"
mv "${f_levelsfile}.levels.new" "${f_levelsfile}.levels" printf '%(%Y-%m-%d %H:%M:%S)T' >"${f_levelsfile}.levels-calculating"
g_echo_note "Estimating relevant levels of $f_levelsfile"
if get_levels "$f_levelsfile"
then
printf '%(%Y-%m-%d %H:%M:%S)T' >"${f_levelsfile}.levels-calculated"
else
continue
fi
echo "${f_levels[@]}" >"${f_levelsfile}.levels.new"
mv "${f_levelsfile}.levels.new" "${f_levelsfile}.levels"
echo "${f_zones[@]}" >"${f_levelsfile}.zones.new"
mv "${f_levelsfile}.zones.new" "${f_levelsfile}.zones"
done
done done
} }
function get_levels { function get_levels {
# estimates the relevant levels from price list from array f_prices and put then in array f_levels # estimates the relevant levels from price list from array f_prices and put then in array f_levels
# - needs array $f_prices with prices sorted from low to high and no duplicates (sort -nru) to analyze # needs levels csv file with prices in ohlcv
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# if there is not enough or no price data
[ -z "${f_prices[100]}" ] && return 1
# reset old levels var # reset old levels var
unset f_levels unset f_levels
unset f_zones
local f_levelsfile=$1
if ! [ -s "$f_levelsfile" ]
then
g_echo_warn "file $f_levelsfile does not exist or is empty"
return 1
fi
# get number of lines in file and use only half of these numbers as relevant price lines to speed up things - later nearest numbers to the current price
f_lines=$(wc -l "${f_levelsfile}" | cut -d" " -f1)
f_relevant_lines=$(( $f_lines * 4 / 5 ))
[ $f_relevant_lines -gt 1000 ] && f_relevant_lines=1000
# read high, low and close, sort and use only relevant lines (near current price)
mapfile -t f_prices < <((cut -d, -f2,3,4,5 "$f_levelsfile" ; echo $f_price) | sed 's/,/\n/g' | sort -rnu | grep -C $f_relevant_lines "^${f_price}$")
# if there is not enough or no price data
if [ -z "${f_prices[100]}" ]
then
g_echo_note "not enough or no price data"
return 1
fi
local f_min_occurrences i j f_level f_level_count f_level_prices f_level_first_price f_baseprice f_threshold_test local f_min_occurrences i j f_level f_level_count f_level_prices f_level_first_price f_baseprice f_threshold_test
# some key points # # some key points
local f_lowest_price=${f_prices[-1]} local f_lowest_price=${f_prices[-1]}
local f_highest_price=${f_prices[1]} local f_highest_price=${f_prices[1]}
local f_number_of_prices=${#f_prices[@]} local f_number_of_prices=${#f_prices[@]}
@@ -69,34 +105,64 @@ function get_levels {
# calc threshold (avarage of percentual price difference) # calc threshold (avarage of percentual price difference)
local f_price_range_percentage=${g_percentage_diff_result//-/} local f_price_range_percentage=${g_percentage_diff_result//-/}
g_calc "$f_price_range_percentage / $f_number_of_prices / 100" || return 1 # g_calc "$f_price_range_percentage / $f_number_of_prices * 0.07" || return 1
local f_threshold=$g_calc_result # local f_threshold=$g_calc_result
# calc threshold in range (1/100 of percentual range) # # calc threshold in range (1/100 of percentual range)
g_calc "$f_price_range_percentage / 100" || return 1 # g_calc "$f_threshold * 11 " || return 1
local f_threshold_in_range=$g_calc_result # local f_threshold_in_range=$g_calc_result
#echo "$f_threshold_in_range - $f_threshold - $f_price_range_percentage"
#return 0
# how much occurencies / same prices have so show up for a defined level - percentage from number of prices # how much occurencies / same prices have so show up for a defined level
#local f_min_occurrences=3 local f_min_occurrences=7
g_calc "$f_number_of_prices / 100 * 0.2" || return 1 if [[ $f_levelsfile =~ \.1w\. ]]
local f_min_occurrences=$g_calc_result then
g_calc "$f_price_range_percentage / $f_number_of_prices * 0.07" || return 1
local f_threshold=$g_calc_result
g_calc "$f_threshold * 11 " || return 1
local f_threshold_in_range=$g_calc_result
#f_threshold="0.0018"
#f_threshold_in_range="0.18"
f_min_occurrences=1
fi
if [[ $f_levelsfile =~ \.1d\. ]]
then
g_calc "$f_price_range_percentage / $f_number_of_prices * 0.33" || return 1
local f_threshold=$g_calc_result
g_calc "$f_threshold * 11 " || return 1
local f_threshold_in_range=$g_calc_result
#f_threshold="0.009"
#f_threshold_in_range="0.09"
f_min_occurrences=7
fi
if [[ $f_levelsfile =~ \.1h\.|\.4h\. ]]
then
#f_threshold="0.03"
#f_threshold_in_range="0.04"
f_min_occurrences=9
fi
if [[ $f_levelsfile =~ \.15m\.|\.5m\. ]]
then
#f_threshold="0.01"
#f_threshold_in_range="0.03"
f_min_occurrences=11
fi
echo "f_threshold_in_range $f_threshold_in_range - f_threshold $f_threshold - f_price_range_percentage $f_price_range_percentage - f_min_occurrences $f_min_occurrences - f_number_of_prices $f_number_of_prices"
# Loop through the f_prices and compare each number with the next # Loop through the f_prices and compare each number with the next
for ((i=0; i<${#f_prices[@]}-1; i++)) for ((i=0; i<${#f_prices[@]}-1; i++))
do do
#echo "$i of ${#f_prices[@]}" #echo "$i of ${#f_prices[@]}"
# pair this and next elemtn # pair this and next element
j=$((i+1)) j=$((i+1))
f_threshold_test=$f_threshold f_threshold_test=$f_threshold
f_baseprice=${f_prices[i]} f_baseprice=${f_prices[i]}
# if we are in a level use first price of level # if we are in a level use current avarage price of level
if [ -n "$f_level_count" ] if [ -n "$f_level_count" ]
then then
#g_calc "($f_level_prices)/$f_level_count"
#f_baseprice=$g_calc_result
f_baseprice=$f_level_first_price f_baseprice=$f_level_first_price
f_threshold_test=$f_threshold_in_range f_threshold_test=$f_threshold_in_range
fi fi
@@ -108,13 +174,17 @@ function get_levels {
if [ -z "$f_level_count" ] if [ -z "$f_level_count" ]
then then
# new level # new level
unset f_zone
f_level_count=2 f_level_count=2
f_level_prices="${f_prices[i]}+${f_prices[j]}" f_level_prices="${f_prices[i]}+${f_prices[j]}"
f_level_first_price=${f_prices[i]} f_level_first_price=${f_prices[i]}
f_zone+=("${f_prices[i]}")
f_zone+=("${f_prices[j]}")
else else
# add values to level # add values to level
f_level_count=$((f_level_count+1)) f_level_count=$((f_level_count+1))
f_level_prices="$f_level_prices+${f_prices[j]}" f_level_prices="$f_level_prices+${f_prices[j]}"
f_zone+=("${f_prices[j]}")
fi fi
#echo "level ($f_level_count): $f_level_prices" #echo "level ($f_level_count): $f_level_prices"
else else
@@ -124,9 +194,11 @@ function get_levels {
#if [ "$f_level_count" -ge "$f_min_occurrences" ] #if [ "$f_level_count" -ge "$f_min_occurrences" ]
if g_num_is_higher_equal $f_level_count $f_min_occurrences if g_num_is_higher_equal $f_level_count $f_min_occurrences
then then
g_calc "($f_level_prices)/$f_level_count" g_median ${f_zone[@]}
f_levels+=("$g_calc_result") f_levels+=("$g_median_result")
g_echo_note "adding significant level at $g_calc_result after reaching $f_level_count times" f_zones+=("${f_zone[0]},${f_zone[-1]},$f_level_count")
g_echo_note "adding significant zone at level $g_median_result after reaching $f_level_count times - Zone: ${f_zone[0]} - ${f_zone[-1]}"
fi fi
f_level_prices="" f_level_prices=""
f_level_count="" f_level_count=""

View File

@@ -1,87 +1,162 @@
function get_marketdata { #!/bin/bash
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" # Copyright (c) 2022-2024 olli
#
get_marketdata_from_url https://www.investing.com/economic-calendar/unemployment-rate-300/ US-UNEMPLOYMENT-INDEX # This file is part of dabo (crypto bot).
get_marketdata_from_url https://www.investing.com/economic-calendar/cpi-733 US-CONSUMER-PRICE-INDEX #
get_marketdata_from_url https://www.investing.com/indices/fed-funds-composite-interest-rate-opinion US-FED-FEDERAL-FUNDS-RATE-INVERTED-INDEX # dabo is free software: you can redistribute it and/or modify
get_marketdata_from_url '"https://fapi.binance.com/futures/data/globalLongShortAccountRatio?symbol=BTCUSDT&period=5m" | jq -r .[].longShortRatio | tail -n1' BINANCE-BTC-GlobalLongShortAccountRatio # it under the terms of the GNU General Public License as published by
get_marketdata_from_url '"https://fapi.binance.com/futures/data/takerlongshortRatio?symbol=BTCUSDT&period=5m" | jq -r .[].buySellRatio | tail -n1' BINANCE-BTC-TakerLongShortRatio # the Free Software Foundation, either version 3 of the License, or
get_marketdata_from_url '"https://fapi.binance.com/futures/data/openInterestHist?symbol=BTCUSDT&period=5m" | jq -r .[].sumOpenInterest | tail -n1' BINANCE-BTC-OpenInterest # (at your option) any later version.
get_marketdata_from_url '"https://api.alternative.me/fng/?limit=1&format=json" | jq -r .data[].value' CRYPTO_FEAR_AND_GREED-INDEX #
# clear old stuff # dabo is distributed in the hope that it will be useful,
find asset-histories/*INDEX* -type f -mtime +6 -delete # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_marketdata_all {
local f_interval=$1
# daily garketdata jobs
if [[ $f_interval = 1d ]]
then
# FEAR_AND_GREED_ALTERNATIVEME
get_marketdata FEAR_AND_GREED_ALTERNATIVEME 'https://api.alternative.me/fng/?limit=0&format=json' '.data[] | (.timestamp | tonumber | strftime("%Y-%m-%d")) + "," + .value + ",,,,0"' "" 1d
# FEAR AND GREED COINMARKETCAP
get_marketdata FEAR_AND_GREED_COINMARKETCAP "https://api.coinmarketcap.com/data-api/v3/fear-greed/chart?start=1&end=$(date +%s)" '.data.dataList[] | (.timestamp | tonumber | strftime("%Y-%m-%d")) + "," + (.score|tostring) + ",,,,0"'
# FEAR_AND_GREED_CNN
get_marketdata FEAR_AND_GREED_CNN 'https://production.dataviz.cnn.io/index/fearandgreed/graphdata' '.fear_and_greed_historical.data[] | (.x/1000 | strftime("%Y-%m-%d")) + "," + (.y|tostring) + ",,,,0"' "" 1d
# Altcoin-Saison-Index COINMARKETCAP Top 100 Altcoins
get_marketdata ALTCOIN_SEASON_INDEX_COINMARKETCAP "https://api.coinmarketcap.com/data-api/v3/altcoin-season/chart?start=1&end=$(date +%s)" '.data.points[:-1][] | (.timestamp | tonumber | strftime("%Y-%m-%d")) + "," + (.altcoinIndex|tostring) + ",,,,0"' "" 1d
# monthly US consumer price index CPI data
get_marketdata US_CONSUMER_PRICE_INDEX_CPI "https://api.bls.gov/publicAPI/v2/timeseries/data/CUUR0000SA0?startyear=$(date -d 'now -8 years' '+%Y')&endyear=$(date '+%Y')" '.Results.series[0].data[] | .year + "-" + (.period | gsub("M"; "")) + "-01," + .value + ",,,,0"' "" 1d
# monthly US unemployment rate
get_marketdata US_UNEMPLOYMENT_RATE "https://api.bls.gov/publicAPI/v2/timeseries/data/LNU03000000?startyear=$(date -d 'now -8 years' '+%Y')&endyear=$(date '+%Y')" '.Results.series[0].data[] | .year + "-" + (.period | gsub("M"; "")) + "-01," + .value + ",,,,0"' "" 1d
# US FED funds rate
get_marketdata US_FED_FUNDS_RATE 'https://fred.stlouisfed.org/graph/fredgraph.csv?id=DFF' "" "" 1d
fi
# Binance Long Short Ration Account / Taker and Open Interest per symbol
get_symbols_ticker
local f_symbol f_asset f_time
for f_symbol in BTC/$CURRENCY "${f_symbols_array_trade[@]}"
do
f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
# week not available
[[ $f_interval = 1w ]] && continue
f_time='%Y-%m-%d %H:%M:00'
[[ $f_interval = 1d ]] && f_time='%Y-%m-%d'
# BINANCE_LONG_SHORT_RATIO_ACCOUNT per symbol
get_marketdata BINANCE_LONG_SHORT_RATIO_ACCOUNT_$f_asset "https://fapi.binance.com/futures/data/globalLongShortAccountRatio?symbol=${f_asset}&limit=500&period=${f_interval}" ".[] | (.timestamp/1000 | strftime(\"${f_time}\")) + \",\" + .longShortRatio + \",,,,0\"" "" ${f_interval}
# BINANCE_LONG_SHORT_RATIO_Taker per symbol
get_marketdata BINANCE_LONG_SHORT_RATIO_TAKER_$f_asset "https://fapi.binance.com/futures/data/takerlongshortRatio?symbol=${f_asset}&limit=500&period=${f_interval}" ".[] | (.timestamp/1000 | strftime(\"${f_time}\")) + \",\" + .buySellRatio + \",,,,0\"" "" ${f_interval}
# BINANCE_OPEN_INTEREST per symbol
get_marketdata BINANCE_OPEN_INTEREST_$f_asset "https://fapi.binance.com/futures/data/openInterestHist?symbol=${f_asset}&limit=500&period=${f_interval}" ".[] | (.timestamp/1000 | strftime(\"${f_time}\")) + \",\" + .sumOpenInterest + \",,,,0\"" "" ${f_interval}
done
} }
function get_marketdata_from_url {
function get_marketdata {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_name=$1
local f_wget=$2
local f_jq=$3
local f_other=$4
local f_timeframe=$5
[ -z "$f_timeframe" ] && f_timeframe=1d
local f_histfile="asset-histories/MARKETDATA_${f_name}.history.${f_timeframe}.csv"
local f_dataline f_failed
local f_url="$1" # download
local f_name="$2" g_wget -O "${f_histfile}.wget.tmp" $f_wget 2>"${f_histfile}.err.tmp" || f_failed=wget
[ -s "${f_histfile}.wget.tmp" ] || f_failed=wget
## get data for analysis if [ -n "$f_failed" ]
if find asset-histories/${f_name}.history.csv -mmin -${INTERVAL_MIN} 2>/dev/null | grep -q "asset-histories/${f_name}.history.csv"
then then
g_echo_note "asset-histories/${f_name}.history.csv already downloaded in the last ${INTERVAL_MIN} minutes" echo "g_wget -O \"${f_histfile}.wget.tmp\" $f_wget 2>\"${f_histfile}.err\"" >"${f_histfile}.err"
f_get_marketdata_price=$(cat MARKET_DATA_CMD_OUT-${f_name})
return 0
fi fi
# check source platform for parsing parameters, prepare and run wget command # jd
>MARKET_DATA_CMD if [ -z "$f_failed" ] && [ -n "$f_jq" ]
if echo "${f_url}" | grep -q "boerse.de"
then then
echo "wget ${g_wget_opts} -q -O - ${f_url} | egrep 'itemprop=\"price\" content=\"[0-9]+\.[0-9]+\"' | sed s'#\"#\n#g' | egrep '^[0-9]+\.[0-9]+'" >MARKET_DATA_CMD if ! jq -r "$f_jq" "${f_histfile}.wget.tmp" >"${f_histfile}.tmp" 2>"${f_histfile}.err.tmp"
elif echo "${f_url}" | egrep -q "investing.com.+economic-calendar"
then
echo "wget ${g_wget_opts} -q -O - ${f_url} | egrep 'Actual.+Forecast.+Previous' | cut -d'>' -f7,11 | cut -d'<' -f1,2 | sed 's#,##g' | sed 's/\%//g' | sed 's#</div>#,#' | grep '[0-9]' | cut -d, -f1" >MARKET_DATA_CMD
elif echo "${f_url}" | egrep -q "investing.com.+indices"
then
echo "wget ${g_wget_opts} -q -O - ${f_url} | sed 's#</div>#\n#g' | grep 'text-5xl.*font-bold.*md:text-' | sed 's#^.*>##; s#,##g' | grep '[0-9]'" >MARKET_DATA_CMD
elif echo "${f_url}" | egrep -q '^"https://'
then
echo "wget -q -O - ${g_wget_opts} ${f_url}" >MARKET_DATA_CMD
else
# default to Yahoo Finace Symbols via API
echo "wget ${g_wget_opts} -q -O - https://query1.finance.yahoo.com/v8/finance/chart/${f_url} | jq -r '.[].result[].meta.regularMarketPrice'" >MARKET_DATA_CMD
fi
g_runcmd g_retrycmd sh MARKET_DATA_CMD >MARKET_DATA_CMD_OUT-${f_name}.tmp 2>MARKET_DATA_CMD_OUT-${f_name}.tmp.err
# check output
local f_get_marketdata_price_tmp=$(cat MARKET_DATA_CMD_OUT-${f_name}.tmp)
if g_num_valid_number ${f_get_marketdata_price_tmp}
then
if egrep -q "^0\.00" MARKET_DATA_CMD_OUT-${f_name}.tmp
then then
g_echo_note "Ignoring ${f_name} $(tail -n 10 MARKET_DATA_CMD_OUT-${f_name}.tmp) - maybe out of business day" echo jq -r "$f_jq" "${f_histfile}.wget.tmp" >"${f_histfile}.err"
f_failed=jq
else else
g_echo_note "${f_name}: ${f_get_marketdata_price_tmp}" mv "${f_histfile}.tmp" "${f_histfile}.wget.tmp"
mv MARKET_DATA_CMD_OUT-${f_name}.tmp MARKET_DATA_CMD_OUT-${f_name} fi
fi
# other/additional processing
if [ -z "$f_failed" ] && [ -n "$f_other" ]
then
if ! cat "${f_histfile}.wget.tmp" | eval $f_other
then
echo "cat \"${f_histfile}.wget.tmp\" | $f_other" >"${f_histfile}.err"
f_failed=other
fi fi
else else
g_echo_warn "MARKET_DATA_CMD_OUT-${f_name}.tmp has wrong Syntax. - Not updating ${f_name} Index. mv "${f_histfile}.wget.tmp" "${f_histfile}.tmp"
CMD:
$(tail -n 10 MARKET_DATA_CMD)
Output:
$(tail -n 10 MARKET_DATA_CMD_OUT-${f_name}.tmp | cat -t)
Error:
$(tail -n 10 MARKET_DATA_CMD_OUT-${f_name}.tmp.err | cat -t)"
fi fi
if ! [ -e "MARKET_DATA_CMD_OUT-${f_name}" ]
# cleanup
rm -f "${f_histfile}.wget.tmp" "${f_histfile}.err.tmp"
# error if no csvfile available
if [ -n "$f_failed" ] || ! [ -s "${f_histfile}.tmp" ]
then then
local f_old_value=$(tail -n 1 asset-histories/${f_name}.history.csv | cut -d, -f2) cat "${f_histfile}.err.tmp" >>"${f_histfile}.err"
if echo ${f_old_value} | egrep -q "^[0-9]*\.[0-9]+" cat "${f_histfile}.wget.tmp" >>"${f_histfile}.err"
cat "${f_histfile}.err" 1>&2
mkdir -p FAILED_MARKETDATA
mv "${f_histfile}.err" "FAILED_MARKETDATA/MARKETDATA-${f_name}" 2>/dev/null
return 1
fi
# on first download
if ! [ -s "${f_histfile}" ]
then
grep ^[2-9] "${f_histfile}.tmp" | sort -k1,1 -t, -u >"${f_histfile}"
else
# merge data
egrep -h ^[0-9][0-9][0-9][0-9]-[0-9][0-9] "${f_histfile}" "${f_histfile}.tmp" | sort -k1,1 -t, -u >"${g_tmp}/${FUNCNAME}.tmp"
# if there is new dataline add it
if ! cmp -s "${g_tmp}/${FUNCNAME}.tmp" "${f_histfile}"
then then
echo ${f_old_value} >MARKET_DATA_CMD_OUT-${f_name} cat "${g_tmp}/${FUNCNAME}.tmp" >"${f_histfile}"
else
echo 0 >MARKET_DATA_CMD_OUT-${f_name}
fi fi
fi fi
f_get_marketdata_price=$(cat MARKET_DATA_CMD_OUT-${f_name}) rm "${f_histfile}.tmp"
echo "${f_timestamp},${f_get_marketdata_price}" >>asset-histories/${f_name}.history.csv
# calc indicators and if 1d then generate 1w histfile
if [[ $f_interval = 1d ]]
then
get_indicators "${f_histfile}" 51
convert_ohlcv_1d_to_1w "${f_histfile}" "${f_histfile/.1d./.1w.}"
get_indicators "${f_histfile/.1d./.1w.}" 51
else
get_indicators "${f_histfile}" 51
fi
} }

View File

@@ -0,0 +1,167 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_marketdata_coinmarketcap {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_item="$1"
local f_name="$2"
local f_timeframe="$3"
local f_targetcsvtmp="${g_tmp}/${f_name}.history-coinmarketcap.csv"
local f_targetjsontmp="${g_tmp}/${f_name}.history-coinmarketcap.json"
rm -f "$f_targetcsvtmp" "$f_targetjsontmp"
[ -z "$f_timeframe" ] && f_timeframe="1d"
local f_targetcsv="asset-histories/${f_name}.history-coinmarketcap.${f_timeframe}.csv"
[ "$f_timeframe" = "1w" ] && f_timeframe="7d"
f_histfile_coinmarketcap="$f_targetcsv"
# use EUR EURC stable coin fo EUR
f_item=${f_item//EUR-/EURC-}
# renamed cryptos
f_item=${f_item//RNDR-/RENDER-}
# remove -
f_item=${f_item//-//}
# USDT to USD
f_item=${f_item//USDT/USD}
# BUSD to USD
f_item=${f_item//BUSD/USD}
if ! [[ $f_item =~ /USD ]]
then
g_echo_error "${FUNCNAME} $@: Only USD supported"
return 1
fi
# transform CCXT symbols to CoinmarketCap IDs
if [[ $f_item =~ / ]]
then
# remove /*
f_item=${f_item///*/}
fi
local f_id
# get id -> If multiple take the one with the largest marketcap
f_id=$(egrep "^${f_item},[1-9]" COINMARKETCAPIDS COINMARKETCAPIDS.tmp 2>/dev/null | sort -n -t, -k4 | tail -n1 | cut -d, -f2)
[[ $f_item = EURC ]] && f_id=20641
if [ -z "$f_id" ]
then
g_echo_error "${FUNCNAME} $@: No CoinMarketCap ID for $f_item"
return 1
fi
# end if already failed the last 5 minutes
if [ -f "FAILED_COINMARKETCAP/${f_name}_HISTORIC_DOWNLOAD" ]
then
find "FAILED_COINMARKETCAP/${f_name}_HISTORIC_DOWNLOAD" -mmin +5 -delete
if [ -f "FAILED_COINMARKETCAP/${f_name}_HISTORIC_DOWNLOAD" ]
then
return 1
fi
fi
# end if already exists and modified under given time
if [ -s "${f_targetcsv}" ] && find "${f_targetcsv}" -mmin -2 | grep -q "${f_targetcsv}"
then
return 0
fi
# cleanup
rm -f "$f_targetcsvtmp" "${f_targetcsvtmp}".err ${f_targetjsontmp} "${f_targetjsontmp}".err
if [ "$f_timeframe" = "1d" ] || [ "$f_timeframe" = "7d" ]
then
# Download data from coinmarketcap
g_wget -O "${f_targetjsontmp}" "https://api.coinmarketcap.com/data-api/v3.1/cryptocurrency/historical?id=${f_id}&interval=${f_timeframe}" 2>"${f_targetjsontmp}".err
jq -r '.data.quotes[] | .quote.timestamp[0:10] + "," + (.quote.open|tostring) + "," + (.quote.high|tostring) + "," + (.quote.low|tostring) + "," + (.quote.close|tostring) + "," + (.quote.volume|tostring)' "${f_targetjsontmp}" | egrep -v ',0$|,$' >"${f_targetcsvtmp}" 2>"${f_targetjsontmp}".err
else
g_echo_error "${FUNCNAME} $@: Timeframe $f_timeframe in CoinMarketCap not supported."
return 1
fi
# error if no csvfile available
if ! [ -s "${f_targetcsvtmp}" ]
then
mkdir -p FAILED_COINMARKETCAP
cat "${f_targetcsvtmp}.err" "${f_targetjsontmp}.err" > "FAILED_COINMARKETCAP/${f_name}_HISTORIC_DOWNLOAD" 2>/dev/null
f_get_marketdata_coinmarketcap_error=$(cat "${f_targetcsvtmp}.err" "${f_targetjsontmp}.err" 2>/dev/null)
return 1
fi
# put the csvs together
if [ -s "${f_targetcsv}" ] && [ -s "${f_targetcsvtmp}" ]
then
egrep -h "^[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*,[0-9]" "${f_targetcsv}" "${f_targetcsvtmp}" | sort -k1,2 -t, -u | sort -k1,1 -t, -u >"${f_targetcsv}.tmp"
mv "${f_targetcsv}.tmp" "${f_targetcsv}"
else
egrep -h "^[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*,[0-9]" "${f_targetcsvtmp}" | sort -k1,2 -t, -u >"$f_targetcsv"
fi
# change exponential notation to normal notation
g_num_exponential2normal_file "${f_targetcsv}"
}
function get_marketdata_coinmarketcap_ids {
# get symbol ids from coinmarketcap
local f_target=COINMARKETCAPIDS
local f_target_tmp="${f_target}.tmp"
local f_target_loop=$f_target_tmp
local f_latest_date
local f_latest_date_seconds
local f_latest_date_seconds_now=$(date -d "now - 8 days" +%s)
# write direct to target if not exists or empty
[ -s "$f_target" ] || f_target_loop=$f_target
for f_id in $(seq 1 50000)
do
#echo "checking COINMARKETCAPID $f_id - Writing to $f_target_loop" 1>&2
sleep 0.3
# download
curl -s --request GET --url "https://api.coinmarketcap.com/data-api/v3.1/cryptocurrency/historical?id=${f_id}&interval=1d" >"$g_tmp/get_marketdata_coinmarketcap_ids.json"
# check latest date
f_latest_date=$(jq -r '.data.quotes[] | .quote.timestamp[0:10]' "$g_tmp/get_marketdata_coinmarketcap_ids.json" | tail -n1)
[ -z "$f_latest_date" ] && continue
# check for up-to-date data
f_latest_date_seconds=$(date -d "$f_latest_date" +%s)
if [ $f_latest_date_seconds_now -lt $f_latest_date_seconds ]
then
jq -r '.data | .symbol + "," + (.id|tostring) + "," + .name + "," + (.quotes[].quote|.marketCap|tostring)' "$g_tmp/get_marketdata_coinmarketcap_ids.json" | grep -vi ",0e-" | head -n 1
fi
done | egrep --line-buffered '^.+,[0-9]*,' >"$f_target_loop"
if [ -s "$f_target_tmp" ]
then
cp -p "$f_target" "${f_target}.$(date +%F)"
mv "$f_target_tmp" "$f_target"
fi
}

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_marketdata_yahoo { function get_marketdata_yahoo {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -12,6 +32,7 @@ function get_marketdata_yahoo {
[ -z "$f_timeframe" ] && f_timeframe="1d" [ -z "$f_timeframe" ] && f_timeframe="1d"
local f_targetcsv="asset-histories/${f_name}.history-yahoo.${f_timeframe}.csv" local f_targetcsv="asset-histories/${f_name}.history-yahoo.${f_timeframe}.csv"
local f_targetbotcsv="asset-histories/${f_name}.history.${f_timeframe}.csv"
[ "$f_timeframe" = "1w" ] && f_timeframe="1wk" [ "$f_timeframe" = "1w" ] && f_timeframe="1wk"
f_histfile_yahoo="$f_targetcsv" f_histfile_yahoo="$f_targetcsv"
@@ -45,23 +66,6 @@ function get_marketdata_yahoo {
[[ $f_item = "USD-EUR" ]] && f_item="USDEUR=X" [[ $f_item = "USD-EUR" ]] && f_item="USDEUR=X"
[[ $f_item = "EUR-USD" ]] && f_item="EURUSD=X" [[ $f_item = "EUR-USD" ]] && f_item="EURUSD=X"
# special names of some coins/currencies of yahoo finance
[[ $f_item = "ARB-USD" ]] && f_item="ARB11841-USD"
[[ $f_item = "DUEL-USD" ]] && f_item="DUEL28868-USD"
[[ $f_item = "GMX-USD" ]] && f_item="GMX11857-USD"
[[ $f_item = "MEW-USD" ]] && f_item="MEW30126-USD"
[[ $f_item = "TAO-USD" ]] && f_item="TAO22974-USD"
[[ $f_item = "UNI-USD" ]] && f_item="UNI7083-USD"
[[ $f_item = "SUI-USD" ]] && f_item="SUI20947-USD"
[[ $f_item = "BLAZE-USD" ]] && f_item="BLAZE30179-USD"
[[ $f_item = "BEER-USD" ]] && f_item="BEER31337-USD"
[[ $f_item = "TAI-USD" ]] && f_item="TAI20605-USD"
[[ $f_item = "DEFI-USD" ]] && f_item="DEFI29200-USD"
[[ $f_item = "TON-USD" ]] && f_item="TON11419-USD"
[[ $f_item = "BRETT-USD" ]] && f_item="BRETT29743-USD"
[[ $f_item = "ADS-USD" ]] && f_item="%24ADS-USD"
[[ $f_item = "PT-USD" ]] && f_item="PT28582-USD"
# end if already failed the last 5 minutes # end if already failed the last 5 minutes
if [ -f "FAILED_YAHOO/${f_name}_HISTORIC_DOWNLOAD" ] if [ -f "FAILED_YAHOO/${f_name}_HISTORIC_DOWNLOAD" ]
then then
@@ -83,49 +87,76 @@ function get_marketdata_yahoo {
# cleanup # cleanup
rm -f "$f_targetcsvtmp" "${f_targetcsvtmp}".err ${f_targetjsontmp} "${f_targetjsontmp}".err rm -f "$f_targetcsvtmp" "${f_targetcsvtmp}".err ${f_targetjsontmp} "${f_targetjsontmp}".err
if [ "$f_timeframe" = "1d" ] || [ "$f_timeframe" = "1wk" ] || [ "$f_timeframe" = "1mo" ] local f_from
then [ "$f_timeframe" = "5m" ] && f_from=$(date -d "now -86000 minutes" +%s)
# Download historical data from yahoo [ "$f_timeframe" = "15m" ] && f_from=$(date -d "now -86000 minutes" +%s)
g_wget -O "${f_targetcsvtmp}" "https://query1.finance.yahoo.com/v7/finance/download/${f_item}?period1=0&period2=${f_sec}&interval=${f_timeframe}&events=history" 2>"${f_targetcsvtmp}".err [ "$f_timeframe" = "1h" ] && f_from=$(date -d "now -17510 hour" +%s)
else [ "$f_timeframe" = "1d" ] && f_from=1
# Download data from yahoo [ "$f_timeframe" = "1wk" ] && f_from=1
g_wget -O "${f_targetjsontmp}" "https://query1.finance.yahoo.com/v7/finance/chart/${f_item}?interval=${f_timeframe}&period2=${f_sec}" 2>"${f_targetjsontmp}".err [ "$f_timeframe" = "1mo" ] && f_from=1
jq -r '.chart.result[0] as $result | range(0; $result.timestamp | length) | [$result.timestamp[.], $result.indicators.quote[0].open[.], $result.indicators.quote[0].high[.], $result.indicators.quote[0].low[.], $result.indicators.quote[0].close[.], $result.indicators.quote[0].volume[.]] | @csv' "${f_targetjsontmp}" >"${f_targetcsvtmp}.unixtime" 2>"${f_targetjsontmp}".err
# change unix time to human readable and fill unfilled lines, ignore lines not with 00 secolds (last line) # Download data from yahoo
local date_time open high low close lastopen lasthigh lastlow lastclose volume g_wget -O "${f_targetjsontmp}" "https://query1.finance.yahoo.com/v8/finance/chart/${f_item}?interval=${f_timeframe}&period1=${f_from}&period2=${f_sec}" 2>"${f_targetjsontmp}".err
while IFS=, read -r timestamp open high low close volume; do
date_time=$(printf "%(%Y-%m-%d %H:%M:%S)T" $timestamp) # Create csv from json
[ -z "$open" ] && open=$lastopen jq -r '.chart.result[0] as $result | range(0; $result.timestamp | length) | [$result.timestamp[.], $result.indicators.quote[0].open[.], $result.indicators.quote[0].high[.], $result.indicators.quote[0].low[.], $result.indicators.quote[0].close[.], $result.indicators.quote[0].volume[.]] | @csv' "${f_targetjsontmp}" >"${f_targetcsvtmp}.unixtime" 2>"${f_targetjsontmp}".err
[ -z "$high" ] && high=$lasthigh
[ -z "$low" ] && low=$lastlow # remove last/open timeframe (use only closed)
[ -z "$close" ] && close=$lastclose sed -i '$d' "${f_targetcsvtmp}.unixtime"
[ -z "$volume" ] && volume=0
lastopen=$open # change unix time to human readable and fill unfilled lines, ignore lines not with 00 secolds (last line)
lasthigh=$high local date_time open high low close lastopen lasthigh lastlow lastclose volume
lastlow=$low while IFS=, read -r timestamp open high low close volume
lastclose=$close do
echo "$date_time,$open,$high,$low,$close,$volume" if [ "$f_timeframe" = "1d" ] || [ "$f_timeframe" = "1mo" ]
done < "${f_targetcsvtmp}.unixtime" | grep ":00," >${f_targetcsvtmp} then
fi printf -v date_time "%(%Y-%m-%d)T" $timestamp
elif [ "$f_timeframe" = "1wk" ]
then
# on week 1 day back like crypto assets
date_time=$(date -d "yesterday $(date -d "@$timestamp" "+%Y-%m-%d")" "+%Y-%m-%d")
else
printf -v date_time "%(%Y-%m-%d %H:%M:%S)T" $timestamp
fi
[ -z "$open" ] && open=$lastopen
[ -z "$high" ] && high=$lasthigh
[ -z "$low" ] && low=$lastlow
[ -z "$close" ] && close=$lastclose
[ -z "$volume" ] && volume=0
lastopen=$open
lasthigh=$high
lastlow=$low
lastclose=$close
echo "$date_time,$open,$high,$low,$close,$volume"
done < "${f_targetcsvtmp}.unixtime" >${f_targetcsvtmp}
# error if no csvfile available # error if no csvfile available
if ! [ -s "${f_targetcsvtmp}" ] if ! [ -s "${f_targetcsvtmp}" ]
then then
mkdir -p FAILED_YAHOO mkdir -p FAILED_YAHOO
cat "${f_targetcsvtmp}.err" "${f_targetjsontmp}.err" > "FAILED_YAHOO/${f_name}_HISTORIC_DOWNLOAD" 2>&1 cat "${f_targetcsvtmp}.err" "${f_targetjsontmp}.err" > "FAILED_YAHOO/${f_name}_HISTORIC_DOWNLOAD" 2>/dev/null
f_get_marketdata_yahoo_error=$(cat "${f_targetcsvtmp}.err" "${f_targetjsontmp}.err" 2>/dev/null) f_get_marketdata_yahoo_error=$(cat "${f_targetcsvtmp}.err" "${f_targetjsontmp}.err" 2>/dev/null)
return 1 return 1
fi fi
# put the csvs together # put the csvs together
# history-yahoo file
if [ -s "${f_targetcsv}" ] && [ -s "${f_targetcsvtmp}" ] if [ -s "${f_targetcsv}" ] && [ -s "${f_targetcsvtmp}" ]
then then
egrep -h "^[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*,[0-9]" "${f_targetcsvtmp}" "${f_targetcsv}" | sort -k1,2 -t, -u >"${f_targetcsv}.tmp" egrep -h "^[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*,[0-9]" "${f_targetcsv}" "${f_targetcsvtmp}" | sort -k1,2 -t, -u | sort -k1,1 -t, -u >"${f_targetcsv}.tmp"
mv "${f_targetcsv}.tmp" "${f_targetcsv}" mv "${f_targetcsv}.tmp" "${f_targetcsv}"
else else
egrep -h "^[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*,[0-9]" "${f_targetcsvtmp}" | sort -k1,2 -t, -u >"$f_targetcsv" egrep -h "^[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*,[0-9]" "${f_targetcsvtmp}" | sort -k1,2 -t, -u >"$f_targetcsv"
fi fi
} # bots history file
if [ -s "${f_targetbotcsv}" ] && [ -s "${f_targetcsv}" ]
then
egrep -h "^[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*,[0-9]" "${f_targetbotcsv}" "${f_targetcsv}" | sort -k1,2 -t, -u | sort -k1,1 -t, -u >"${f_targetbotcsv}.tmp"
mv "${f_targetbotcsv}.tmp" "${f_targetbotcsv}"
else
egrep -h "^[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*,[0-9]" "${f_targetcsv}" | sort -k1,2 -t, -u >"$f_targetbotcsv"
fi
}

View File

@@ -1,31 +1,52 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_ohlcv-candles { function get_ohlcv-candles {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_histfile f_symbol f_timeframe f_1h_histfile local f_histfile f_symbol f_timeframe f_1h_histfile f_1d_histfile
local f_timeframes="1w 1d 4h 1h 15m 5m" local f_timeframes="1w 1d 4h 1h 15m 5m"
[ -n $1 ] && f_timeframes=$1 [ -n $1 ] && f_timeframes=$1
# fetch economy candles from yahoo finance # fetch economy candles from yahoo finance
local f_eco_assets="DXY DOWJONES SP500 NASDAQ MSCIEAFE 10YRTREASURY OIL GOLD MSCIWORLD OILGAS KRE EUR-USD"
local f_eco_asset local f_eco_asset
for f_eco_asset in $f_eco_assets for f_eco_asset in $ECO_ASSETS
do do
for f_timeframe in $f_timeframes for f_timeframe in $f_timeframes
do do
g_echo_note "Fetching/Refreshing $f_eco_asset $f_timeframe" g_echo_note "Fetching/Refreshing $f_eco_asset $f_timeframe"
f_histfile="asset-histories/ECONOMY-${f_eco_asset}.history.${f_timeframe}.csv" f_histfile="asset-histories/ECONOMY-${f_eco_asset}.history.${f_timeframe}.csv"
# 4h timefrage does not exist on yahoo finance so calc from 1h # 4h timeframe does not exist on yahoo finance so calc from 1h
if [ "$f_timeframe" = "4h" ] if [ "$f_timeframe" = "4h" ]
then then
f_1h_histfile="asset-histories/ECONOMY-${f_eco_asset}.history.1h.csv" f_1h_histfile="asset-histories/ECONOMY-${f_eco_asset}.history.1h.csv"
[ -s "$f_1h_histfile" ] && convert_ohlcv_1h_to_4h "$f_1h_histfile" "$f_histfile" [ -s "$f_1h_histfile" ] && convert_ohlcv_1h_to_4h "$f_1h_histfile" "$f_histfile"
f_add_missing_ohlcv_intervals "$f_histfile" 4h
else else
get_ohlcv-candle "${f_eco_asset}" ${f_timeframe} "${f_histfile}" "ECONOMY-${f_eco_asset}" #get_ohlcv-candle "${f_eco_asset}" ${f_timeframe} "${f_histfile}" "ECONOMY-${f_eco_asset}"
get_marketdata_yahoo ${f_eco_asset} ECONOMY-${f_eco_asset} ${f_timeframe}
fi fi
# refresh latest indicators # refresh latest indicators
[ -s "${f_histfile}" ] && get_indicators "${f_histfile}" 900 [ -s "${f_histfile}" ] && get_indicators "${f_histfile}" 51
done done
done done
@@ -35,7 +56,7 @@ function get_ohlcv-candles {
do do
# fetch only single symbols (for debugging) # fetch only single symbols (for debugging)
#[ "$f_symbol" = "BTC/USDT:USDT" ] || continue #[ "$f_symbol" = "BTC/USDT:USDT" ] || continue
echo "=== Fetching/Refreshing $f_symbol ===" g_echo_note "Fetching/Refreshing $f_symbol $f_timeframe"
for f_timeframe in $f_timeframes for f_timeframe in $f_timeframes
do do
f_asset="${f_symbol//:*}" f_asset="${f_symbol//:*}"
@@ -54,7 +75,7 @@ function get_ohlcv-candles {
get_ohlcv-candle "$f_symbol" $f_timeframe "${f_histfile}" && printf '%(%Y-%m-%d %H:%M:%S)T' >>"$f_histfile.fetched" get_ohlcv-candle "$f_symbol" $f_timeframe "${f_histfile}" && printf '%(%Y-%m-%d %H:%M:%S)T' >>"$f_histfile.fetched"
# refresh latest indicators # refresh latest indicators
get_indicators "${f_histfile}" 900 get_indicators "${f_histfile}" 51
rm -f "${f_histfile}.fetching" rm -f "${f_histfile}.fetching"
@@ -67,28 +88,42 @@ function get_ohlcv-candle {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_yahoo f_date f_unit_date f_data f_data_array f_data_unit f_open f_high f_low f_close f_volume f_last_unit_date f_last_unit_close local f_extdata f_date f_unit_date f_data f_data_array f_data_unit f_open f_high f_low f_close f_volume f_last_unit_date f_last_unit_close
local f_symbol="$1" local f_symbol="$1"
local f_timeframe=$2 local f_timeframe=$2
local f_histfile="$3" local f_histfile="$3"
local f_asset=$4 local f_asset=$4
unset f_histfile_yahoo unset f_histfile_yahoo f_histfile_coinmarketcap
#[ -n "$f_asset" ] && f_yahoo=1a #[ -n "$f_asset" ] && f_extdata=1
#local f_histfile_week="$4" #local f_histfile_week="$4"
# fetch >=1d from yahoo finance # fetch >=1d from coinmarketcap
if [ "$f_timeframe" = "1d" ] || [ "$f_timeframe" = "1w" ] || [ "$f_timeframe" = "1mo" ] || [ -n "$f_asset" ] if [ "$f_timeframe" = "1d" ] || [ "$f_timeframe" = "1w" ] || [ "$f_timeframe" = "1mo" ] || [ -n "$f_asset" ]
then then
f_yahoo=1 f_extdata=1
if [ -z "$f_asset" ] if [ -z "$f_asset" ]
then then
f_asset=${f_symbol///} f_asset=${f_symbol///}
f_asset=${f_asset//:*} f_asset=${f_asset//:*}
fi fi
if ! get_marketdata_yahoo "$f_symbol" "$f_asset" $f_timeframe
if [[ $f_asset =~ ^ECONOMY- ]]
then then
g_echo_error "$f_get_marketdata_yahoo_error" # economy from yahoo finance
return 1 if ! get_marketdata_yahoo "$f_symbol" "$f_asset" $f_timeframe
then
g_echo_error "$f_get_marketdata_coinmarketcap_error"
return 1
fi
f_histfile_extdata=$f_histfile_yahoo
else
# crypto from coinmarketcap
if ! get_marketdata_coinmarketcap "$f_symbol" "$f_asset" $f_timeframe
then
g_echo_error "$f_get_marketdata_coinmarketcap_error"
return 1
fi
f_histfile_extdata=$f_histfile_coinmarketcap
fi fi
fi fi
@@ -96,7 +131,7 @@ function get_ohlcv-candle {
while true while true
do do
# fetch data # fetch data
if [ -z "$f_yahoo" ] if [ -z "$f_extdata" ]
then then
# find latest time which is not fetched already create f_since # find latest time which is not fetched already create f_since
get_ohlcv-candle-latest "$f_symbol" "$f_histfile" get_ohlcv-candle-latest "$f_symbol" "$f_histfile"
@@ -112,28 +147,30 @@ function get_ohlcv-candle {
f_data=${f_data//],/+} f_data=${f_data//],/+}
g_array $f_data f_data_ref + g_array $f_data f_data_ref +
else else
# from yahoo finance # from coinmarketcap/yahoo
g_array "$f_histfile_yahoo" f_data_ref
g_array "$f_histfile_extdata" f_data_ref
fi fi
f_data_array=("${f_data_ref[@]}") f_data_array=("${f_data_ref[@]}")
# check if last data already in history file and end if already present # check if last data already in history file and end if already present
g_array "${f_data_array[-1]}" f_last_data_unit_ref , g_array "${f_data_array[-1]}" f_last_data_unit_ref ,
[ -z "$f_yahoo" ] && printf -v f_last_unit_date '%(%Y-%m-%d %H:%M:%S)T' ${f_last_data_unit_ref[0]::-3} [ -z "$f_extdata" ] && printf -v f_last_unit_date '%(%Y-%m-%d %H:%M:%S)T' ${f_last_data_unit_ref[0]::-3}
[ -n "$f_yahoo" ] && f_last_unit_date="${f_last_data_unit_ref[0]}" [ -n "$f_extdata" ] && f_last_unit_date="${f_last_data_unit_ref[0]}"
# exit if we have already in the newest date
#echo "grep -q ^\"$f_last_unit_date\" \"$f_histfile\""
[ -s "$f_histfile" ] && grep -q ^"${f_last_unit_date}," "$f_histfile" && break [ -s "$f_histfile" ] && grep -q ^"${f_last_unit_date}," "$f_histfile" && break
# go through data and write to history file if new units available # go through data and write to history file if new units available
for f_data_unit in "${f_data_array[@]}" for f_data_unit in "${f_data_array[@]}"
do do
# use array for each unit and assigned values to vars # use array for each unit and assigned values to vars
g_array "$f_data_unit" f_data_unit_ref , g_array "$f_data_unit" f_data_unit_ref ,
[ -z "$f_yahoo" ] && printf -v f_unit_date '%(%Y-%m-%d %H:%M:%S)T' ${f_data_unit_ref[0]::-3} [ -z "$f_extdata" ] && printf -v f_unit_date '%(%Y-%m-%d %H:%M:%S)T' ${f_data_unit_ref[0]::-3}
[ -n "$f_yahoo" ] && f_unit_date="${f_last_data_unit_ref[0]}" [ -n "$f_extdata" ] && f_unit_date="${f_last_data_unit_ref[0]}"
# check if date is already in history file # check if date is already in history file
[ -s "$f_histfile" ] && grep -q ^"$f_unit_date" "$f_histfile" && continue [ -s "$f_histfile" ] && grep -q ^"$f_unit_date" "$f_histfile" && continue
@@ -144,7 +181,7 @@ function get_ohlcv-candle {
then then
f_open=${f_data_unit_ref[1]} f_open=${f_data_unit_ref[1]}
fi fi
g_num_exponential2normal "$f_open" && f_open=$g_num_exponential2normal_resul g_num_exponential2normal "$f_open" && f_open=$g_num_exponential2normal_result
f_high=${f_data_unit_ref[2]} f_high=${f_data_unit_ref[2]}
g_num_exponential2normal "$f_high" && f_high=$g_num_exponential2normal_result g_num_exponential2normal "$f_high" && f_high=$g_num_exponential2normal_result
f_low=${f_data_unit_ref[3]} f_low=${f_data_unit_ref[3]}
@@ -153,7 +190,7 @@ function get_ohlcv-candle {
g_num_exponential2normal "$f_close" && f_close=$g_num_exponential2normal_result g_num_exponential2normal "$f_close" && f_close=$g_num_exponential2normal_result
f_last_unit_close=$f_close f_last_unit_close=$f_close
f_volume=${f_data_unit_ref[5]} f_volume=${f_data_unit_ref[5]}
# yahoo historic volume col 6 # coinmarketcap historic volume col 6
[ -n "${f_data_unit_ref[6]}" ] && f_volume=${f_data_unit_ref[6]} [ -n "${f_data_unit_ref[6]}" ] && f_volume=${f_data_unit_ref[6]}
g_num_exponential2normal "$f_volume" && f_volume=$g_num_exponential2normal_result g_num_exponential2normal "$f_volume" && f_volume=$g_num_exponential2normal_result
@@ -178,8 +215,8 @@ function get_ohlcv-candle {
done done
# end if yahoo (complete file and not time chunks) # end if coinmarketcap (complete file and not time chunks)
[ -n "$f_yahoo" ] && break [ -n "$f_extdata" ] && break
# end if lates refresh is this day # end if lates refresh is this day
printf -v f_date '%(%Y-%m-%d)T\n' printf -v f_date '%(%Y-%m-%d)T\n'
@@ -226,6 +263,9 @@ function get_ohlcv-candle-latest {
function convert_ohlcv_1h_to_4h { function convert_ohlcv_1h_to_4h {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_input_file="$1" local f_input_file="$1"
local f_output_file="$2" local f_output_file="$2"
@@ -248,7 +288,7 @@ function convert_ohlcv_1h_to_4h {
fi fi
# Read the input file line by line # Read the input file line by line
while IFS=',' read -r f_date f_1h_open f_1h_high f_1h_low f_1h_close f_1h_volume f_rest grep -h "$f_latest_date" -A99999 "$f_input_file" | while IFS=',' read -r f_date f_1h_open f_1h_high f_1h_low f_1h_close f_1h_volume f_rest
do do
# check for already converted lines # check for already converted lines
@@ -305,10 +345,206 @@ function convert_ohlcv_1h_to_4h {
g_calc "$f_volume + $f_1h_volume" g_calc "$f_volume + $f_1h_volume"
f_volume=$g_calc_result f_volume=$g_calc_result
done < "$f_input_file" >>"$f_output_file" done >>"$f_output_file.4htmp"
egrep -h "^[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-9][0-9].*,[0-9]" "$f_output_file" "$f_output_file.4htmp" | sort -k1,2 -t, -u | sort -k1,1 -t, -u >"$f_output_file.tmp"
mv "$f_output_file.tmp" "$f_output_file"
rm -f "$f_output_file.4htmp"
} }
#function convert_ohlcv_1h_to_1d {
#
# g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
#
# local f_input_file="$1"
# local f_output_file="$2"
#
# local f_latestdate f_nextdate f_mytimezone f_line f_date f_open f_high f_low f_close f_volume f_inday i
#
# if ! [ -s "$f_input_file" ]
# then
# g_echo_error "$f_input_file"
# return 0
# fi
#
# # crypto timezone UTC
# local f_target_timezone=UTC
# # US economy timezone America/New_York
# [[ $f_input_file =~ ECONOMY ]] && f_target_timezone="America/New_York"
#
# [ -s "$f_output_file" ] && f_latestdate=$(tail -n1 "$f_output_file" | cut -d, -f1)
# [ -z "$f_latestdate" ] && f_latestdate=$(date -d "$(head -n1 "$f_input_file" | cut -d, -f1)" +%Y-%m-%d)
# f_latestdate=$(TZ="$f_target_timezone" date -d "$f_latestdate $f_mytimezone" "+%Y-%m-%d")
# f_nextdate=$(date -d "$f_latestdate +1day" "+%Y-%m-%d")
#
# # mytimezone, respecting summer/winter time
# f_mytimezone=$(date -d "$_latestdate" +%Z)
#
# local f_today=$(TZ="$f_target_timezone" date "+%Y-%m-%d")
# # check if there is a $f_latestdate
# grep -A9999 -B24 "^$f_latestdate" "$f_input_file" >"$g_tmp/convert_ohlcv_1h_to_1d_nextlines"
# if ! [ -s "$g_tmp/convert_ohlcv_1h_to_1d_nextlines" ]
# then
# cat "$f_input_file" >"$g_tmp/convert_ohlcv_1h_to_1d_nextlines"
# f_nextdate=$(date -d "$(head -n1 "$g_tmp/convert_ohlcv_1h_to_1d_nextlines" | cut -d, -f1)" +%Y-%m-%d)
# fi
#
# # go through lines and switch to $f_target_timezone
# cat "$g_tmp/convert_ohlcv_1h_to_1d_nextlines" | grep ':00:00,' | cut -d, -f1,2,3,4,5,6 | while read f_line
# do
# g_array "$f_line" g_line_array ,
# # calculate day in target timezone
# g_line_array[0]=$(TZ="$f_target_timezone" date -d "${g_line_array[0]} $f_mytimezone" "+%Y-%m-%d")
# [[ ${g_line_array[0]} = $f_today ]] && break
# echo "${g_line_array[0]},${g_line_array[1]},${g_line_array[2]},${g_line_array[3]},${g_line_array[4]},${g_line_array[5]}"
# done >"${f_output_file}.tmp"
#
# # check if $f_nextdate really exists in $f_target_timezone if not add a day until it exists
# # useful for weekends
# i=1
# until grep -q "^$f_nextdate" "${f_output_file}.tmp"
# do
# #echo $f_nextdate
# [[ $f_nextdate = $f_today ]] && return 0
# f_nextdate=$(date -d "$f_nextdate +1day" "+%Y-%m-%d")
# i=$((i++))
# if [ $i -gt 10 ]
# then
# g_echo_warn "${FUNCNAME} $@: no nextdate found after >10 iterations"
# return 1
# fi
# done
#
# # set ent mark to store latest complete day
# echo END >>"${f_output_file}.tmp"
#
# # go through converted lines
# cat "${f_output_file}.tmp" | while read f_line
# do
# g_array "$f_line" g_line_array ,
# [[ ${g_line_array[0]} = $f_today ]] && break
#
# # wait until next day in target file reached
# if [[ ${g_line_array[0]} = $f_nextdate ]]
# then
# f_end_reached=1
# else
# [ -z $f_end_reached ] && continue
# fi
#
# # if dayend
# if [ -n "$f_inday" ] && [[ $f_latestdate != ${g_line_array[0]} ]]
# then
# # day end
# echo "$f_date,$f_open,$f_high,$f_low,$f_close,$f_volume"
# f_inday=""
# fi
#
# # calc values if inday
# if [ -n "$f_inday" ]
# then
# #echo "in day $f_date" 1>&2
# # in day
# # add volume
# g_calc "$f_volume+${g_line_array[5]}"
# f_volume=$g_calc_result
# # look for higher high
# g_num_is_higher ${g_line_array[2]} $f_high && f_high=${g_line_array[2]}
# # look for lower low
# g_num_is_lower ${g_line_array[3]} $f_low && f_low=${g_line_array[3]}
# fi
#
# # if newday
# if [ -z "$f_inday" ]
# then
# #echo "day begin ${g_line_array[0]}" 1>&2
# # day begin
# f_inday=1
# f_date=${g_line_array[0]}
# f_latestdate=$f_date
# f_open=${g_line_array[1]}
# f_high=${g_line_array[2]}
# f_low=${g_line_array[3]}
# f_close=${g_line_array[4]}
# f_volume=${g_line_array[5]}
# fi
#
# done >>"$f_output_file"
#
#}
function convert_ohlcv_1d_to_1w {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_input_file=$1
local f_output_file=$2
local f_week_date f_day f_month f_year f_other f_line f_data
local -A f_open_prices f_high_prices f_low_prices f_close_prices f_volume_prices
# get lastest date to continue from here and create output file if not exists
if [ -s "$f_output_file" ]
then
f_latestdate=$(tail -n1 "$f_output_file" | cut -d, -f1)
else
touch "$f_output_file"
fi
# if not exists use first date as latest date
[ -z "$f_latestdate" ] && f_latestdate=$(date -d "$(head -n1 "$f_input_file" | cut -d, -f1)" +%Y-%m-%d)
# check if there is a $f_latestdate
grep -A9999 -B9 "^$f_latestdate" "$f_input_file" >"$g_tmp/convert_ohlcv_1d_to_1w_nextlines"
if ! [ -s "$g_tmp/convert_ohlcv_1d_to_1w_nextlines" ]
then
cat "$f_input_file" >"$g_tmp/convert_ohlcv_1d_to_1w_nextlines"
fi
# go through lines
for f_line in $(cat "$g_tmp/convert_ohlcv_1d_to_1w_nextlines")
do
IFS=',' read -r f_date f_open f_high f_low f_close f_volume f_other <<< "$f_line"
IFS='-' read -r f_year f_month f_day <<< "$f_date"
[ -z "$f_high" ] && f_high=$f_open
[ -z "$f_low" ] && f_low=$f_open
[ -z "$f_close" ] && f_close=$f_open
[ -z "$f_volume" ] && f_volume=0
# use week-number to sort day data in weeks
f_week_number=$(date -d "$f_year-$f_month-$f_day" +%U)
f_week_number=${f_week_number##0}
f_week_year=$f_year$f_week_number
# calculate week ohlcv and write to arrays sortet by f_week_year
g_calc "${f_open_prices[$f_week_year]:-$f_open}"
f_open_prices[$f_week_year]=$g_calc_result
g_num_is_higher "$f_high" "${f_high_prices[$f_week_year]:-0}" && f_high_prices[$f_week_year]=$f_high
[ -z "${f_low_prices[$f_week_year]}" ] && f_low_prices[$f_week_year]=$f_low
g_num_is_lower "$f_low" "${f_low_prices[$f_week_year]:-0}" && f_low_prices[$f_week_year]=$f_low
f_close_prices[$f_week_year]=$f_close
[ -z "$f_volume" ] && f_volume=0
g_calc "${f_volume_prices[$f_week_year]:-0}+$f_volume"
f_volume_prices[$f_week_year]=$g_calc_result
done
# go through array(s) and write down missing week data
for f_week_year in "${!f_open_prices[@]}"
do
f_week_date=$(date -d "${f_week_year:0:4}-01-01 +$((${f_week_year:4})) week -1day" +%F)
# ignore if date alerady exists
grep -q ^$f_week_date, "$f_output_file" && continue
echo "$f_week_date,${f_open_prices[$f_week_year]},${f_high_prices[$f_week_year]},${f_low_prices[$f_week_year]},${f_close_prices[$f_week_year]},${f_volume_prices[$f_week_year]}"
done | sort >>"$f_output_file"
}
function f_add_missing_ohlcv_intervals { function f_add_missing_ohlcv_intervals {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -335,12 +571,16 @@ function f_add_missing_ohlcv_intervals {
[[ $f_interval = 1w ]] && return 0 [[ $f_interval = 1w ]] && return 0
[[ $f_histfile =~ \.1w\. ]] && return 0 [[ $f_histfile =~ \.1w\. ]] && return 0
local f_prev_date f_prev_vals f_curr_date f_curr_vals f_missing_date f_open f_high f_low f_close f_volume f_percent
local f_prev_date f_prev_vals f_curr_date f_curr_vals f_missing_date f_open f_high f_low f_close f_volume f_percent f_open f_counter
# go through csv per line # go through csv per line
while IFS=',' read -r f_curr_date f_open f_high f_low f_close f_volume f_percent f_curr_vals while IFS=',' read -r f_curr_date f_open f_high f_low f_close f_volume f_percent f_curr_vals
do do
# Wegnn das vorherige Datum nicht leer ist
#echo "$f_curr_date" 1>&2
# if prev date is not empty
if [ -z "$f_prev_date" ] if [ -z "$f_prev_date" ]
then then
f_prev_date=$f_curr_date f_prev_date=$f_curr_date
@@ -348,24 +588,38 @@ function f_add_missing_ohlcv_intervals {
continue continue
fi fi
while true #echo "$f_curr_date x" 1>&2
# only 10 interations to prevelt endless loop
f_counter=0
while [ $f_counter -lt 10 ]
#while true
do do
((f_counter++))
#echo "$f_curr_date xx $f_counter" 1>&2
# get second timestamps # get second timestamps
f_prev_date_in_seconds=$(date -d"$f_prev_date" +%s) f_prev_date_in_seconds=$(date -d"$f_prev_date" +%s)
f_curr_date_in_seconds=$(date -d"$f_curr_date" +%s) f_curr_date_in_seconds=$(date -d"$f_curr_date" +%s)
# calculate/check the next timestamp from previ15ms # echo [ "$f_prev_date_in_seconds" -gt "$f_curr_date_in_seconds" ] # && break
# and check for summer/winter time
# calculate/check the next timestamp from previous
# and check for summer/winter time in 4h or greater interval
if [ $f_interval -gt 3600 ] if [ $f_interval -gt 3600 ]
then then
# reduce an hour because of possible summer/winter time change # reduce an hour because of possible summer/winter time change
#g_calc "$f_curr_date_in_seconds - ($f_counter * $f_prev_date_in_seconds - 3600)"
g_calc "$f_curr_date_in_seconds - $f_prev_date_in_seconds - 3600" g_calc "$f_curr_date_in_seconds - $f_prev_date_in_seconds - 3600"
else else
#g_calc "$f_curr_date_in_seconds - $f_counter * $f_prev_date_in_seconds"
g_calc "$f_curr_date_in_seconds - $f_prev_date_in_seconds" g_calc "$f_curr_date_in_seconds - $f_prev_date_in_seconds"
fi fi
if [ $g_calc_result -gt $f_interval ] if [ $g_calc_result -gt $f_interval ]
then then
# calc missing timestamp in seconds # calc missing timestamp in seconds
#f_curr_date_in_seconds=$(( f_prev_date_in_seconds + f_interval * f_counter ))
f_curr_date_in_seconds=$(( f_prev_date_in_seconds + f_interval )) f_curr_date_in_seconds=$(( f_prev_date_in_seconds + f_interval ))
# and calculate next timestamp # and calculate next timestamp
g_calc "$f_curr_date_in_seconds - $f_prev_date_in_seconds" g_calc "$f_curr_date_in_seconds - $f_prev_date_in_seconds"
@@ -377,15 +631,28 @@ function f_add_missing_ohlcv_intervals {
else else
f_missing_date=$(date -d"@$f_curr_date_in_seconds" +"%F") f_missing_date=$(date -d"@$f_curr_date_in_seconds" +"%F")
fi fi
# prevent endless loop if something goes wrong (strange errors in 1d ohlcv!)
f_missing_date_in_seconds=$(date -d"$f_missing_date" +%s)
if [ $f_missing_date_in_seconds -lt $f_curr_date_in_seconds ]
then
[ -z "$f_curr_vals" ] && echo "$f_curr_date,$f_open,$f_high,$f_low,$f_close,$f_volume,$f_percent"
[ -n "$f_curr_vals" ] && echo "$f_curr_date,$f_open,$f_high,$f_low,$f_close,$f_volume,$f_percent,$f_curr_vals"
f_prev_date=$f_curr_date
break
fi
# write missing line # write missing line
echo "$f_missing_date,$f_close,$f_close,$f_close,$f_close,0,0.00,$f_curr_vals" [ -z "$f_curr_vals" ] && echo "$f_missing_date,$f_open,$f_open,$f_open,$f_open,0,0.00"
[ -n "$f_curr_vals" ] && echo "$f_missing_date,$f_open,$f_open,$f_open,$f_open,0,0.00,$f_curr_vals"
f_prev_date=$f_missing_date f_prev_date=$f_missing_date
else else
f_prev_date=$f_curr_date f_prev_date=$f_curr_date
echo "$f_curr_date,$f_open,$f_high,$f_low,$f_close,$f_volume,$f_percent,$f_curr_vals" [ -z "$f_curr_vals" ] && echo "$f_curr_date,$f_open,$f_high,$f_low,$f_close,$f_volume,$f_percent"
[ -n "$f_curr_vals" ] && echo "$f_curr_date,$f_open,$f_high,$f_low,$f_close,$f_volume,$f_percent,$f_curr_vals"
break break
fi fi
done done
done < "$f_histfile" > $g_tmp/f_add_missing_ohlcv_intervals_result done < "$f_histfile" > $g_tmp/f_add_missing_ohlcv_intervals_result
@@ -398,5 +665,3 @@ function f_add_missing_ohlcv_intervals {
cat "$g_tmp/f_add_missing_ohlcv_intervals_result" >"$f_histfile" cat "$g_tmp/f_add_missing_ohlcv_intervals_result" >"$f_histfile"
fi fi
} }

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_onetrading_csv_transactions { function get_onetrading_csv_transactions {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_orders { function get_orders {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -23,23 +43,93 @@ function get_orders {
fi fi
[ -z "$f_symbols" ] && return 1 [ -z "$f_symbols" ] && return 1
for f_symbol in "${f_symbols[@]}" for f_symbol in ${f_symbols_array_trade[@]}
do do
f_symbol_file=${f_symbol//:*} f_symbol_file=${f_symbol//:*}
f_symbol_file=${f_symbol_file///} f_symbol_file=${f_symbol_file///}
g_echo_note "Getting orders from $f_symbol to \"CCXT_OPEN_ORDERS_$f_symbol_file\"" g_echo_note "Getting orders from $f_symbol to \"CCXT_ORDERS_$f_symbol_file\""
if f_ccxt "print($STOCK_EXCHANGE.fetchOpenOrders(symbol='${f_symbol}'))" if f_ccxt "print($STOCK_EXCHANGE.fetchOpenOrders(symbol='${f_symbol}'))"
then then
echo $f_ccxt_result | tee "CCXT_OPEN_ORDERS_${f_symbol_file}_RAW" | jq -r " echo $f_ccxt_result | tee "CCXT_ORDERS_${f_symbol_file}_RAW" | jq -r "
.[] | .[] |
select(.status==\"open\") | select(.status==\"open\") |
.symbol + \",\" + .type + \",\" + .side + \",\" + (.price|tostring) + \",\" + (.stopPrice|tostring) + \",\" + (.amount .symbol + \",\" + .type + \",\" + .side + \",\" + (.price|tostring) + \",\" + (.amount|tostring) + \",\" + .id + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring) + \",\" + (.stopPrice|tostring)
|tostring) " >"CCXT_ORDERS_${f_symbol_file}"
" >"CCXT_OPEN_ORDERS_${f_symbol_file}"
else else
rm -f "CCXT_OPEN_ORDERS_${f_symbol_file}_RAW" "CCXT_OPEN_ORDERS_${f_symbol_file}" rm -f "CCXT_ORDERS_${f_symbol_file}_RAW" "CCXT_ORDERS_${f_symbol_file}"
continue continue
fi fi
done done
cat CCXT_ORDERS_*${CURRENCY} >CCXT_ORDERS 2>/dev/null
get_orders_array
} }
function get_orders_array {
local f_order
# clear/create assoziative array o
unset o
declare -Ag o
# build array from lines in CCXT_ORDERS
g_array CCXT_ORDERS f_get_ordes_array
for f_order in ${f_get_ordes_array[@]}
do
get_order_line_vars "$f_order"
done
# write values to file
for i in "${!o[@]}"
do
echo "\${o[$i]}=${o[$i]}"
done | sort >values-orders.new
mv values-orders.new values-orders
}
function get_order_line_vars {
local f_order_line=$1
g_array $f_order_line f_order_array ,
f_order_symbol=${f_order_array[0]}
local f_asset=${f_order_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
local f_order_type=${f_order_array[1]}
local f_order_side=${f_order_array[2]}
local f_type
if [[ $f_order_type = limit ]]
then
[[ $f_order_side = buy ]] && f_type="open_long"
[[ $f_order_side = sell ]] && f_type="open_short"
fi
if [[ $f_order_type = Stop ]]
then
[[ $f_order_side = buy ]] && f_type="sl_close_short"
[[ $f_order_side = sell ]] && f_type="sl_close_long"
fi
if [[ $f_order_type = MarketIfTouched ]]
then
[[ $f_order_side = buy ]] && f_type="tp_close_short"
[[ $f_order_side = sell ]] && f_type="tp_close_long"
fi
if [ -z "${o[${f_asset}_present]}" ]
then
o[${f_asset}_present]=${f_type}
else
o[${f_asset}_present]="${o[${f_asset}_present]} ${f_type}"
fi
o[${f_asset}_${f_type}_type]=${f_order_array[1]}
o[${f_asset}_${f_type}_side]=${f_order_array[2]}
o[${f_asset}_${f_type}_entry_price]=${f_order_array[3]}
o[${f_asset}_${f_type}_amount]=${f_order_array[4]}
o[${f_asset}_${f_type}_id]=${f_order_array[5]}
o[${f_asset}_${f_type}_stoplossprice]=${f_order_array[6]}
o[${f_asset}_${f_type}_takeprofitprice]=${f_order_array[7]}
o[${f_asset}_${f_type}_stopprice]=${f_order_array[8]}
}

View File

@@ -0,0 +1,63 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_phemex_csv_transactions {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# PHEMEX Export format:
# Time (UTC),Symbol,Exec Type,Exec. Size,Direction,Exec. Price,Order Size,Order Price,Exec Value,Fee Rate,Fee Paid,Type,"ID"
if [ -s phemex-export.csv ]
then
# explicit long
cat phemex-export.csv | egrep '^[0-9].+,Trade,.+ Long,' | sort | sed 's/,Long,/,Open Long,/; s/Open Long/leverage-buy/; s/Close Long/leverage-sell/; s/ /,/g' | awk -F, '{print $1" "$2","$7","$6","$5","$13","$12",phemex,"$16","$15","$18}' >TRANSACTIONS-phemex-LONG.csv.tmp
# explicit short
cat phemex-export.csv | egrep '^[0-9].+,Trade,.+ Short,' | sort | sed 's/,Short,/,Open Short,/; s/Open Short/leverage-sell/; s/Close Short/leverage-buy/; s/ /,/g' | awk -F, '{print $1" "$2","$7","$6","$5","$13","$12",phemex,"$16","$15","$18}' >TRANSACTIONS-phemex-SHORT.csv.tmp
# buy/sell
cat phemex-export.csv | egrep '^[0-9].+,Trade,.+,Short,|^[0-9].+,Trade,.+,Long,' | sort | sed 's/Short/leverage-sell/; s/Long/leverage-buy/; s/ /,/g' | awk -F, '{print $1" "$2","$7","$6","$5","$13","$12",phemex,"$16","$15","$18}' >TRANSACTIONS-phemex.csv.tmp
# liquidations long
cat phemex-export.csv | egrep '^[0-9].+,Liquidation,.+Long,' | sort | sed 's/ /,/g' | awk -F, '{print $1" "$2",liquidation,"$6","$5","$14","$13",phemex,"$17","$16","$19}' >TRANSACTIONS-phemex-liquidations-LONG.csv.tmp
# liquidations short
cat phemex-export.csv | egrep '^[0-9].+,Liquidation,.+Short,' | sort | sed 's/ /,/g' | awk -F, '{print $1" "$2",liquidation,"$6","$5","$14","$13",phemex,"$17","$16","$19}' >TRANSACTIONS-phemex-liquidations-SHORT.csv.tmp
# fundingfees seeem to be included in sell
cat TRANSACTIONS-phemex/*.csv | egrep 'funding' | sort -u >>TRANSACTIONS-phemex.csv.tmp
# put together
local f_line f_id
touch "TRANSACTIONS-phemex.csv"
cat TRANSACTIONS-phemex-LONG.csv.tmp TRANSACTIONS-phemex.csv.tmp TRANSACTIONS-phemex-liquidations-LONG.csv.tmp | sort | while read f_line
do
f_id=$(echo "$f_line" | cut -d, -f10)
grep -q "$f_id" "TRANSACTIONS-phemex.csv" || echo $f_line >>"TRANSACTIONS-phemex.csv"
done
cat TRANSACTIONS-phemex-SHORT.csv.tmp TRANSACTIONS-phemex-liquidations-SHORT.csv.tmp | sort | while read f_line
do
f_id=$(echo "$f_line" | cut -d, -f10)
grep -q "$f_id" "TRANSACTIONS-phemex.csv" || echo $f_line >>"TRANSACTIONS-phemex.csv"
done
# cleanup
rm -f TRANSACTIONS-phemex-LONG.csv.tmp TRANSACTIONS-phemex-SHORT.csv.tmp TRANSACTIONS-phemex.csv.tmp TRANSACTIONS-phemex-liquidations-LONG.csv.tmp TRANSACTIONS-phemex-liquidations-SHORT.csv.tmp
fi
}

View File

@@ -1,8 +1,30 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_positions { function get_positions {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_symbol f_symbols local f_symbol f_symbols f_asset f_stoploss f_takeprofit
get_symbols_ticker
# build python array of symbols # build python array of symbols
for f_symbol in "${f_symbols_array_trade[@]}" for f_symbol in "${f_symbols_array_trade[@]}"
@@ -17,50 +39,132 @@ function get_positions {
[ -z "$f_symbols" ] && return 1 [ -z "$f_symbols" ] && return 1
f_ccxt "print($STOCK_EXCHANGE.fetchPositions(symbols=[${f_symbols}]))" && echo $f_ccxt_result >CCXT_POSITIONS_RAW f_ccxt "print($STOCK_EXCHANGE.fetchPositions(symbols=[${f_symbols}]))" && echo $f_ccxt_result >CCXT_POSITIONS_RAW
jq -r " jq -r "
.[] | .[] |
select(.entryPrice != 0) | select(.entryPrice != 0) |
.symbol + \",\" + (.notional|tostring) + \",\" + (.entryPrice|tostring) + \",\" + (.markPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring) + \",\" + (.contracts|tostring) + \",\" + (.contractSize|tostring) + \",\" + (.liquidationPrice|tostring) + \",\" + (.unrealizedPnl|tostring) .symbol + \",\" + (.collateral|tostring) + \",\" + (.entryPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring) + \",\" + (.liquidationPrice|tostring) + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring) + \",\" + (.contracts|tostring)
" CCXT_POSITIONS_RAW >CCXT_POSITIONS " CCXT_POSITIONS_RAW >CCXT_POSITIONS
# check for takeprofit/stoploss orders if not in CCXT output (needed for phememx and maybe more exchanges)
get_position_array
for f_symbol in ${f_symbols_array_trade[@]}
do
f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
# only continue if position for symbol exists and stoploss or takeprofit is empty
[ -z "${p[${f_asset}_entry_price]}" ] && continue
[ -n "${p[${f_asset}_stoploss_price]}" ] && continue
[ -n "${p[${f_asset}_takeprofit_price]}" ] && continue
# check for position side
[ "${p[${f_asset}_side]}" = "long" ] && f_action=sell
[ "${p[${f_asset}_side]}" = "short" ] && f_action=buy
if [[ ${p[${f_asset}_side]} =~ long|short ]]
then
# search for stoploss and takeprofit
f_stoploss=$(egrep "^$f_symbol,Stop,$f_action,null,0," CCXT_ORDERS | cut -d , -f9)
f_takeprofit=$(egrep "^$f_symbol,MarketIfTouched,$f_action,null,0," CCXT_ORDERS | cut -d , -f9)
# escape : and / for sed and edit CCXT_POSITIONS if stoploss or takeprofit order found
f_symbol=${f_symbol//\//\\\/}
f_symbol=${f_symbol//:/\\:}
[ -n "$f_stoploss" ] && sed -i "/^$f_symbol,.*,${p[${f_asset}_side]},/s/^\(\([^,]*,\)\{6\}\)[^,]*/\1$f_stoploss/" CCXT_POSITIONS
[ -n "$f_takeprofit" ] && sed -i "/^$f_symbol,.*,${p[${f_asset}_side]},/s/^\(\([^,]*,\)\{7\}\)[^,]*/\1$f_takeprofit/" CCXT_POSITIONS
fi
done
return 0
} }
function get_position_array { function get_position_array {
local f_position
# clear/create assoziative array p
unset p
declare -Ag p
get_symbols_ticker
# build array from lines in CCXT_POSITIONS
g_array CCXT_POSITIONS f_get_positions_array g_array CCXT_POSITIONS f_get_positions_array
for f_position in ${f_get_positions_array[@]}
do
get_position_line_vars "$f_position"
done
# write values to file
for i in "${!p[@]}"
do
echo "\${p[$i]}=${p[$i]}"
done | sort >values-positions.new
mv values-positions.new values-positions
} }
function get_position_line_vars { function get_position_line_vars {
local f_pos_line=$1 local f_pos_line=$1
g_array $f_pos_line f_position_array , g_array $f_pos_line f_position_array ,
f_position_symbol=${f_position_array[0]} f_position_symbol=${f_position_array[0]}
f_position_currency_amount=${f_position_array[1]} local f_asset=${f_position_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
printf -v f_position_currency_amount %.2f ${f_position_array[1]}
p[${f_asset}_currency_amount]=$f_position_currency_amount
f_position_entry_price=${f_position_array[2]} f_position_entry_price=${f_position_array[2]}
f_position_current_price=${f_position_array[3]} p[${f_asset}_entry_price]=$f_position_entry_price
f_position_side=${f_position_array[4]}
# mark price seems not lates price in very case so take the ticker
p[${f_asset}_current_price]=${v[${f_asset}_price]}
f_position_current_price=${v[${f_asset}_price]}
f_position_side=${f_position_array[3]}
[ -z "$f_position_side" ] && f_position_side="long" [ -z "$f_position_side" ] && f_position_side="long"
f_position_leverage=${f_position_array[5]} p[${f_asset}_side]=$f_position_side
[ -z "$f_position_leverage" ] && f_position_leverage="1"
f_position_contracts=${f_position_array[6]}
f_position_contract_size=${f_position_array[7]}
f_position_liquidation_price=${f_position_array[8]}
f_position_unrealized_pnl=${f_position_array[9]}
g_percentage-diff $f_position_entry_price $f_position_current_price f_position_leverage=${f_position_array[4]}
[ "$f_position_side" = short ] && g_percentage-diff $f_position_current_price $f_position_entry_price [[ $f_position_leverage = null ]] && f_position_leverage="1"
f_position_pnl_percentage=$g_percentage_diff_result p[${f_asset}_leverage]=$f_position_leverage
if [ -n $f_position_leverage ]
p[${f_asset}_liquidation_price]=${f_position_array[5]}
f_position_liquidation_price=${f_position_array[5]}
if [[ ${f_position_array[6]} = null ]]
then then
g_calc "$f_position_pnl_percentage*$f_position_leverage" unset p[${f_asset}_stoploss_price]
f_position_pnl_percentage=$g_calc_result unset f_position_stoploss_price
else
g_calc "$f_position_currency_amount/$f_position_leverage" p[${f_asset}_stoploss_price]=${f_position_array[6]}
f_position_currency_amount=$g_calc_result f_position_stoploss_price=${f_position_array[6]}
g_calc "$f_position_currency_amount/100*$f_position_pnl_percentage"
f_position_pnl=$g_calc_result
fi fi
if [[ ${f_position_array[7]} = null ]]
then
unset p[${f_asset}_takeprofit_price]
unset f_position_takeprofit_price
else
p[${f_asset}_takeprofit_price]=${f_position_array[7]}
f_position_takeprofit_price=${f_position_array[7]}
fi
#printf -v f_position_asset_amount %.2f ${f_position_array[8]}
#p[${f_asset}_asset_amount]=$f_position_asset_amount
p[${f_asset}_asset_amount]=${f_position_array[8]}
# calc pnl percentage
if [[ $f_position_side = long ]]
then
g_percentage-diff $f_position_entry_price $f_position_current_price
else
g_percentage-diff $f_position_current_price $f_position_entry_price
fi
g_calc "$g_percentage_diff_result*$f_position_leverage"
f_position_pnl_percentage=$g_calc_result
p[${f_asset}_pnl_percentage]=$g_calc_result
# calc pnl
g_calc "$f_position_currency_amount/100*$f_position_pnl_percentage"
printf -v f_position_pnl %.2f $g_calc_result
p[${f_asset}_pnl]=$f_position_pnl
} }

View File

@@ -1,5 +1,24 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_range { function get_range {
#g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" #g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_rsi_indicator { function get_rsi_indicator {
#g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" #g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# get histfile # get histfile

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_symbols_ticker { function get_symbols_ticker {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -66,6 +86,8 @@ function get_symbols_ticker {
g_array CCXT_TICKERS-$STOCK_EXCHANGE f_tickers_array_ref g_array CCXT_TICKERS-$STOCK_EXCHANGE f_tickers_array_ref
local f_ticker f_symbol f_price local f_ticker f_symbol f_price
declare -Ag f_tickers_array declare -Ag f_tickers_array
declare -Ag v
declare -Ag vr
for f_ticker in "${f_tickers_array_ref[@]}" for f_ticker in "${f_tickers_array_ref[@]}"
do do
f_symbol=${f_ticker%%:*} f_symbol=${f_ticker%%:*}
@@ -74,6 +96,8 @@ function get_symbols_ticker {
f_price=${f_ticker/*,/} f_price=${f_ticker/*,/}
g_num_exponential2normal $f_price && f_price=$g_num_exponential2normal_result g_num_exponential2normal $f_price && f_price=$g_num_exponential2normal_result
f_tickers_array[$f_symbol]=$f_price f_tickers_array[$f_symbol]=$f_price
vr[${f_symbol}_price]=$f_price
v[${f_symbol}_price]=$f_price
done done
fi fi

View File

@@ -1,8 +1,28 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_transactions { function get_transactions {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_exchange f_symbol f_symbol_file f_asset f_currency f_leverage f_convert_end_month f_convert_end_year f_symbol_file_csv f_symbol_file_csv_tmp f_start_date f_end_date f_convert_file f_fiat f_fiats local f_exchange f_symbol f_symbol_file f_asset f_currency f_leverage f_convert_end_month f_convert_end_year f_symbol_file_csv f_symbol_file_csv_tmp f_start_date f_end_date f_convert_file f_fiat f_fiats f_return
local DEFAULT_STOCK_EXCHANGE=$STOCK_EXCHANGE local DEFAULT_STOCK_EXCHANGE=$STOCK_EXCHANGE
local DEFAULT_LEVERAGE=$LEVERAGE local DEFAULT_LEVERAGE=$LEVERAGE
@@ -50,15 +70,28 @@ function get_transactions {
# fetch only if not exists # fetch only if not exists
[ -f "$f_symbol_file" ] && continue [ -f "$f_symbol_file" ] && continue
g_echo_note "fetching closed orders of $f_symbol on $f_exchange" g_echo_note "fetching closed orders of $f_symbol on ${STOCK_EXCHANGE}"
f_ccxt "print(${STOCK_EXCHANGE}.fetchMyTrades(symbol='$f_symbol', limit=500, params={'paginate': True}))" || continue
# fetch and reset/store return code
# write to file f_return=""
#[[ $f_ccxt_result = \[\] ]] && f_ccxt_result="" f_ccxt "print(${STOCK_EXCHANGE}.fetchMyTrades(symbol='$f_symbol', limit=500, params={'paginate': True}))" || f_return=1
# write result even if its failed/empty for timestamp
echo -n $f_ccxt_result >"$f_symbol_file" echo -n $f_ccxt_result >"$f_symbol_file"
# continue if no trade # continue if fetch failed/empty
#[ -z "$f_ccxt_result" ] && continue if [ -n "$f_return" ]
then
g_echo_note "fetch of $f_symbol on ${STOCK_EXCHANGE} failed no json output or empty - no trades"
continue
fi
# check output for symbol
if ! [[ $f_ccxt_result =~ $f_symbol ]]
then
g_echo_warn "unexpectet return in \"$f_symbol_file\" Symbol $f_symbol not present!?"
continue
fi
# get f_asset+f_currency from symbol (BTC/USDT) # get f_asset+f_currency from symbol (BTC/USDT)
g_array "$f_symbol" f_symbol_array / g_array "$f_symbol" f_symbol_array /
@@ -80,7 +113,7 @@ function get_transactions {
f_ccxt "print(${STOCK_EXCHANGE}.fetchFundingHistory('$f_symbol', limit=200, params={'paginate': True}))" && echo -n $f_ccxt_result >"${f_symbol_file}.FundingFees" f_ccxt "print(${STOCK_EXCHANGE}.fetchFundingHistory('$f_symbol', limit=200, params={'paginate': True}))" && echo -n $f_ccxt_result >"${f_symbol_file}.FundingFees"
cat ${f_symbol_file}.FundingFees | jq -r " cat ${f_symbol_file}.FundingFees | jq -r "
.[] | .[] |
.datetime + \",fundingfee,$f_asset,0,\" + .code + \",0\" + \",$f_exchange,\" + .code + \",\" + (.amount|tostring) .datetime + \",fundingfee,$f_asset,0,\" + .code + \",0\" + \",$f_exchange,\" + .code + \",\" + (.amount|tostring)
" >>$f_symbol_file_csv_tmp " >>$f_symbol_file_csv_tmp
# remove the ':' in f_currency # remove the ':' in f_currency
@@ -89,33 +122,33 @@ function get_transactions {
fi fi
# generate csv # generate csv
# get longs (posSide=="1")
# get spot buy/sell (posSide=="1")
cat "$f_symbol_file" | jq -r " cat "$f_symbol_file" | jq -r "
.[] | .[] |
select(.side==\"buy\" or .side==\"sell\") | select(.side==\"buy\" or .side==\"sell\") |
select(.info.posSide==\"1\") | select(.symbol != null) |
select(.symbol!= null) | select(.type != null) |
.datetime + \",$f_leverage\" + .side + \",$f_asset,\" + (.amount|tostring) + \",$f_currency,\" + (.cost|tostring) + \",$f_exchange,\" + .fee.currency + \",\" + (.fee.cost|tostring) .datetime + \",$f_leverage\" + .side + \",$f_asset,\" + (.amount|tostring) + \",$f_currency,\" + (.cost|tostring) + \",$f_exchange,\" + .fee.currency + \",\" + (.fee.cost|tostring) + \",\" + .id
" >>"$f_symbol_file_csv_tmp" " >>"$f_symbol_file_csv_tmp"
# get shorts (posSide=="2") sell first, then buy (https://github.com/ccxt/ccxt/issues/22518) # # get longs (posSide=="1")
cat "$f_symbol_file" | jq -r " # cat "$f_symbol_file" | jq -r "
.[] | #.[] |
select(.side==\"sell\") | # select(.side==\"buy\" or .side==\"sell\") |
select(.info.posSide==\"2\") | # select(.info.posSide=\"1\") |
select(.symbol!= null) | # select(.symbol!= null) |
.side = \"sell\" | #.datetime + \",$f_leverage\" + .side + \",$f_asset,\" + (.amount|tostring) + \",$f_currency,\" + (.cost|tostring) + \",$f_exchange,\" + .fee.currency + \",\" + (.fee.cost|tostring) + \",\" + .id
.datetime + \",$f_leverage\" + .side + \",$f_asset,\" + (.amount|tostring) + \",$f_currency,\" + (.cost|tostring) + \",$f_exchange,\" + .fee.currency + \",\" + (.fee.cost|tostring) + \",short\" #" >>"$f_symbol_file_csv_tmp"
" >>"$f_symbol_file_csv_tmp" #
# # get shorts (posSide=="2") sell first, then buy (https://github.com/ccxt/ccxt/issues/22518)
cat "$f_symbol_file" | jq -r " # cat "$f_symbol_file" | jq -r "
.[] | #.[] |
select(.side==\"buy\") | # select(.side==\"buy\" or .side==\"sell\") |
select(.info.posSide==\"2\") | # select(.info.posSide==\"2\") |
select(.symbol!= null) | # select(.symbol!=null) |
.side = \"buy\" | #.datetime + \",$f_leverage\" + .side + \",$f_asset,\" + (.amount|tostring) + \",$f_currency,\" + (.cost|tostring) + \",$f_exchange,\" + .fee.currency + \",\" + (.fee.cost|tostring) + \",\" + .id
.datetime + \",$f_leverage\" + .side + \",$f_asset,\" + (.amount|tostring) + \",$f_currency,\" + (.cost|tostring) + \",$f_exchange,\" + .fee.currency + \",\" + (.fee.cost|tostring) + \",short\" #" >>"$f_symbol_file_csv_tmp"
" >>"$f_symbol_file_csv_tmp"
if [ -s "$f_symbol_file_csv_tmp" ] if [ -s "$f_symbol_file_csv_tmp" ]
then then
@@ -136,6 +169,7 @@ function get_transactions {
## Get converts on supported exchanges since 2022 ## Get converts on supported exchanges since 2022
if [[ $f_exchange = binance ]] if [[ $f_exchange = binance ]]
then then
local m y
printf -v f_convert_end_year '%(%Y)T' printf -v f_convert_end_year '%(%Y)T'
for ((y=2022;y<=$f_convert_end_year;y++)) for ((y=2022;y<=$f_convert_end_year;y++))
do do
@@ -144,9 +178,10 @@ function get_transactions {
for ((m=1;m<=$f_convert_end_month;m++)) for ((m=1;m<=$f_convert_end_month;m++))
do do
f_start_date="$(date -d "$y-$m-1" +%s)001" f_start_date="$(date -d "$y-$m-1" +%s)001"
em=$((m+1)) #em=$((m+1))
[ $em = 13 ] && em=1 #[ $em = 13 ] && em=1
f_end_date="$(date -d "$y-$em-1" +%s)000" #f_aend_date="$(date -d "$y-$em-1" +%s)000"
f_end_date="$(date -d "$y-$m-1 +29days" +%s)000"
f_convert_file="TRANSACTIONS-$f_exchange/CONVERT-$y-$m" f_convert_file="TRANSACTIONS-$f_exchange/CONVERT-$y-$m"
[ -s "${f_convert_file}.csv" ] && continue [ -s "${f_convert_file}.csv" ] && continue
@@ -172,14 +207,20 @@ function get_transactions {
done done
fi fi
# put all sorted n one file # put all sorted in one file. duplicates check with id
if [ -s TRANSACTIONS-$f_exchange.csv ] local f_line f_date f_sym
then touch "TRANSACTIONS-$f_exchange.csv"
cat "TRANSACTIONS-$f_exchange/"*.csv TRANSACTIONS-$f_exchange.csv | sort -u >TRANSACTIONS-$f_exchange.csv.tmp grep -vh ,fundingfee, "TRANSACTIONS-$f_exchange/"*.csv | while read f_line
mv TRANSACTIONS-$f_exchange.csv.tmp TRANSACTIONS-$f_exchange.csv do
else f_id=$(echo "$f_line" | cut -d, -f10)
cat "TRANSACTIONS-$f_exchange/"*.csv | sort -u >TRANSACTIONS-$f_exchange.csv grep -q "$f_id" "TRANSACTIONS-$f_exchange.csv" || echo $f_line >>"TRANSACTIONS-$f_exchange.csv"
fi done
grep -h ,fundingfee, "TRANSACTIONS-$f_exchange/"*.csv | while read f_line
do
f_date=$(echo "$f_line" | cut -d: -f1)
f_sym=$(echo "$f_line" | cut -d, -f3)
egrep -q "^$f_date:.+,$f_sym," "TRANSACTIONS-$f_exchange.csv" || echo $f_line >>"TRANSACTIONS-$f_exchange.csv"
done
# Switch sides if Fiat is in Krypto side # Switch sides if Fiat is in Krypto side
f_fiats="USD EUR" f_fiats="USD EUR"
@@ -193,7 +234,7 @@ function get_transactions {
g_echo_note "Switched some fiat/krypto sides" g_echo_note "Switched some fiat/krypto sides"
#cat TRANSACTIONS-$f_exchange.csv.tmp #cat TRANSACTIONS-$f_exchange.csv.tmp
cat TRANSACTIONS-$f_exchange.csv | egrep -v ",sell,$f_fiat,|,buy,$f_fiat," >>TRANSACTIONS-$f_exchange.csv.tmp cat TRANSACTIONS-$f_exchange.csv | egrep -v ",sell,$f_fiat,|,buy,$f_fiat," >>TRANSACTIONS-$f_exchange.csv.tmp
cat TRANSACTIONS-$f_exchange.csv.tmp | sort >TRANSACTIONS-$f_exchange.csv cat TRANSACTIONS-$f_exchange.csv.tmp >TRANSACTIONS-$f_exchange.csv
fi fi
done done

View File

@@ -0,0 +1,134 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_values {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_assets="$@"
local f_asset_histories
f_assets=${f_assets//:$CURRENCY/}
f_assets=${f_assets//\//}
for f_asset in $f_assets
do
f_asset_histories+="$f_asset "
f_asset_histories+="MARKETDATA_BINANCE_OPEN_INTEREST_$f_asset "
f_asset_histories+="MARKETDATA_BINANCE_LONG_SHORT_RATIO_TAKER_$f_asset "
f_asset_histories+="MARKETDATA_BINANCE_LONG_SHORT_RATIO_ACCOUNT_$f_asset "
done
local f_eco_asset f_eco_assets f_asset f_time f_prefix f_histfile f_columns f_return f_levelsfile f_tmp_levels f_first
for f_eco_asset in $ECO_ASSETS
do
if [ -z "$f_eco_assets" ]
then
f_eco_assets="ECONOMY-${f_eco_asset}"
else
f_eco_assets="$f_eco_assets ECONOMY-${f_eco_asset}"
fi
done
# get current prices from exchange
get_symbols_ticker
# get values from csv files
for f_asset in $f_asset_histories\
BTC${CURRENCY}\
$f_eco_assets\
MARKETDATA_BINANCE_OPEN_INTEREST_BTC${CURRENCY}\
MARKETDATA_BINANCE_LONG_SHORT_RATIO_TAKER_BTC${CURRENCY}\
MARKETDATA_BINANCE_LONG_SHORT_RATIO_ACCOUNT_BTC${CURRENCY}\
MARKETDATA_FEAR_AND_GREED_ALTERNATIVEME\
MARKETDATA_FEAR_AND_GREED_CNN\
MARKETDATA_US_CONSUMER_PRICE_INDEX_CPI\
MARKETDATA_US_FED_FUNDS_RATE MARKETDATA_US_UNEMPLOYMENT_RATE
do
# read latest ohlcv data and indicators per timeframe to vars
for f_time in 5m 15m 1h 4h 1d 1w
do
# special on ECONOMY data
f_prefix="${f_time}_"
if [[ "$f_asset" =~ ^ECONOMY- ]]
then
f_prefix="${f_asset}_${f_time}_"
f_prefix=${f_prefix//-/_}
fi
# histfile
f_histfile="asset-histories/${f_asset}.history.${f_time}.csv"
if ! [ -s "$f_histfile" ]
then
f_return=1
continue
fi
f_columns="${f_prefix}date,${f_prefix}open,${f_prefix}high,${f_prefix}low,${f_prefix}close,${f_prefix}volume,${f_prefix}change,${f_prefix}ath,${f_prefix}ema12,${f_prefix}ema26,${f_prefix}ema50,${f_prefix}ema100,${f_prefix}ema200,${f_prefix}ema400,${f_prefix}ema800,${f_prefix}rsi5,${f_prefix}rsi14,${f_prefix}rsi21,${f_prefix}macd,${f_prefix}macd_ema9_signal,${f_prefix}macd_histogram,${f_prefix}macd_histogram_signal,${f_prefix}macd_histogram_max,${f_prefix}macd_histogram_strength"
g_read_csv "${f_histfile}" 2 "$f_columns"
done
# read current levels
for f_time in 1w 1d
do
f_levelsfile="asset-histories/${f_asset}.history.${f_time}.csv.levels"
if [ -s "$f_levelsfile" ]
then
# get levels
read -r -a f_levels <"$f_levelsfile"
vr[${f_asset}_levels_$f_time]="${f_levels[*]}"
# add current price and sort
f_levels+=("${vr[${f_asset}_price]}")
oldIFS="$IFS"
IFS=$'\n' f_levels_sorted=($(sort -n <<<"${f_levels[*]}"))
IFS="$oldIFS"
# find current price and +- one for upper lower price
for ((i=0; i<${#f_levels_sorted[@]}; i++)); do
if [ "${f_levels_sorted[$i]}" = "${vr[${f_asset}_price]}" ]
then
vr[${f_asset}_levels_${f_time}_next_up]=${f_levels_sorted[i+1]}
vr[${f_asset}_levels_${f_time}_next_down]=${f_levels_sorted[i-1]}
break
fi
done
fi
done
done
# use reverse as default to be 0 latest, 1 pre latest,...
unset v
declare -Ag v
for key in "${!vr[@]}"; do
v[$key]=${vr[$key]}
done
unset vr
# write values file for overview
for i in "${!v[@]}"
do
echo "\${v[$i]}=${v[$i]}"
done | sort >values.new
mv values.new values
return $f_return
}

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function get_vars_from_csv { function get_vars_from_csv {
unset f_empty_var unset f_empty_var

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function market_performance { function market_performance {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -1,50 +1,112 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function order { function order {
# Info for log # Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# needed vars # needed vars
local f_symbol=$1 local f_symbol=$1
local f_amount=$2 # amount in $CURRENCY / if crypto_amount:XXX then amount in crypto local f_amount=$2 # amount in $CURRENCY / if asset_amount:XXX then amount in invested asset
local f_side=$3 # buy/sell long/short local f_side=$3 # buy/sell long/short
local f_price=$4 # price for limit order - if not given do market order local f_price=$4 # price for limit order - if "0" do market order - "stoploss" for pure StopLoss Order and "takeprofit" for pure TakeProfit Order
local f_params f_type local f_stoploss=$5
local f_takeprofit=$6
local f_params="params={"
local f_type f_side_opposite f_pos_side f_side_opposide f_trigger_sl f_trigger_tp
### validity checks ### ### validity checks ###
if [ -z "$f_symbol" ] || [ -z "$f_amount" ] || [ -z "$f_side" ] || [ -z "$f_price" ]
then
g_echo_error "Missing values!
Usage: order symbol amount side price [stoploss] [takeprofit]
Given: ${FUNCNAME} $@"
return 1
fi
# check symbol XXX/$CURRENCY[:$CURRENCY] # check symbol XXX/$CURRENCY[:$CURRENCY]
[[ $f_symbol =~ /$CURRENCY ]] || return 1 [[ $f_symbol =~ /$CURRENCY ]] || return 1
# check side # check side
[ "$f_side" = "long" ] && f_side="buy" if [ "$f_side" = "long" ] || [ "$f_side" = "buy" ]
[ "$f_side" = "short" ] && f_side="sell" then
f_side="buy"
f_pos_side="Long"
f_side_opposide="sell"
f_trigger_sl="down"
f_trigger_tp="up"
fi
if [ "$f_side" = "short" ] || [ "$f_side" = "sell" ]
then
f_side="sell"
f_pos_side="Short"
f_side_opposide="buy"
f_trigger_sl="up"
f_trigger_tp="down"
fi
[[ $f_side =~ ^buy$|^sell$ ]] || return 1 [[ $f_side =~ ^buy$|^sell$ ]] || return 1
# check order type limit/market # check order type limit/market
if [ -z "$f_price" ] if [[ $f_price = 0 ]]
then then
f_type="market" f_type="market"
f_price=0 elif [[ $f_price = stoploss ]]
then
f_type="stoploss"
f_price="None"
elif [[ $f_price = takeprofit ]]
then
f_type="takeprofit"
f_price="None"
else else
f_type="limit" f_type="limit"
fi fi
### validity checks end### ### validity checks end ###
# get amount in crypto asset
if [[ $f_amount =~ ^crypto_amount: ]] # get amount in target asset
if [[ $f_amount =~ ^asset_amount: ]]
then then
# if given in crypto # if given in target
f_amount=${f_amount//crypto_amount:} f_amount=${f_amount//asset_amount:}
else else
# if given in $CURRENCY # on market order use current price
local f_asset=${f_symbol///*} if [[ $f_type = market ]]
currency_converter $f_amount $CURRENCY $f_asset || return 1 then
local f_amount=$f_currency_converter_result # if given in $CURRENCY
fi local f_asset=${f_symbol///*}
currency_converter $f_amount $CURRENCY $f_asset || return 1
f_amount=$f_currency_converter_result
# on limit order use limit price
elif [[ $f_type = limit ]]
then
g_calc "1/${f_price}*${f_amount}"
f_amount=$g_calc_result
fi
fi
# check for swap/margin trades # check for swap/margin trades
if [ -n "$LEVERAGE" ] if [ -n "$LEVERAGE" ]
then then
# do some margin things # do some margin things
@@ -57,17 +119,108 @@ function order {
# set leverage # set leverage
f_ccxt "$STOCK_EXCHANGE.setLeverage($LEVERAGE, '$f_symbol')" || return 1 f_ccxt "$STOCK_EXCHANGE.setLeverage($LEVERAGE, '$f_symbol')" || return 1
# define margibn mode isolated/cross # define margin mode isolated/cross
f_params="params={'marginMode': '$MARGIN_MODE'}" #[[ $f_type =~ limit|market ]] &&
f_params="${f_params}'marginMode': '$MARGIN_MODE', "
# calculate amount with leverage
if [[ $f_type != stoploss ]] && [[ $f_type != takeprofit ]]
then
g_calc "${f_amount}*${LEVERAGE}"
f_amount=$g_calc_result
fi
else else
# short/sell not possible in spot market # short/sell not possible in spot market
[[ $f_side =~ ^sell$ ]] || return 1 [[ $f_side =~ ^sell$ ]] || return 1
fi fi
# do the order
f_ccxt "print($STOCK_EXCHANGE.createOrder(symbol='${f_symbol}', type='$f_type', price=$f_price, amount='${f_amount}', side='${f_side}', ${f_params}))" || return 1
# refresh positions # Add stoploss and take profit if available
if [ -n "$f_stoploss" ]
then
if [[ $f_type = limit ]]
then
# check for long
if [[ $f_side = buy ]] && g_num_is_higher_equal $f_stoploss $f_price
then
g_echo_warn "Long Order not possible: Stoploss ($f_stoploss) higher then buy price ($f_price)"
return 1
fi
# check for short
if [[ $f_side = sell ]] && g_num_is_lower_equal $f_stoploss $f_price
then
g_echo_warn "Short Order not possible: Stoploss ($f_stoploss) lower then buy price ($f_price)"
return 1
fi
fi
f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_stoploss}))"
f_stoploss=$f_ccxt_result
# market or limit order with stoploss
if [[ $f_type =~ limit|market ]]
then
f_params="${f_params}'stopLoss': { 'triggerPrice': $f_stoploss, 'type': 'market' }, "
# stoploss (change) for open position
elif [[ $f_type = "stoploss" ]]
then
f_type="market"
f_price=$f_stoploss
f_params="${f_params}'reduceOnly': True, 'triggerPrice': $f_stoploss, 'triggerDirection': '$f_trigger_sl', "
fi
fi
if [ -n "$f_takeprofit" ]
then
# check for long
if [[ $f_type = limit ]]
then
if [[ $f_side = buy ]] && g_num_is_lower_equal $f_takeprofit $f_price
then
g_echo_warn "Long Order not possible:TakeProfit ($f_takeprofit) lower then buy price ($f_price)"
return 1
fi
# check for short
if [[ $f_side = sell ]] && g_num_is_higher_equal $f_takeprofit $f_price
then
g_echo_warn "Short Order not possible:TakeProfit ($f_takeprofit) higher then buy price ($f_price)"
return 1
fi
fi
f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_takeprofit}))"
f_takeprofit=$f_ccxt_result
[[ $f_type =~ limit|market ]] && f_params="${f_params}'takeProfit': { 'triggerPrice': $f_takeprofit, 'type': 'limit', 'price': $f_takeprofit, }, "
if [[ $f_type = "takeprofit" ]]
then
f_type="limit"
f_price=$f_takeprofit
f_params="${f_params}'reduceOnly': True, 'triggerPrice': $f_takeprofit, 'triggerDirection': '$f_trigger_tp', "
fi
fi
# end up params syntax with "}"
f_params="${f_params}}"
# calculate price amount precision
f_ccxt "print($STOCK_EXCHANGE.amountToPrecision('${f_symbol}', ${f_amount}))"
f_amount=$f_ccxt_result
if [[ $f_type = limit ]]
then
f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_price}))"
f_price=$f_ccxt_result
fi
# do the order
# market order with or without stoploss/takeprofit
[[ $f_type = limit ]] && local f_order="symbol='${f_symbol}', type='$f_type', price=$f_price, amount=${f_amount}, side='${f_side}', ${f_params}"
[[ $f_type = market ]] && local f_order="symbol='${f_symbol}', type='$f_type', amount=${f_amount}, side='${f_side}', ${f_params}"
# takeprofit/stoploss only
[[ $f_params =~ reduceOnly ]] && local f_order="symbol='${f_symbol}', type='$f_type', amount=${f_amount}, side='${f_side_opposide}', price=$f_price, ${f_params}"
echo "$f_order" | notify.sh -s "ORDER"
f_ccxt "print($STOCK_EXCHANGE.createOrder(${f_order}))" || return 1
# refresh orders and positions
get_orders "$f_symbol"
get_positions get_positions
get_position_array
get_orders_array
} }

View File

@@ -0,0 +1,95 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function order_cancel {
# Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_symbol=$1
local f_order
get_symbols_ticker
get_orders "$f_symbol"
get_orders_array
local f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
if [ -n "${o[${f_asset}_present]}" ]
then
f_ccxt "print(${STOCK_EXCHANGE}.cancelAllOrders('$f_symbol'))"
get_orders "$f_symbol"
get_orders_array
else
g_echo_note "No orders for $f_symbol/$f_asset found"
return 0
fi
}
function order_cancel_all {
# Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_order
get_symbols_ticker
get_orders_array
for f_order in "${f_get_orders_array[@]}"
do
get_order_line_vars "$f_order"
if [[ $f_symbol = $f_order_symbol ]]
then
f_ccxt "print(${STOCK_EXCHANGE}.cancelAllOrders('$f_symbol'))"
get_orders "$f_symbol"
get_orders_array
fi
done
}
function order_cancel_id {
# Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_symbol=$1
local f_id=$2
local f_order
get_symbols_ticker
get_orders "$f_symbol"
get_orders_array
local f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
if grep -q "$f_asset.*$f_id" values-orders
then
f_ccxt "print(${STOCK_EXCHANGE}.cancelOrder(id='${f_id}', symbol='${f_symbol}'))"
get_orders "$f_symbol"
get_orders_array
else
g_echo_note "No orders for $f_symbol/$f_asset with id $f_id found"
return 1
fi
}

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function position_close { function position_close {
# Info for log # Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -0,0 +1,45 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function run_strategies {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_strategy
unset s_score
unset s_SYMBOLS
get_symbols_ticker
get_values ${f_symbols_array_trade[*]}
for f_strategy in $(find /dabo/strategies -type f -name "*.strategy.sh" ! -name "\.*")
do
if ! bash -n "${f_strategy}" >$g_tmp/strat_bash_error 2>&1
then
g_echo_error "Error in ${f_strategy} $(cat $g_tmp/strat_bash_error)"
continue
fi
g_echo_note "Running strategy ${f_strategy}"
. "${f_strategy}" || g_echo_warn "Failed ${f_strategy}"
done
}

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function score { function score {
[ -z "${s_score}" ] && s_score=0 [ -z "${s_score}" ] && s_score=0
#s_score=$((s_score${1})) #s_score=$((s_score${1}))
@@ -7,3 +27,4 @@ function score {
s_score_hist="${s_score_hist} s_score_hist="${s_score_hist}
s_score=${s_score} (${1}) ${2}" s_score=${s_score} (${1}) ${2}"
} }

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function transactions_overview { function transactions_overview {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -7,6 +27,7 @@ function transactions_overview {
get_bitpanda_api_transactions get_bitpanda_api_transactions
get_justtrade_csv_transactions get_justtrade_csv_transactions
get_onetrading_csv_transactions get_onetrading_csv_transactions
get_phemex_csv_transactions
>ALL_TRANSACTIONS_OVERVIEW.csv.tmp >ALL_TRANSACTIONS_OVERVIEW.csv.tmp
>ALL_TRANSACTIONS_OVERVIEW_WARN.csv.tmp >ALL_TRANSACTIONS_OVERVIEW_WARN.csv.tmp
@@ -14,14 +35,18 @@ function transactions_overview {
local f_exchange f_asset f_transactions_array f_transaction f_result f_asset_quantity f_asset_quantity_sold f_currency_quantity f_currency_quantity_sold f_currency_spent f_date f_type f_asset_amount f_currency f_currency_amount f_fee_currency f_fee_amount f_sell_result f_taxable f_tax_type f_one_year_ago f_currency_amount_eur f_currency_spent_eur f_currency_quantity_sold_eur f_note f_asset_quantity_remaining f_currency_remaining f_year f_currency_spent_eur_tax f_currency_quantity_sold_eur_tax f_sell_result_percentage f_sell_result_percentage_eur local f_exchange f_asset f_transactions_array f_transaction f_result f_asset_quantity f_asset_quantity_sold f_currency_quantity f_currency_quantity_sold f_currency_spent f_date f_type f_asset_amount f_currency f_currency_amount f_fee_currency f_fee_amount f_sell_result f_taxable f_tax_type f_one_year_ago f_currency_amount_eur f_currency_spent_eur f_currency_quantity_sold_eur f_note f_asset_quantity_remaining f_currency_remaining f_year f_currency_spent_eur_tax f_currency_quantity_sold_eur_tax f_sell_result_percentage f_sell_result_percentage_eur
f_assets_per_exchange=$(egrep -h -v '^DATE,TYPE,ASSET,ASSET_AMOUNT,CURRENCY,CURRENCY_AMOUNT,EXCHANGE|^#|^$|^ +$' TRANSACTIONS-*.csv | cut -d, -f3,7 | sort -u) f_assets_per_exchange=$(egrep -h -v '^DATE,TYPE,ASSET,ASSET_AMOUNT,CURRENCY,CURRENCY_AMOUNT,EXCHANGE|^#|^$|^ +$' TRANSACTIONS-*.csv | cut -d, -f3,7 | sort -u | grep JustTrade)
for f_asset_per_exchange in ${f_assets_per_exchange} for f_asset_per_exchange in ${f_assets_per_exchange}
do do
mapfile -d, -t f_asset_per_exchange_array < <(echo $f_asset_per_exchange) mapfile -d, -t f_asset_per_exchange_array < <(echo $f_asset_per_exchange)
f_asset=${f_asset_per_exchange_array[0]} f_asset=${f_asset_per_exchange_array[0]}
f_exchange=${f_asset_per_exchange_array[1]%$'\n'} f_exchange=${f_asset_per_exchange_array[1]%$'\n'}
# check values
[ -z "$f_asset" ] && continue
[ -z "$f_exchange" ] && continue
# Ignore stableCoins, EUR, USD # Ignore stableCoins, EUR, USD
[[ $f_asset = USDT ]] && continue [[ $f_asset = USDT ]] && continue
[[ $f_asset = USDC ]] && continue [[ $f_asset = USDC ]] && continue
@@ -46,11 +71,17 @@ function transactions_overview {
mapfile -t f_transactions_array < <(egrep -h -v '^DATE,TYPE,ASSET,ASSET_AMOUNT,CURRENCY,CURRENCY_AMOUNT,EXCHANGE|^#|^$|^ +$' TRANSACTIONS-*.csv | sort -u | egrep ",${f_asset},.+,.+,${f_exchange}" | sort) mapfile -t f_transactions_array < <(egrep -h -v '^DATE,TYPE,ASSET,ASSET_AMOUNT,CURRENCY,CURRENCY_AMOUNT,EXCHANGE|^#|^$|^ +$' TRANSACTIONS-*.csv | sort -u | egrep ",${f_asset},.+,.+,${f_exchange}" | sort)
for f_transaction in "${f_transactions_array[@]}" for f_transaction in "${f_transactions_array[@]}"
do do
g_echo_note "Transaction: $f_transaction"
mapfile -d, -t f_transaction_array < <(echo $f_transaction) mapfile -d, -t f_transaction_array < <(echo $f_transaction)
f_date=${f_transaction_array[0]} f_date=${f_transaction_array[0]}
f_type=${f_transaction_array[1]} f_type=${f_transaction_array[1]}
f_asset_amount=${f_transaction_array[3]} f_asset_amount=${f_transaction_array[3]}
f_currency=${f_transaction_array[4]} f_currency=${f_transaction_array[4]}
if [ -z "$f_currency" ]
then
g_echo_warn "f_currency empty: $f_transaction"
continue
fi
f_currency_amount=${f_transaction_array[5]} f_currency_amount=${f_transaction_array[5]}
f_currency_amount_eur=0 f_currency_amount_eur=0
f_fee_currency=${f_transaction_array[7]} f_fee_currency=${f_transaction_array[7]}
@@ -125,6 +156,7 @@ function transactions_overview {
[[ $f_type =~ stake ]] && continue [[ $f_type =~ stake ]] && continue
# what did I spent on asset in currency # what did I spent on asset in currency
#if [[ $f_type =~ buy|leverage-buy ]]
if [[ $f_type =~ buy|leverage-buy|reward-staking|instant_trade_bonus|giveaway ]] if [[ $f_type =~ buy|leverage-buy|reward-staking|instant_trade_bonus|giveaway ]]
then then
g_calc "$f_currency_spent+$f_currency_amount" g_calc "$f_currency_spent+$f_currency_amount"
@@ -181,7 +213,7 @@ function transactions_overview {
echo "$f_date,$f_exchange,$f_type,$f_asset,$f_asset_amount,$f_currency,$f_currency_amount,$f_one_year_ago,$f_currency_spent,$f_asset_quantity,$f_result,$f_sell_result,$f_tax_type,$f_taxable,$f_currency_amount_eur,$f_result_eur,$f_sell_result_eur,$f_asset_quantity_remaining,$f_note,Sell never buyed!? Spent currency on $f_asset is 0" 1>&2 echo "$f_date,$f_exchange,$f_type,$f_asset,$f_asset_amount,$f_currency,$f_currency_amount,$f_one_year_ago,$f_currency_spent,$f_asset_quantity,$f_result,$f_sell_result,$f_tax_type,$f_taxable,$f_currency_amount_eur,$f_result_eur,$f_sell_result_eur,$f_asset_quantity_remaining,$f_note,Sell never buyed!? Spent currency on $f_asset is 0" 1>&2
continue continue
fi fi
# if sell wahats not exists!? # if sell what not exists!?
if [ $f_asset_quantity = 0 ] if [ $f_asset_quantity = 0 ]
then then
#g_echo_warn "!!!!!! Sell never buyed!? Buyed asset $f_asset is 0" #g_echo_warn "!!!!!! Sell never buyed!? Buyed asset $f_asset is 0"
@@ -209,6 +241,7 @@ function transactions_overview {
## Check for ended trade (asset-quantity=0 or tttt) ## Check for ended trade (asset-quantity=0 or tttt)
# if all is sold trade ended and calculate PNL # if all is sold trade ended and calculate PNL
local f_trade_end=0 local f_trade_end=0
local f_trade_partial_end=0
local f_dust=0 local f_dust=0
local f_dust_eur=0 local f_dust_eur=0
g_calc "$f_asset_quantity_sold==$f_asset_quantity" g_calc "$f_asset_quantity_sold==$f_asset_quantity"
@@ -244,10 +277,11 @@ function transactions_overview {
else else
g_echo_note "Tade not closed - partial sale!? Remaining $f_asset_quantity_remaining $f_asset ($f_currency_remaining $f_currency)!?" >>ALL_TRANSACTIONS_OVERVIEW.log g_echo_note "Tade not closed - partial sale!? Remaining $f_asset_quantity_remaining $f_asset ($f_currency_remaining $f_currency)!?" >>ALL_TRANSACTIONS_OVERVIEW.log
f_note="Trade not closed - partial sale. Remaining $f_asset_quantity_remaining $f_asset ($f_currency_remaining $f_currency)" f_note="Trade not closed - partial sale. Remaining $f_asset_quantity_remaining $f_asset ($f_currency_remaining $f_currency)"
f_trade_partial_end=1
fi fi
fi fi
if [ ${f_trade_end} -eq 1 ] if [ ${f_trade_end} -eq 1 ] || [ ${f_trade_partial_end} -eq 1 ]
then then
echo "Buy price: $f_currency_spent $f_currency ($f_currency_spent_eur EUR)" >>ALL_TRANSACTIONS_OVERVIEW.log echo "Buy price: $f_currency_spent $f_currency ($f_currency_spent_eur EUR)" >>ALL_TRANSACTIONS_OVERVIEW.log
@@ -273,17 +307,20 @@ function transactions_overview {
# calculate complete result EUR # calculate complete result EUR
g_calc "$f_result_eur+($f_sell_result_eur)" g_calc "$f_result_eur+($f_sell_result_eur)"
f_result_eur=$g_calc_result f_result_eur=$g_calc_result
# reset vars if [ ${f_trade_end} -eq 1 ]
f_asset_quantity=0 then
f_asset_quantity_sold=0 # reset vars
f_asset_quantity_remaining=0 f_asset_quantity=0
f_currency_spent=0 f_asset_quantity_sold=0
printf -v f_currency_spent_eur_tax %.2f $f_currency_spent_eur f_asset_quantity_remaining=0
f_currency_spent_eur=0 f_currency_spent=0
f_currency_quantity_sold=0 printf -v f_currency_spent_eur_tax %.2f $f_currency_spent_eur
printf -v f_currency_quantity_sold_eur_tax %.2f $f_currency_quantity_sold_eur f_currency_spent_eur=0
f_currency_quantity_sold_eur=0 f_currency_quantity_sold=0
printf -v f_currency_quantity_sold_eur_tax %.2f $f_currency_quantity_sold_eur
f_currency_quantity_sold_eur=0
fi
fi fi
# at leverage always full taxable # at leverage always full taxable
@@ -344,6 +381,7 @@ function transactions_overview {
## completely tax free if over 1 year ## completely tax free if over 1 year
f_taxable=0 f_taxable=0
f_one_year_ago="yes" f_one_year_ago="yes"
f_tax_type="Kauf >1 Jahr zurück"
# reduce tax free volume # reduce tax free volume
g_calc "$f_asset_amount_tax_free-$f_asset_amount" g_calc "$f_asset_amount_tax_free-$f_asset_amount"
f_asset_amount_tax_free=$g_calc_result f_asset_amount_tax_free=$g_calc_result
@@ -407,6 +445,8 @@ function transactions_overview {
# 24 f_sell_result_percentage_eur # 24 f_sell_result_percentage_eur
echo "$f_date,$f_exchange,$f_type,$f_asset,$f_asset_amount,$f_currency,$f_currency_amount,$f_one_year_ago,$f_currency_spent,$f_asset_quantity,$f_result,$f_sell_result,$f_tax_type,$f_taxable,$f_currency_amount_eur,$f_result_eur,$f_sell_result_eur,$f_asset_quantity_remaining,$f_note,$f_currency_spent_eur,$f_currency_quantity_sold,$f_currency_quantity_sold_eur,$f_sell_result_percentage,$f_sell_result_percentage_eur" | tee -a ALL_TRANSACTIONS_OVERVIEW.csv.tmp >>ALL_TRANSACTIONS_OVERVIEW.log echo "$f_date,$f_exchange,$f_type,$f_asset,$f_asset_amount,$f_currency,$f_currency_amount,$f_one_year_ago,$f_currency_spent,$f_asset_quantity,$f_result,$f_sell_result,$f_tax_type,$f_taxable,$f_currency_amount_eur,$f_result_eur,$f_sell_result_eur,$f_asset_quantity_remaining,$f_note,$f_currency_spent_eur,$f_currency_quantity_sold,$f_currency_quantity_sold_eur,$f_sell_result_percentage,$f_sell_result_percentage_eur" | tee -a ALL_TRANSACTIONS_OVERVIEW.csv.tmp >>ALL_TRANSACTIONS_OVERVIEW.log
echo "$f_date,$f_exchange,$f_type,$f_asset,$f_asset_amount,$f_currency,$f_currency_amount,$f_one_year_ago,$f_currency_spent,$f_asset_quantity,$f_result,$f_sell_result,$f_tax_type,$f_taxable,$f_currency_amount_eur,$f_result_eur,$f_sell_result_eur,$f_asset_quantity_remaining,$f_note,$f_currency_spent_eur,$f_currency_quantity_sold,$f_currency_quantity_sold_eur,$f_sell_result_percentage,$f_sell_result_percentage_eur"
if [[ $f_type =~ sell|leverage-sell ]] if [[ $f_type =~ sell|leverage-sell ]]
then then
echo -e "\n" >>ALL_TRANSACTIONS_OVERVIEW.log echo -e "\n" >>ALL_TRANSACTIONS_OVERVIEW.log

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function watch_assets { function watch_assets {
local f_watch_assets_array local f_watch_assets_array

View File

@@ -1,9 +1,30 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function webpage { function webpage {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
charts
webpage_transactions webpage_transactions
get_symbols_ticker
charts
# create status webpage # create status webpage
echo "<html> echo "<html>
@@ -19,9 +40,7 @@ function webpage {
<h1>State of Dabo-Bot! on ${STOCK_EXCHANGE} - ${URL} (ReadOnly)</h1> <h1>State of Dabo-Bot! on ${STOCK_EXCHANGE} - ${URL} (ReadOnly)</h1>
<h1>Last update $(date '+%F %T')</h1>" >../index.html.tmp <h1>Last update $(date '+%F %T')</h1>" >../index.html.tmp
# historic overview # balance
echo '<a href=TRANSACTIONS_OVERVIEWS.html><h2>Historic Overview</h2></a>' >>../index.html.tmp
local f_USED_BALANCE=$(tail -n1 "asset-histories/BALANCEUSED${CURRENCY}.history.csv" | cut -d, -f2) local f_USED_BALANCE=$(tail -n1 "asset-histories/BALANCEUSED${CURRENCY}.history.csv" | cut -d, -f2)
local f_COMPLETE_BALANCE=$(tail -n1 "asset-histories/BALANCECOMPLETE${CURRENCY}.history.csv" | cut -d, -f2) local f_COMPLETE_BALANCE=$(tail -n1 "asset-histories/BALANCECOMPLETE${CURRENCY}.history.csv" | cut -d, -f2)
g_calc "$f_COMPLETE_BALANCE-$f_USED_BALANCE" g_calc "$f_COMPLETE_BALANCE-$f_USED_BALANCE"
@@ -43,7 +62,7 @@ function webpage {
</table>" >>../index.html.tmp </table>" >>../index.html.tmp
echo "<h2>Balance in- outflows</h2>" >>../index.html.tmp echo "<h2>Balance in- outflows</h2>" >>../index.html.tmp
echo "<table><tr><td><b>Time ago</b><td><b>Balance</b></td><td><b>in/out</b></td><td><b>Percentage</b></td></tr>" >> ../index.html.tmp echo "<table><tr class=\"headline\"><td><b>Time ago</b><td><b>Balance</b></td><td><b>in/out</b></td><td><b>Percentage</b></td></tr>" >> ../index.html.tmp
for f_balance_date in Day Week Month 3Month Year for f_balance_date in Day Week Month 3Month Year
do do
@@ -62,23 +81,73 @@ function webpage {
echo '<h2>Open Positions</h2>' >>../index.html.tmp echo '<h2>Open Positions</h2>' >>../index.html.tmp
echo "<table width='100%'><tr><td>Symbol</td><td>Amount</td><td>Entry Price</td><td>Current Price</td><td>Profit/Loss</td><td>Notes</td></tr>" >>../index.html.tmp echo "<table width='100%'><tr class=\"headline\"><td>Symbol</td><td>Amount</td><td>Entry Price</td><td>Current Price</td><td>Profit/Loss</td><td>Liquidation Price</td><td>StopLoss</td><td>TakeProfit</td><td>Notes</td></tr>" >>../index.html.tmp
get_position_array get_position_array
for f_position in "${f_get_positions_array[@]}" for f_symbol in ${f_symbols_array_trade[@]}
do do
get_position_line_vars "$f_position" f_asset=${f_symbol//:$CURRENCY/}
printf -v f_position_currency_amount %.2f $f_position_currency_amount f_asset=${f_asset//\//}
printf -v f_position_entry_price %.2f $f_position_entry_price [ -z "${p[${f_asset}_entry_price]}" ] && continue
printf -v f_position_current_price %.2f $f_position_current_price echo "<tr>
printf -v f_position_pnl %.2f $f_position_pnl <td><a href=\"charts.html?symbol=${f_asset}&time=4h&symbol2=BTCUSDT\" target=\"_blank\" rel=\"noopener noreferrer\">$f_symbol</a></td>
echo "<tr><td>$f_position_symbol</td><td>${CURRENCY} $f_position_currency_amount</td><td>${CURRENCY} $f_position_entry_price</td><td>${CURRENCY} $f_position_current_price</td><td>${CURRENCY} $f_position_pnl ( ${f_position_pnl_percentage}%)</td><td>$f_position_side ${f_position_leverage}x</td></tr>" >>../index.html.tmp <td>${p[${f_asset}_currency_amount]}</td>
<td>${p[${f_asset}_entry_price]}</td>
<td>${p[${f_asset}_current_price]}</td>
<td>${p[${f_asset}_pnl]} ( ${p[${f_asset}_pnl_percentage]}%)</td>
<td>${p[${f_asset}_liquidation_price]}</td>
<td>${p[${f_asset}_stoploss_price]}</td>
<td>${p[${f_asset}_takeprofit_price]}</td>
<td>${p[${f_asset}_side]} ${p[${f_asset}_leverage]}x</td>
</tr>" >>../index.html.tmp
done done
echo "</table>" >>../index.html.tmp echo "</table>" >>../index.html.tmp
echo '<h2>Open Orders</h2>' >>../index.html.tmp
echo "<table width='100%'><tr class=\"headline\"><td>Symbol</td><td>Amount</td><td>Entry Price</td><td>StopLoss</td><td>TakeProfit</td><td>Notes</td></tr>" >>../index.html.tmp
get_orders_array
local f_type
for f_symbol in ${f_symbols_array_trade[@]}
do
f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
for f_type in ${o[${f_asset}_present]}
do
[ -z "${o[${f_asset}_${f_type}_entry_price]}" ] && continue
[ "${o[${f_asset}_${f_type}_entry_price]}" = "null" ] && continue
echo "<tr>
<td><a href=\"charts.html?symbol=${f_asset}&time=4h&symbol2=BTCUSDT\" target=\"_blank\" rel=\"noopener noreferrer\">$f_symbol</a></td>
<td>${o[${f_asset}_${f_type}_amount]}</td>
<td>${o[${f_asset}_${f_type}_entry_price]}</td>
<td>${o[${f_asset}_${f_type}_stoplossprice]}</td>
<td>${o[${f_asset}_${f_type}_takeprofitprice]}</td>
<td>${o[${f_asset}_${f_type}_type]} ${p[${f_asset}_${f_type}_side]}</td>
</tr>" >>../index.html.tmp
done
done
echo "</table>" >>../index.html.tmp
## charts
echo '<h2>Charts with local data</h2><p>Click on time units to open chart</p>' >>../index.html.tmp
local eco_assets=$(echo " $ECO_ASSETS" | sed 's/ / ECONOMY-/g')
for f_symbol in ${f_symbols_array_trade[@]} $eco_assets
do
f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
echo "$f_asset: " >>../index.html.tmp
for f_timeframe in 1w 1d 4h 1h 15m
do
echo "<td><a href=\"charts.html?symbol=${f_asset}&time=${f_timeframe}&symbol2=BTCUSDT\" target=\"_blank\" rel=\"noopener noreferrer\"}>${f_timeframe}</a>" >>../index.html.tmp
done
echo "<br>" >>../index.html.tmp
done
## Open Positions ## Open Positions
echo "<h2>Open Positions - From Trade Histories (daily refresh only)</h2>" >>../index.html.tmp echo "<h2>Open Positions - from other Exchanges</h2>
<p>Crypto-Only from Bitpanda and JustTrade - daily refresh</p>" >>../index.html.tmp
echo "<table width='100%'>" >>../index.html.tmp echo "<table width='100%'>" >>../index.html.tmp
echo "<tr><td>Amount</td><td>Spent Amount</td><td>Sold Amount</td><td>Profit/Loss</td><td>Asset Amount</td><td>Exchange</td></tr>" >>../index.html.tmp echo "<tr class=\"headline\"><td>Date</td><td>Amount</td><td>Spent Amount</td><td>Sold Amount</td><td>Profit/Loss</td><td>Asset Amount</td><td>Exchange</td></tr>" >>../index.html.tmp
rm -f ../index.html.tmp.tmp rm -f ../index.html.tmp.tmp
local f_result_complete=0 local f_result_complete=0
local f_spent_complete=0 local f_spent_complete=0
@@ -86,20 +155,19 @@ function webpage {
local f_sold_complete=0 local f_sold_complete=0
local f_result_percent_complete=0 local f_result_percent_complete=0
local f_asset f_exchange f_amount f_spent f_sold f_currency_amount f_result_percent local f_asset f_exchange f_amount f_spent f_sold f_currency_amount f_result_percent
if [ -s ALL_TRANSACTIONS_OVERVIEW.csv ] for f_asset_per_exchange in $(cat ALL_TRANSACTIONS_OVERVIEW.csv 2>/dev/null | cut -d, -f2,4 | sort -u)
then
for f_asset_per_exchange in $(cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d, -f2,4 | sort -u)
do do
mapfile -d, -t f_asset_per_exchange_array < <(echo $f_asset_per_exchange) mapfile -d, -t f_asset_per_exchange_array < <(echo $f_asset_per_exchange)
f_asset=${f_asset_per_exchange_array[1]%$'\n'} f_asset=${f_asset_per_exchange_array[1]%$'\n'}
f_exchange=${f_asset_per_exchange_array[0]} f_exchange=${f_asset_per_exchange_array[0]}
[[ "$f_exchange" =~ JustTrade|Bitpanda ]] || continue [[ "$f_exchange" =~ JustTrade|Bitpanda ]] || continue
f_date=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f1)
f_amount=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f18) f_amount=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f18)
f_spent=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f20) f_spent=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f20)
f_sold=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f22) f_sold=$(egrep "$f_exchange,.+,$f_asset" ALL_TRANSACTIONS_OVERVIEW.csv | tail -n1 | cut -d, -f22)
if ! [ "$f_amount" = 0 ] if ! [ "$f_amount" = 0 ]
then then
currency_converter $f_amount $f_asset $TRANSFER_CURRENCY || continue currency_converter "$f_amount" "$f_asset" "$TRANSFER_CURRENCY" || continue
f_currency_amount=$f_currency_converter_result f_currency_amount=$f_currency_converter_result
g_calc "$f_currency_amount+($f_sold)" g_calc "$f_currency_amount+($f_sold)"
#f_currency_amount=$g_calc_result #f_currency_amount=$g_calc_result
@@ -136,60 +204,33 @@ function webpage {
#f_sold_complete=$g_calc_result #f_sold_complete=$g_calc_result
printf -v f_sold_complete %.2f $g_calc_result printf -v f_sold_complete %.2f $g_calc_result
echo "<tr><td>$f_currency_amount $TRANSFER_CURRENCY</td><td>$f_spent $TRANSFER_CURRENCY</td><td>$f_sold $TRANSFER_CURRENCY</td><td>$f_result $TRANSFER_CURRENCY ( ${f_result_percent}%)</td><td>$f_amount $f_asset</td><td>$f_exchange</td></tr>" >>../index.html.tmp.tmp echo "<tr><td>$f_date</td><td>$f_currency_amount $TRANSFER_CURRENCY</td><td>$f_spent $TRANSFER_CURRENCY</td><td>$f_sold $TRANSFER_CURRENCY</td><td>$f_result $TRANSFER_CURRENCY ( ${f_result_percent}%)</td><td>$f_amount $f_asset</td><td>$f_exchange</td></tr>" >>../index.html.tmp.tmp
fi fi
done done
g_percentage-diff $f_spent_complete $f_currency_amount_complete g_percentage-diff $f_spent_complete $f_currency_amount_complete
f_result_percent_complete=$g_percentage_diff_result f_result_percent_complete=$g_percentage_diff_result
# ALL Line
echo "<tr><td>-</td><td>$f_currency_amount_complete $TRANSFER_CURRENCY</td><td>$f_spent_complete $TRANSFER_CURRENCY</td><td>$f_sold_complete $TRANSFER_CURRENCY</td><td>$f_result_complete $TRANSFER_CURRENCY ( ${f_result_percent_complete}%)</td><td>ALL</td><td>ALL</td></tr>" >>../index.html.tmp
echo "<tr><td>$f_currency_amount_complete $TRANSFER_CURRENCY</td><td>$f_spent_complete $TRANSFER_CURRENCY</td><td>$f_sold_complete $TRANSFER_CURRENCY</td><td>$f_result_complete $TRANSFER_CURRENCY ( ${f_result_percent_complete}%)</td><td>ALL</td><td>ALL</td></tr>" >>../index.html.tmp # Sort by Spent Amount
sort -n -k3 -t'>' -r ../index.html.tmp.tmp >>../index.html.tmp sort -n -k7 -t'>' -r ../index.html.tmp.tmp >>../index.html.tmp
rm ../index.html.tmp.tmp rm ../index.html.tmp.tmp
echo "</table>" >>../index.html.tmp echo "</table>" >>../index.html.tmp
fi
echo "<h2>Market Performance ( $(cat MARKET_PERFORMANCE_LATEST)%)</h2>" >>../index.html.tmp # Closed positions
#echo "<table width='100%'><tr><td><details><summary>Charts</summary>" >>../index.html.tmp echo "<h2>Closed Positions and (german) tax declaration notes</h2>" >>../index.html.tmp
echo "<details><summary>Charts</summary>" >>../index.html.tmp ls ../TRANSACTIONS_OVERVIEW-* | while read f_html
echo "Krypto" >>../index.html.tmp
genchart MARKET_PERFORMANCE.csv 50 2,3,4,5,6,7 red-or-green,gold,royalblue,lightyellow,MediumSlateBlue,Sienna >>../index.html.tmp
echo "Commodities" >>../index.html.tmp
genchart MARKET_PERFORMANCE.csv 50 2,12,10,13 red-or-green,gold,SandyBrown,Sienna >>../index.html.tmp
echo "World Economic data" >>../index.html.tmp
genchart MARKET_PERFORMANCE.csv 50 2,11,15 red-or-green,Yellow,Sienna >>../index.html.tmp
echo "US Economic data" >>../index.html.tmp
genchart MARKET_PERFORMANCE.csv 50 2,8,17,16,18,19,20,21,14,9 red-or-green,OliveDrab,Yellow,Orange,DeepSkyBlue,DarkMagenta,PeachPuff,PaleTurquoise,Pink,PapayaWhip >>../index.html.tmp
#echo "</details></td></tr></table>" >>../index.html.tmp
echo "</details>" >>../index.html.tmp
echo "<details><summary>Table</summary><table width='100%'>" >>../index.html.tmp
echo "<tr>" >>../index.html.tmp
head -n1 MARKET_PERFORMANCE.csv | perl -pe 's/,/\n/g' | tr [:lower:] [:upper:] | while read f_mperfcol
do do
echo "<td><b>${f_mperfcol}</b></td>" >>../index.html.tmp f_html=$(basename $f_html)
done f_name=$(echo $f_html | cut -d- -f2,3 | cut -d. -f1)
echo "</tr>" >>../index.html.tmp echo "<a href='${f_html}'>$f_name</a><br>" >>../index.html.tmp
egrep "^[0-9][0-9]" MARKET_PERFORMANCE.csv | tail -n10 | while read f_mperfline
do
f_mperfline="$(echo ${f_mperfline} | perl -pe 's/ /_/g; s/,/ /g')"
echo "<tr>" >>../index.html.tmp
#echo "${mperfline}" | perl -pe 's/,/\n/g' | while read f_mperfcol
for f_mperfcol in ${f_mperfline}
do
if echo "${f_mperfcol}" | grep -q ":"
then
f_mperfcol="$(echo ${f_mperfcol} | perl -pe 's/_/ /')"
echo "<td><b>${f_mperfcol}</b></td>" >>../index.html.tmp
else
echo "<td> ${f_mperfcol}%</td>" >>../index.html.tmp
fi
done
echo "</tr>" >>../index.html.tmp
done done
echo "$(cat ALL_TRANSACTIONS_OVERVIEW_WARN.csv | cut -d, -f1,2,20)<br>" >>../index.html.tmp
echo "</table></details>" >>../index.html.tmp # THE END
echo "<a href=\"botdata/MARKET_PERFORMANCE.csv\">Complete list</a>" >>../index.html.tmp echo "</body></html>" >>../index.html.tmp
# color magic # color magic
cat ../index.html.tmp | perl -pe 's/ (\-[0-9]+\.[0-9]+\%)/<font color=red>$1<\/font>/g; s/ ([0-9]+\.[0-9]+\%)/<font color=green>$1<\/font>/g;' >../index.html cat ../index.html.tmp | perl -pe 's/ (\-[0-9]+\.[0-9]+\%)/<font color=red>$1<\/font>/g; s/ ([0-9]+\.[0-9]+\%)/<font color=green>$1<\/font>/g;' >../index.html

View File

@@ -1,3 +1,23 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
function webpage_transactions { function webpage_transactions {
# calculate totals from csv # calculate totals from csv
@@ -7,7 +27,7 @@ function webpage_transactions {
#echo -e "\n\n========== Total Results ===========" #echo -e "\n\n========== Total Results ==========="
##echo "Trade Result: $f_trade_result EUR" #echo "Trade Result: $f_trade_result EUR"
#echo "Staking Result: $f_staking_rewards EUR" #echo "Staking Result: $f_staking_rewards EUR"
#echo "Giveaway Result: $f_giveaway EUR" #echo "Giveaway Result: $f_giveaway EUR"
#echo -e "Instand Trade Bonus: $f_instant_trade_bonus EUR\n" #echo -e "Instand Trade Bonus: $f_instant_trade_bonus EUR\n"
@@ -17,15 +37,16 @@ function webpage_transactions {
local f_tax_year local f_tax_year
cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d- -f1 | sort -u | while read f_tax_year cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d- -f1 | sort -u | while read f_tax_year
do do
echo "========== Tax year $f_tax_year (German Tax Law) ==========" #echo "========== Tax year $f_tax_year (German Tax Law) =========="
local f_exchange_tax_type local f_exchange_tax_type
cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13 | sort -u | egrep -v ',$' | grep -v "Note: " | while read f_exchange_tax_type cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13 | sort -u | egrep -v ',$' | grep -v "Note: " | while read f_exchange_tax_type
do do
#echo "$f_exchange_tax_type"
local f_exchange=$(echo $f_exchange_tax_type | cut -d, -f1) local f_exchange=$(echo $f_exchange_tax_type | cut -d, -f1)
local f_tax_type=$(echo $f_exchange_tax_type | cut -d, -f2) local f_tax_type=$(echo $f_exchange_tax_type | cut -d, -f2)
local f_tax=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13,14 | egrep -v ',,0$' | grep "$f_exchange_tax_type" | cut -d, -f3 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }") local f_tax=$(cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^$f_tax_year-" | cut -d, -f 2,13,14 | egrep -v ',,0$' | grep "$f_exchange_tax_type" | cut -d, -f3 | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM) }")
echo "$f_exchange_tax_type: $f_tax" #echo "$f_exchange_tax_type: $f_tax"
echo "$f_tax_type: $f_tax EUR<br>" >>${g_tmp}/tax_summary_$f_exchange-$f_tax_year echo "$f_tax_type: $f_tax EUR<br>" >>${g_tmp}/tax_summary_$f_exchange-$f_tax_year
@@ -50,14 +71,14 @@ $(cat ${g_tmp}/tax_summary_$f_exchange-$f_tax_year)
<tr><td>Date</td><td>Type of transaction</td><td>Crypto value</td><td>Fiat value</td><td>Result</td><td>Tax type</td><td>Tax amount</td></tr> <tr><td>Date</td><td>Type of transaction</td><td>Crypto value</td><td>Fiat value</td><td>Result</td><td>Tax type</td><td>Tax amount</td></tr>
" >TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp " >TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^${f_tax_year}-" | grep ",${f_exchange}," | awk -F, ' cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^${f_tax_year}-" | grep ",${f_exchange}," | awk -F, '
{printf "<tr><td>"$1"</td><td>"$3"</td><td>"$5" "$4"</td><td>"} {
{printf("%.2f", $15)} printf "<tr><td>%s</td><td>%s</td><td>%s %s</td><td>%.2f EUR</td><td>", $1, $3, $5, $4, $15
{printf " EUR </td><td>"} if ($17 != "") {
{printf("%.2f", $17)} printf "%.2f EUR", $17
{printf " EUR</td><td>"$13"</td><td>"} }
{printf("%.2f", $14)} printf "</td><td>%s</td><td>%.2f EUR</td></tr>\n", $13, $14
{print " EUR</td></tr>"}' >>TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp }' >>TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
echo "</table></body></html>" >>TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp echo "</table></body></html>" >>TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
mv TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp ../TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html mv TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp ../TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html
@@ -65,34 +86,8 @@ $(cat ${g_tmp}/tax_summary_$f_exchange-$f_tax_year)
done done
echo "" #echo ""
done done
## Overview over Overviews
echo "<html>
<head>
<meta charset='UTF-8'>
<meta http-equiv='refresh' content='${INTERVAL}'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' href='/browser.css'>
<link rel='stylesheet' type='text/css' href='/charts.min.css'>
<title>Trading Overview</title>
</head>
<body>
<h1>Transaction Overviews</h1>" >../TRANSACTIONS_OVERVIEWS.html
local f_html f_name
ls ../TRANSACTIONS_OVERVIEW-* | while read f_html
do
f_html=$(basename $f_html)
f_name=$(echo $f_html | cut -d- -f2,3 | cut -d. -f1)
echo "<a href='${f_html}'>$f_name</a><br>" >>../TRANSACTIONS_OVERVIEWS.html
done
echo "$(cat ALL_TRANSACTIONS_OVERVIEW_WARN.csv | cut -d, -f1,2,20)<br>" >>../TRANSACTIONS_OVERVIEWS.html
echo "</body></html>" >>../TRANSACTIONS_OVERVIEWS.html
} }

View File

@@ -1,4 +1,23 @@
#!/bin/bash -e #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /etc/bash/gaboshlib.include . /etc/bash/gaboshlib.include

View File

@@ -1,4 +1,23 @@
#!/bin/bash -e #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
. /etc/bash/gaboshlib.include . /etc/bash/gaboshlib.include

View File

@@ -1,4 +1,23 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
mkdir final mkdir final
ls -1 *.history.csv | while read x ls -1 *.history.csv | while read x
do do

View File

@@ -86,63 +86,6 @@ a[id^="btn"] { background-color:#111111; cursor:pointer; display:inline-block; f
a[id^="btn"]:last-child { margin-left:-4px; } a[id^="btn"]:last-child { margin-left:-4px; }
a[id^="btn"]::-moz-focus-inner { border:0; padding:0; } a[id^="btn"]::-moz-focus-inner { border:0; padding:0; }
/* Chrome / Android / Tablet
html[data-useragent*="Chrome"][data-useragent*="Android"] body { color:#373837; }
html[data-useragent*="Chrome"][data-useragent*="Android"] audio { margin-left:4px; width:689px; }
html[data-useragent*="Chrome"][data-useragent*="Android"] #audiowrap { background-color:#fafafa; }
html[data-useragent*="Chrome"][data-useragent*="Android"] a[id^="btn"] { background-color:#fafafa; color:#373837; }
html[data-useragent*="Chrome"][data-useragent*="Android"] a[id^="btn"]:hover { background-color:#eee; }
html[data-useragent*="Chrome"][data-useragent*="Android"] #plList li { background-color:#fafafa; }
html[data-useragent*="Chrome"][data-useragent*="Android"] #plList li:hover { background-color:#eee; }
html[data-useragent*="Chrome"][data-useragent*="Android"] .plSel,
html[data-useragent*="Chrome"][data-useragent*="Android"] .plSel:hover { background-color:#eee!important; }
*/
/* Audio Player Media Queries
================================================== */
/* Tablet Portrait
@media only screen and (min-width: 768px) and (max-width: 959px) {
audio { width:526px; }
html[data-useragent*="MSIE 9.0"] audio { width:536px; }
html[data-useragent*="MSIE 10.0"] audio { width:543px; }
html[data-useragent*="rv:11.0"] audio { width:551px; }
html[data-useragent*="OS 7"] audio { width:546px; }
html[data-useragent*="OS 8"] audio { width:550px; }
html[data-useragent*="OS 9"] audio { width:550px; }
html[data-useragent*="Chrome"] audio { width:533px; }
html[data-useragent*="Chrome"][data-useragent*="Android"] audio { margin-left:4px; width:545px; }
}
/* Mobile Landscape
@media only screen and (min-width: 480px) and (max-width: 767px) {
audio { width:390px; }
html[data-useragent*="MSIE 9.0"] audio { width:400px; }
html[data-useragent*="MSIE 10.0"] audio { width:407px; }
html[data-useragent*="rv:11.0"] audio { width:415px; }
html[data-useragent*="OS 7"] audio { width:410px; }
html[data-useragent*="OS 8"] audio { width:414px; }
html[data-useragent*="OS 9"] audio { width:414px; }
html[data-useragent*="Chrome"] audio { width:397px; }
html[data-useragent*="Chrome"][data-useragent*="Mobile"] audio { margin-left:4px; width:410px; }
#npTitle { width:245px; }
}
/* Mobile Portrait
@media only screen and (max-width: 479px) {
audio { width:270px; }
html[data-useragent*="MSIE 9.0"] audio { width:280px; }
html[data-useragent*="MSIE 10.0"] audio { width:287px; }
html[data-useragent*="rv:11.0"] audio { width:295px; }
html[data-useragent*="OS 7"] audio { width:290px; }
html[data-useragent*="OS 8"] audio { width:294px; }
html[data-useragent*="OS 9"] audio { width:294px; }
html[data-useragent*="Chrome"] audio { width:277px; }
html[data-useragent*="Chrome"][data-useragent*="Mobile"] audio { margin-left:4px; width:290px; }
#npTitle { width:167px; }
}
*/
audio { width:92%; } audio { width:92%; }
/* for VPN Login */ /* for VPN Login */
@@ -173,12 +116,20 @@ pre,#footer {
font:16px sans-serif; font:16px sans-serif;
} }
.headline {
font-size:18px;
background-color: #808080;
font-weight: bold;
color: black;
}
.statusok { .statusok {
font:18px sans-serif; font:18px sans-serif;
background-color: #00BF40; background-color: #00BF40;
color: black; color: black;
} }
.statusnok { .statusnok {
font:18px sans-serif; font:18px sans-serif;
background-color: #E10020; background-color: #E10020;

View File

@@ -1,6 +1,7 @@
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const symbol = urlParams.get('symbol'); const symbol = urlParams.get('symbol');
const time = urlParams.get('time'); const time = urlParams.get('time');
const symbol2 = urlParams.get('symbol2');
const heightrsimacdchart = 100 const heightrsimacdchart = 100
@@ -81,7 +82,7 @@ const chart = LightweightCharts.createChart(document.getElementById('container')
type: 'solid', type: 'solid',
color: '#222', color: '#222',
}, },
textColor: '#DDD', textColor: '#DDD',
}, },
grid: { grid: {
@@ -163,7 +164,6 @@ const chartmacd = LightweightCharts.createChart(document.getElementById("contain
}, },
height: heightrsimacdchart, height: heightrsimacdchart,
timeScale: { timeScale: {
timeVisible: true, timeVisible: true,
secondsVisible: false, secondsVisible: false,
@@ -306,10 +306,10 @@ fetch("/botdata/asset-histories/" + symbol + ".history." + time + ".csv", { cach
// Lines for price levels // Lines for price levels
fetch("/botdata/asset-histories/" + symbol + ".history.csv.levels", { cache: 'no-store' }) fetch("/botdata/asset-histories/" + symbol + ".history." + time + ".csv.levels", { cache: 'no-store' })
.then(response => response.text()) .then(response => response.text())
.then(text => { .then(text => {
const levels = text.split('\n'); const levels = text.split(' ');
levels.forEach(function(level) { levels.forEach(function(level) {
candleSeries.createPriceLine({price: level, color: "blue", lineWidth: 0.5, lineStyle: 3, axisLabelVisible: true, title: 'Level'}); candleSeries.createPriceLine({price: level, color: "blue", lineWidth: 0.5, lineStyle: 3, axisLabelVisible: true, title: 'Level'});
}); });
@@ -362,7 +362,7 @@ DXYchart.applyOptions({
horzAlign: 'top', horzAlign: 'top',
vertAlign: 'left', vertAlign: 'left',
color: '#DDD', color: '#DDD',
text: "DXY" + time, text: symbol2 + " " + time,
} }
}); });
@@ -415,7 +415,7 @@ const DXYlineSeriesRSI5 = DXYchartrsi.addLineSeries({ color: 'orange', lineWidth
const DXYlineSeriesRSI14 = DXYchartrsi.addLineSeries({ color: 'yellow', lineWidth: 2, priceLineVisible: false, title: 'RSI14'}); const DXYlineSeriesRSI14 = DXYchartrsi.addLineSeries({ color: 'yellow', lineWidth: 2, priceLineVisible: false, title: 'RSI14'});
const DXYlineSeriesRSI21 = DXYchartrsi.addLineSeries({ color: 'lightgreen', lineWidth: 1, lineStyle: 2, priceLineVisible: false, title: 'RSI21'}); const DXYlineSeriesRSI21 = DXYchartrsi.addLineSeries({ color: 'lightgreen', lineWidth: 1, lineStyle: 2, priceLineVisible: false, title: 'RSI21'});
fetch("/botdata/asset-histories/ECONOMY-DXY.history." + time + ".csv", { cache: 'no-store' }) fetch("/botdata/asset-histories/" + symbol2 + ".history." + time + ".csv", { cache: 'no-store' })
.then(response => response.text()) .then(response => response.text())
.then(data => { .then(data => {
const DYXparsedData = parseCSV(data); const DYXparsedData = parseCSV(data);
@@ -540,6 +540,3 @@ DXYchart.subscribeCrosshairMove(param => {
const dataPointmacd = getCrosshairDataPoint(DXYlineSeriesEMA50, param); const dataPointmacd = getCrosshairDataPoint(DXYlineSeriesEMA50, param);
syncCrosshair(chartmacd, lineSeriesMACD, dataPointrsi); syncCrosshair(chartmacd, lineSeriesMACD, dataPointrsi);
}); });

View File

@@ -13,8 +13,7 @@ services:
# - ./watch-assets.csv:/dabo/watch-assets.csv # - ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
deploy: deploy:
resources: resources:
@@ -35,8 +34,7 @@ services:
# - ./watch-assets.csv:/dabo/watch-assets.csv # - ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/fetch-symbols_ticker.sh entrypoint: /dabo/fetch-symbols_ticker.sh
deploy: deploy:
@@ -57,8 +55,7 @@ services:
- ./dabo-bot.conf:/dabo/dabo-bot.override.conf - ./dabo-bot.conf:/dabo/dabo-bot.override.conf
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 5m 300 entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 5m 300
@@ -75,8 +72,7 @@ services:
- ./dabo-bot.conf:/dabo/dabo-bot.override.conf - ./dabo-bot.conf:/dabo/dabo-bot.override.conf
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 15m 900 entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 15m 900
@@ -93,8 +89,7 @@ services:
- ./dabo-bot.conf:/dabo/dabo-bot.override.conf - ./dabo-bot.conf:/dabo/dabo-bot.override.conf
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 1h 3600 entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 1h 3600
@@ -111,8 +106,7 @@ services:
- ./dabo-bot.conf:/dabo/dabo-bot.override.conf - ./dabo-bot.conf:/dabo/dabo-bot.override.conf
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 4h 3600 entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 4h 3600
@@ -129,8 +123,7 @@ services:
- ./dabo-bot.conf:/dabo/dabo-bot.override.conf - ./dabo-bot.conf:/dabo/dabo-bot.override.conf
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 1d entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 1d
@@ -147,8 +140,7 @@ services:
- ./dabo-bot.conf:/dabo/dabo-bot.override.conf - ./dabo-bot.conf:/dabo/dabo-bot.override.conf
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 1w entrypoint: /dabo/fetch-ohlcv-candles-indicators.sh 1w
@@ -166,8 +158,7 @@ services:
# - ./watch-assets.csv:/dabo/watch-assets.csv # - ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/calc-indicators-hist.sh entrypoint: /dabo/calc-indicators-hist.sh
cpu_shares: 128 cpu_shares: 128
@@ -175,7 +166,7 @@ services:
resources: resources:
limits: limits:
cpus: '1' cpus: '1'
memory: 1024M memory: 512M
dabo-calc-levels: dabo-calc-levels:
build: build:
@@ -190,8 +181,7 @@ services:
# - ./watch-assets.csv:/dabo/watch-assets.csv # - ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:rw
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/calc-levels.sh entrypoint: /dabo/calc-levels.sh
deploy: deploy:
@@ -213,8 +203,7 @@ services:
# - ./watch-assets.csv:/dabo/watch-assets.csv # - ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/fetch-orders.sh entrypoint: /dabo/fetch-orders.sh
deploy: deploy:
@@ -236,8 +225,7 @@ services:
# - ./watch-assets.csv:/dabo/watch-assets.csv # - ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/fetch-transaction-history.sh entrypoint: /dabo/fetch-transaction-history.sh
cpu_shares: 128 cpu_shares: 128
@@ -247,6 +235,30 @@ services:
cpus: '0.5' cpus: '0.5'
memory: 512M memory: 512M
dabo-fetch-coinmarketcapids:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
user: 10000:10000
volumes:
- ./dabo:/dabo:ro
- ./strategies:/dabo/strategies:ro
- ./dabo-bot.conf:/dabo/dabo-bot.override.conf
# - ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw
- ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/fetch-coinmarketcapids.sh
cpu_shares: 128
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
# dabo-test: # dabo-test:
# build: # build:
# context: . # context: .
@@ -260,8 +272,7 @@ services:
## - ./watch-assets.csv:/dabo/watch-assets.csv ## - ./watch-assets.csv:/dabo/watch-assets.csv
# - ./data:/dabo/htdocs:rw # - ./data:/dabo/htdocs:rw
# - ./home:/dabo/home:rw # - ./home:/dabo/home:rw
# - /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro # - ./notify.local.conf:/usr/local/etc/notify.conf:ro
# - /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
# - /etc/localtime:/etc/localtime:ro # - /etc/localtime:/etc/localtime:ro
# entrypoint: /dabo/test.sh # entrypoint: /dabo/test.sh
# cpu_shares: 128 # cpu_shares: 128
@@ -285,8 +296,7 @@ services:
# - ./watch-assets.csv:/dabo/watch-assets.csv # - ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw - ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/create_webpage.sh entrypoint: /dabo/create_webpage.sh
deploy: deploy:
@@ -307,3 +317,5 @@ services:
cpus: '1' cpus: '1'
memory: 128M memory: 128M

6981
example-values Normal file

File diff suppressed because it is too large Load Diff

2
notify.conf Normal file
View File

@@ -0,0 +1,2 @@
tohost=sshuser@sshhost
default_togroup=message-group

View File

@@ -1,56 +0,0 @@
# remove this line if you are fine with this settings and want to use them on your own risk!!!
# It is strongly recommended to test this strategy first via analyze.sh!!!
return 1
# GOOD_MARKET_PERFORMANCE_INDEX defines from which growth the market is considered good/favorable for investment.
# The market performance is calculated from the average percentage development of various indicators such as development MSCI World, Bitcoin and Ethereum as well as forecasts.
# for details see functions/market_performance.sh
# If the market performance is under this value no buying will be done
local GOOD_MARKET_PERFORMANCE_INDEX="100"
###### BUY CONDITIONS ######
### RSI Indicator checks
# Don't buy if the RSI-XX value is >= BUY_RSIXX_BUY_SIGNAL_UNTIL
local BUY_RSI5_SIGNAL_UNTIL="0"
local BUY_RSI14_SIGNAL_UNTIL="0"
local BUY_RSI21_SIGNAL_UNTIL="0"
local BUY_RSI60_SIGNAL_UNTIL="0"
local BUY_RSI120_SIGNAL_UNTIL="0"
local BUY_RSI240_SIGNAL_UNTIL="0"
local BUY_RSI420_SIGNAL_UNTIL="0"
local BUY_RSI720_SIGNAL_UNTIL="0"
# Don't buy if the RSI-XX value is <= BUY_RSIXX_BUY_SIGNAL_FROM
local BUY_RSI5_SIGNAL_FROM="0"
local BUY_RSI14_SIGNAL_FROM="0"
local BUY_RSI21_SIGNAL_FROM="0"
local BUY_RSI60_SIGNAL_FROM="0"
local BUY_RSI120_SIGNAL_FROM="0"
local BUY_RSI240_SIGNAL_FROM="0"
local BUY_RSI420_SIGNAL_FROM="0"
local BUY_RSI720_SIGNAL_FROM="0"
### MACD Indicator Checks
# Don't buy if MACD Histogram Relation is not between this values.
# The ratio is calculated by the difference between the maximum positive Histogram value (of the defined time period) and the current value.
# Here you can specify a percentage range.
# If only the buy signal should be considered, simply specify the range 0 and 100.
# decimal numbers are not allowed here.
local BUY_MACD_RELATION_FROM="0"
local BUY_MACD_RELATION_TO="0"
# Don't buy if price change is under this percentage values
local BUY_MIN_PRICE_CHANGE_LAST_1_DAY="0.25"
local BUY_MIN_PRICE_CHANGE_LAST_7_DAY="-1"
local BUY_MIN_PRICE_CHANGE_LAST_14_DAY="-2"
local BUY_MIN_PRICE_CHANGE_LAST_30_DAY="-5"
# Dont buy if growth in the last defined time period <= BUY_MINGROWTH
local BUY_MINGROWTH_PERIOD="30"
local BUY_MINGROWTH="-10"

View File

@@ -0,0 +1,272 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
# Example strategy
g_echo_note "EXAMPLE Strategy"
##### WARNING! This strategy is only intended as an example and should not be used with real trades. Please develop your own strategy ######
# if you want to use this remove the next line with return 0
return 0
# get vars with orders and positions
get_position_array
get_orders_array
# reset score
unset s_score
unset s_score_hist
s_score=0
### BEGIN market scoring ###
# correlation to crypto
for asset in DOWJONES SP500 NASDAQ MSCIEAFE GOLD MSCIWORLD KRE
do
g_echo "scoring ECONOMY_${asset}"
# bullish? bull market?
[ -n "${v[ECONOMY_${asset}_1d_ema200_0]}" ] && if g_num_is_higher ${v[ECONOMY_${asset}_15m_close_0]} ${v[ECONOMY_${asset}_1d_ema200_0]}
then
score 2 "${asset} EMA200 over last 15m close"
else
score -2 "${asset} EMA200 under last 15m close"
fi
# RSI14 1d
if [ -n "${v[ECONOMY_${asset}_1d_rsi14_0]}" ]
then
rsi14=${v[ECONOMY_${asset}_1d_rsi14_0]}
g_num_is_between $rsi14 80 100 && score -2 "${asset} RSI14 $rsi14"
g_num_is_between $rsi14 55 80 && score 2 "${asset} RSI14 $rsi14"
g_num_is_between $rsi14 15 45 && score 1 "${asset} RSI14 $rsi14"
g_num_is_between $rsi14 0 15 && score -2 "${asset} RSI14 $rsi14"
fi
# macd trend
[[ ${v[ECONOMY_${asset}_1d_macd_histogram_signal_0]} = uptrend ]] && score 2 "${asset} MACD uptrend"
[[ ${v[ECONOMY_${asset}_1d_macd_histogram_signal_0]} = downtrend ]] && score -2 "${asset} MACD downtrend"
done
# inverse correlation to crypto
for asset in DXY OILGAS
do
g_echo "scoring ECONOMY_${asset}"
# bullish? bull market?
[ -n "${v[ECONOMY_${asset}_1d_ema200_0]}" ] && if g_num_is_higher ${v[ECONOMY_${asset}_15m_close_0]} ${v[ECONOMY_${asset}_1d_ema200_0]}
then
score -2 "${asset} EMA200 over last 15m close"
else
score 2 "${asset} EMA200 under last 15m close"
fi
# RSI14 1d
if [ -n "${v[ECONOMY_${asset}_1d_rsi14_0]}" ]
then
rsi14=${v[ECONOMY_${asset}_1d_rsi14_0]}
g_num_is_between $rsi14 80 100 && score 2 "${asset} RSI14 $rsi14"
g_num_is_between $rsi14 55 80 && score -2 "${asset} RSI14 $rsi14"
g_num_is_between $rsi14 15 45 && score -1 "${asset} RSI14 $rsi14"
g_num_is_between $rsi14 0 15 && score 2 "${asset} RSI14 $rsi14"
fi
# macd trend
[[ ${v[ECONOMY_${asset}_1d_macd_histogram_signal_0]} = uptrend ]] && score -2 "${asset} MACD uptrend"
[[ ${v[ECONOMY_${asset}_1d_macd_histogram_signal_0]} = downtrend ]] && score 2 "${asset} MACD downtrend"
done
### Evaluate BTC and ETH
for asset in BTC${CURRENCY} ETH${CURRENCY}
do
g_echo "scoring ${asset}"
# bullish? bull market?
[ -n "${v[${asset}_1d_ema200_0]}" ] && if g_num_is_higher ${v[${asset}_15m_close_0]} ${v[${asset}_1d_ema200_0]}
then
score 2 "${asset} EMA200 over last 15m close"
else
score -2 "${asset} EMA200 under last 15m close"
fi
# RSI14 1d
if [ -n "${v[${asset}_1d_rsi14_0]}" ]
then
rsi14=${v[${asset}_1d_rsi14_0]}
g_num_is_between $rsi14 80 100 && score -2 "${asset} RSI14 $rsi14"
g_num_is_between $rsi14 55 80 && score 2 "${asset} RSI14 $rsi14"
g_num_is_between $rsi14 15 45 && score 1 "${asset} RSI14 $rsi14"
g_num_is_between $rsi14 0 15 && score -2 "${asset} RSI14 $rsi14"
fi
# macd trend
[[ ${v[${asset}_1d_macd_histogram_signal_0]} = uptrend ]] && score 2 "${asset} MACD uptrend"
[[ ${v[${asset}_1d_macd_histogram_signal_0]} = downtrend ]] && score -2 "${asset} MACD downtrend"
done
### END market scoring ###
# save score until here
market_score=$s_score
market_score_hist=$s_score_hist
### Go through trading symbols
for symbol in ${f_symbols_array_trade[@]}
do
# restore market score as base
s_score=$market_score
s_score_hist=$market_score_hist
asset=${symbol//:$CURRENCY/}
asset=${asset//\//}
### Evaluate symbol
g_echo "scoring ${asset}"
# bullish? bull market?
[ -n "${v[${asset}_1d_ema200_0]}" ] && if g_num_is_higher ${v[${asset}_15m_close_0]} ${v[${asset}_1d_ema200_0]}
then
score 2 "${asset} EMA200 over last 15m close"
else
score -2 "${asset} EMA200 under last 15m close"
fi
# RSI14 5m
if [ -n "${v[${asset}_5m_rsi14_0]}" ]
then
rsi14=${v[${asset}_5m_rsi14_0]}
g_num_is_between $rsi14 80 100 && score -4 "$asset RSI14 $rsi14"
g_num_is_between $rsi14 55 80 && score 4 "$asset RSI14 $rsi14"
g_num_is_between $rsi14 15 45 && score 2 "$asset RSI14 $rsi14"
g_num_is_between $rsi14 0 15 && score -4 "$asset RSI14 $rsi14"
fi
# macd trend
[[ ${v[${asset}_5m_macd_histogram_signal_0]} = uptrend ]] && score 2 "$asset MACD uptrend"
[[ ${v[${asset}_5m_macd_histogram_signal_0]} = downtrend ]] && score -2 "$asset MACD downtrend"
# go short or go long or better do notghing?
side="unclear"
g_num_is_higher $s_score 5 && side="long"
g_num_is_lower $s_score -5 && side="short"
g_echo_ok "Score: $s_score"
g_echo_ok "Side: $side"
g_echo "Scores: $s_score_hist"
# remove existing orders and do nothing if unclear
if [[ $side = "unclear" ]]
then
g_echo "Situation of $asset unclear - remove existing orders and do nothing!"
order_cancel "$symbol"
continue
fi
# if no contract trading / no shot possible ignore
if [ -z "$LEVERAGE" ] && [[ $side = short ]]
then
g_echo "No 'short' possible while sport trading - doung nothing with $asset"
continue
fi
# Next week level is:
g_echo "level_1w_next_up: ${v[${asset}_levels_1w_next_up]}"
g_echo "level_1w_next_down: ${v[${asset}_levels_1w_next_down]}"
# define entry price
unset entry_price
[[ $side = long ]] && entry_price=${v[${asset}_levels_1w_next_down]}
[[ $side = short ]] && entry_price=${v[${asset}_levels_1w_next_up]}
# if entry price not given set to current price
[ -z "$entry_price" ] && entry_price=${v[${asset}_price]}
# check for updates if order with entry price is already defined
if [ -n "${o[${asset}_open_${side}_entry_price]}" ]
then
if g_num_is_approx ${o[${asset}_open_${side}_entry_price]} $entry_price 0.5 0.5
then
g_echo "Order of $asset at ${o[${asset}_open_long_entry_price]} fine"
else
# cancelling order
g_echo_warn "Cancelling order because entry price not seems to be up2date anymore: ${o[${asset}_open_${side}_entry_price]} != $entry_price"
order_cancel "$symbol"
fi
fi
# check for already existing order
if [ -n "${o[${asset}_present]}" ]
then
g_echo_ok "Order(s) of ${asset} already exists"
continue
fi
# check for already existing position
if [ -n "${p[${asset}_currency_amount]}" ]
then
g_echo "Position of ${asset} already open"
continue
fi
# StopLoss at 20% loss
stoplosspercentage=20
# calc percentage loss if leverage is set
if [ -n "$LEVERAGE" ]
then
g_calc "$stoplosspercentage/$LEVERAGE"
stoplosspercentage=$g_calc_result
fi
# calc stoploss
[[ $side = long ]] && g_calc "$entry_price-($entry_price/100*${stoplosspercentage})"
[[ $side = short ]] && g_calc "$entry_price+($entry_price/100*${stoplosspercentage})"
stoploss=$g_calc_result
# TakeProfit at 2% profit
takeprofitpercentage=5
if [ -n "$LEVERAGE" ]
then
g_calc "$takeprofitpercentage/$LEVERAGE"
takeprofitpercentage=$g_calc_result
fi
[[ $side = long ]] && g_calc "$entry_price+($entry_price/100*${takeprofitpercentage})"
[[ $side = short ]] && g_calc "$entry_price-($entry_price/100*${takeprofitpercentage})"
takeprofit=$g_calc_result
# Use 100 of balace for trade
trade_balance=100
# altarnative calculate 2 percentage of available balace for trade
#get_balance
#g_calc "$f_CURRENCY_BALANCE/100*2"
#trade_balance=$g_calc_result
# place the order
order "$symbol" "$trade_balance" "$side" "$entry_price" "$stoploss" "$takeprofit"
done

View File

@@ -0,0 +1,87 @@
#!/bin/bash
# Copyright (c) 2022-2024 olli
#
# This file is part of dabo (crypto bot).
#
# dabo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dabo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dabo. If not, see <http://www.gnu.org/licenses/>.
# Example strategy for managing open positions
g_echo_note "EXAMPLE Strategy for managing open positions"
##### WARNING! This strategy is only intended as an example and should not be used with real trades. Please develop your own strategy ######
# if you want to use this remove the next line with return 0
return 0
# get vars with positions
get_position_array
# go through trading symbols
for symbol in ${f_symbols_array_trade[@]}
do
asset=${symbol//:$CURRENCY/}
asset=${asset//\//}
# adjust stoploss from percentage profit
from_profit=0.5
if [ -n "$LEVERAGE" ]
then
g_calc "${from_profit}*${LEVERAGE}"
from_profit=$g_calc_result
fi
# save profit by switching stoploss in profit
if [ -n "${p[${asset}_pnl]}" ]
then
# what side are we on (long or short)
side=${p[${asset}_side]}
g_echo_note "Checking open $side position for $f_asset"
if g_num_is_higher ${p[${asset}_pnl_percentage]} $from_profit
then
# calculate stoploss price with half of current pnl
g_calc "${p[${asset}_current_price]}-((${p[${asset}_current_price]}-${p[${asset}_entry_price]})/2)"
stoploss_price=$g_calc_result
# check for already existing stoploss
if [ -n "${o[${asset}_sl_close_${side}_id]}" ]
then
# do nothing if current stoploss price is already larger/equal then half of current pnl
if [[ $side = long ]]
then
g_num_is_higher_equal ${o[${asset}_sl_close_${side}_stopprice]} $stoploss_price && continue
fi
if [[ $side = short ]]
then
g_num_is_lower_equal ${o[${asset}_sl_close_${side}_stopprice]} $stoploss_price && continue
fi
# cancel existing stoploss order
order_cancel_id "$symbol" "${o[${asset}_sl_close_${side}_id]}" || continue
fi
# create new stoploss
g_echo_ok "==== New StopLoss in profit for $asset at $stoploss_price"
order "$symbol" "asset_amount:${p[${asset}_asset_amount]}" ${side} stoploss "$stoploss_price"
fi
fi
done

View File

@@ -1,65 +0,0 @@
# remove this line if you are fine with this settings and want to use them on your own risk!!!
# It is strongly recommended to test this strategy first via analyze.sh!!!
return 1
# GOOD_MARKET_PERFORMANCE_INDEX defines from which growth the market is considered good/favorable for investment.
# The market performance is calculated from the average percentage development of various indicators such as development MSCI World, Bitcoin and Ethereum as well as forecasts.
# for details see functions/market_performance.sh
# If the market performance is under this value no buying will be done
local GOOD_MARKET_PERFORMANCE_INDEX="2"
# Force hold if result negative expect SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE. Boolean 1 for true 0 for false.
local SELL_HOLD_IF_RESULT_NEGATIVE="1"
# If the price falls by this percentage value from the purchase price, then sell in any case
local SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE="-10"
# from here only if SELL_HOLD_IF_RESULT_NEGATIVE doesn't match
# If the price falls by this percentage value from the last rate
local SELL_IF_LAST_RATE_LOWER_THEN="-0.25"
### RSI Indicator checks
# SELL if the RSI-XX value is <= SELL_RSIXX_SELL_SIGNAL_UNTIL
local SELL_RSI5_SIGNAL_UNTIL="99"
local SELL_RSI14_SIGNAL_UNTIL="99"
local SELL_RSI21_SIGNAL_UNTIL="99"
local SELL_RSI60_SIGNAL_UNTIL="99"
local SELL_RSI120_SIGNAL_UNTIL="99"
local SELL_RSI240_SIGNAL_UNTIL="99"
local SELL_RSI420_SIGNAL_UNTIL="99"
local SELL_RSI720_SIGNAL_UNTIL="99"
# SELL if the RSI-XX value is >= SELL_RSIXX_SELL_SIGNAL_FROM
local SELL_RSI5_SIGNAL_FROM="90"
local SELL_RSI14_SIGNAL_FROM="90"
local SELL_RSI21_SIGNAL_FROM="90"
local SELL_RSI60_SIGNAL_FROM="70"
local SELL_RSI120_SIGNAL_FROM="50"
local SELL_RSI240_SIGNAL_FROM="50"
local SELL_RSI420_SIGNAL_FROM="50"
local SELL_RSI720_SIGNAL_FROM="50"
# If the price after this time period is lower the the trading fee, then sell if SELL_HOLD_IF_RESULT_NEGATIVE is fine with it
local SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD="7200"
### MACD Indicator Checks
# Sell if MACD Histogram relation is < this value
# The ratio is calculated by the difference between the maximum negative Histogram value (of the defined time period) and the current value.
# Here you can specify a percentage range.
# If only the sell signal should be considered, simply specify 0
# decimal numbers are not allowed here.
local SELL_MACD_RELATION_FROM="25"
### Take profit/loss
local TAKE_PROFIT_CHECK_AFTER_POSTITIVE_RESULTS="1"
local TAKE_PROFIT_CHECK_AT_FEE_PLUS="0.5"
local TAKE_PROFIT_CHECK_AT_FACTOR="1.25"
local TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS="5"
local TAKE_LOSS_CHECK_AT_FEE_PLUS="0"
local TAKE_LOSS_CHECK_AT_FACTOR="2"