Compare commits

..

164 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
f9d4f7d8ed fixes 2024-07-29 20:12:23 +02:00
39b10958d5 fixes 2024-07-29 20:09:41 +02:00
4f45f1c98a bugfixes, charts, economy-data 2024-07-27 17:44:29 +02:00
e06b575e46 niver code 2024-07-15 17:10:48 +02:00
2bdc7d3ab2 initial charts 2024-07-15 16:34:01 +02:00
9fab344720 fixes, levels, whitelist... 2024-07-14 22:08:59 +02:00
927102b2e9 indicators, levels, fixes,... 2024-07-07 16:39:38 +02:00
4ecce00fa5 doc 2024-06-20 21:22:14 +02:00
3df42d885c doc 2024-06-20 21:17:14 +02:00
fd51c16855 doc 2024-06-20 21:15:18 +02:00
2f42617e8d doc 2024-06-20 20:57:43 +02:00
0094d806e8 ccxt switch 2024-06-14 22:45:01 +02:00
f6c358d807 close positions of symbol 2024-06-14 22:44:13 +02:00
f93d33a6a1 ccxt switch 2024-06-14 19:59:33 +02:00
5c32cd3dd1 separate container 2024-06-14 19:57:04 +02:00
c2ee85d7b6 fixes and switch to ccxt 2024-06-14 19:56:43 +02:00
73081d1309 ccxt switch 2024-06-14 19:51:41 +02:00
9a49a05f73 new vars 2024-06-14 19:51:12 +02:00
6665091700 rename 2024-06-14 19:50:39 +02:00
ee0af1a21d ccxt switch 2024-06-14 19:50:27 +02:00
c53b968b21 separate containers 2024-06-14 19:49:51 +02:00
ec7b7a9d8f place orders 2024-06-14 19:49:27 +02:00
c7c8ea9b7f fetch orders 2024-06-14 19:49:10 +02:00
7ade733c8d separate container 2024-06-14 19:48:50 +02:00
fd18f33ed5 separate container 2024-06-14 19:48:42 +02:00
ce5c91fa44 separate container 2024-06-14 19:48:36 +02:00
89 changed files with 14082 additions and 1893 deletions

8
.gitignore vendored
View File

@@ -9,11 +9,15 @@
/dabo/.*-secrets
/home/.ssh
/home/.viminfo
/home/.bash_history
/home/.dabo-bot.sh.lock
.*history
.wget-hsts
/analyze-*
*.del
*.tmp
*local*
test*.sh
/env
/genpw.sh
/watch-assets.csv*
/data/watch.html
/data/lightweight-charts.standalone.production.js

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>.

551
README.md
View File

@@ -1,69 +1,213 @@
# 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!!!
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!
# Objective
The dabo-bot is intended to help make and execute timely buy and sell decisions automatically in the fast-paced crypto environment. It is to be invested in the case of larger increases in value and investments are to be sold again when the prices fall, so that price gains are taken and losses are minimized.
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.
# Naming
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.
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,...
## Naming
The name Dabo comes from the Star Trek universe.
Dabo was a roulette-style game of chance developed by the Ferengi.
More information here:
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 ;-)
# Features
## General:
- Compatible with the following crypto exchanges: Binance, OneTrading.com (ex BitpandaPro)
- Consideration of trading fees
- 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
## Structure
The Bot is splitted in the following parts/containers:
## 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
- dabo-bot: Basic Bot with buy and sell decisions based on self-definable strategies
- dabo-symbols_ticker: Ticker for current symbols and prices
- dabo-ohlcv-candles: Continuously collect OHLCV data
- dabo-indicators: Continuously calculate indicators and other data
- dabo-orders: Continuously collect current orders placed by bot and others
- dabo-transaction-history: Continuously creates overview of historic trades
- dabo-webpage: Continuously creates webpage overview (readonly)
- dabo-web: Webserver for webpage overview
## 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
Each part runs parallel to the others in its own docker-container.
# How to use/install
Linux knowledge required!
## Features
### General:
- theoretically compatible to supported CCXT exchanges. Tested with Phemex Contract trading. Please let me know your experiences with other exchanges.
- parallel processing in separate non-root docker containers
- Notifications via Matrix Messenger to groups
Needed a running Docker install. Traefik suggested, see
### Dabo Bot
- place limit and market orders and supports ...
- ... leverage trading
- ... short trades
- ... margins cross and isolated
- ... stoploss and takeprofit
- multiple different strategies possible at the same time
### Dabo Symbol Ticker
- automatically finds all supported tokens and pairs and fetches continiously ...
- ... symbols
- ... and prices
### Dabo OHLCV Candle data
OHLCV = Open, High, Low, Close and Volume of a time unit
- time units 1w, 1d, 4h, 1h, 15m and 5m
- 4h, 1h, 15m and 5m from the respective stock exchange
- 1d and 1w data from coinmarketcap to have longer terms
- economic data from yahoo finance
### Dabo Indicators
- data per time unit
- time units 1w, 1d, 4h, 1h, 15m and 5m
- self-calculated EMA12, 26 ,50, 100, 200, 400 and 800
- self-calculated RSI5, 14, 21
- self-calculated MACD
- self-calculated significant levels (support/resist)
### Dabo Market Data
- Yahoo Finance
- CoinMarketCap
- BLS.gov
- alternative.me
- CNN
- Fed
### Dabo Orders
### Dabo Transaction History
- Support of additional Exchnages/Brokers JustTrade (CSV-Import) and Bitpanda (API+CSV-Import)
- German tax calculation
### Dabo Webpage
- ReadOnly Overview
https://gitea.ds9.dedyn.io/olli/debian.ansible.docker
## Why bash?
Yes, bash is not a language in which you write something like this in a normal way.
https://gitea.ds9.dedyn.io/olli/debian.ansible.traefik.server
To be honest, I'm more of a Linux admin than a programmer, so I do a lot of my work using bash.
Simply it's the language I'm most familiar with.
Originally this project was supposed to be a simple script to monitor prices of equities and ETFs and set alarms at certain marks. Over time it has expanded a lot and a complete rewrite in another language would have meant a lot of additional work. So it has stayed that way until now.
## Download
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.
## How to install (basic Linux knowledge required!)
Should run on every system with docker.
### 1: Operating System
Tested and running with Debian 12 (Bookworm).
https://www.debian.org/download
https://www.raspberrypi.com/software/operating-systems/
### 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.
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
```
## 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
```
## 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:
```
echo '
@@ -105,87 +249,63 @@ networks:
' >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
ssh-keygen -f home/.ssh/id_ed25519 -N "" -t ed25519
chmod 700 home/.ssh
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)
```
# 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
echo 'local API_SECRET="YOUR_LONG_API_SECRET_FROM_BINANCE"
local API_KEY="YOUR_LONG_API_KEY_FROM_BINANCE" '>dabo/.binance-secrets
- file: dabo/.CCXT-ID-secrets
CCXI-ID see: https://github.com/ccxt/ccxt
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
```
Create Config
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
```
Defaults in dabo/dabo-bot.conf
## How to use
## Prepare/Create a stretegy
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
### Operational commands
Run/Restart:
```
docker compose down # if an old instance is running
docker compose up -d
```
Check
List and state of containers:
```
docker compose ps
```
@@ -194,132 +314,167 @@ Logs/Output:
```
docker compose logs -f
```
Update:
Logs/Oputput of a specific container for example dabo-bot:
```
# 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 clean -fd # Remove local uncommited files
# 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 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.
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.
IMPORTANT!!!
A Binance or OneTrading.com (ex BitpandaPro) account must exist and the API must be enabled.
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.
THE EXAMPLE STRATEGIES MAY NOT FIT YOUR NEEDS OR WORK PROPERLY. SO YOU CAN LOOSE ALL YOUR MONEY!!! USE ON YOUR OWN RISK!!!
# 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
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
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
```
## Variables with current values from the CSV files
#### Own strategies
Aditional strategies can be created with naming convention *.strategy.sh
```
# date from current timeframe
${f_date}
# 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}
strategies/my-new.strategy.sh
strategies/yet-another-new.strategy.sh
```
# Future ideas/featrues
- Crypto preferences (While/Blacklist for certain currencies)
- Overview trades/profits/losses for tax declaration
- Support for decentralized exchanges like uniswap to gain more "security"
Strategy files should have specific rights - must be readable by the bot:
```
chown -R 10000:10000 strategies
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
- 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
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}}
force: true
notify: Restart dabo
- name: /home/docker/dabo.{{inventory_hostname}}/genpw.sh (generate Random PW)
- name: /home/docker/dabo.{{inventory_hostname}}/initiate.sh
blockinfile:
path: /home/docker/dabo.{{inventory_hostname}}/genpw.sh
path: /home/docker/dabo.{{inventory_hostname}}/initiate.sh
create: yes
mode: 0550
owner: root
@@ -29,41 +29,22 @@
block: |
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 ]
then
mkdir -p home/.ssh
ssh-keygen -f home/.ssh/id_ed25519 -N "" -t ed25519 >/dev/null
chmod 700 home/.ssh
fi
[ -f watch-assets.csv ] || cp dabo/watch-assets.csv watch-assets.csv
chown -R 10000:10000 dabo data home strategies dabo-bot.conf watch-assets.csv
mkdir -p data/botdata strategies
chown -R 10000:10000 dabo data home strategies dabo-bot.conf
backup: yes
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:
path: /home/docker/dabo.{{inventory_hostname}}/genpw.sh
path: /home/docker/dabo.{{inventory_hostname}}/initiate.sh
insertbefore: BOF
line: "#!/bin/bash -e"
@@ -84,10 +65,10 @@
- Restart dabo
- name: Get crypted PW
shell: bash /home/docker/dabo.{{inventory_hostname}}/genpw.sh
register: cryptpw
changed_when: false
#- name: Get crypted PW
# shell: bash /home/docker/dabo.{{inventory_hostname}}/initiate.sh
# register: cryptpw
# changed_when: false
- name: /home/docker/dabo.{{inventory_hostname}}/docker-compose.override.yml Container Configuration
blockinfile:
@@ -98,7 +79,13 @@
group: docker
marker: "# {mark} ANSIBLE MANAGED BLOCK"
block: |
version: '3.6'
networks:
dabo-network:
driver: bridge
driver_opts:
com.docker.network.bridge.name: br-dabo
traefik:
external: true
services:
@@ -120,21 +107,11 @@
# cert via letsencrypt
- traefik.http.routers.dabo.tls.certresolver=letsencrypt
# activate secHeaders@file
- traefik.http.routers.dabo.middlewares=secHeaders@file,dabo-basicauth
- traefik.http.middlewares.dabo-basicauth.basicauth.users={{ cryptpw.stdout }}
- traefik.http.routers.dabo.middlewares=secHeaders@file,default-basic-auth@file
# Traefik network
- traefik.docker.network=traefik
networks:
- traefik
networks:
dabo-network:
driver: bridge
driver_opts:
com.docker.network.bridge.name: br-dabo
traefik:
external: true
backup: yes
notify: Restart dabo
@@ -144,11 +121,26 @@
chdir: /home/docker/dabo.{{inventory_hostname}}
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:
- name: run genpw.sh
ansible.builtin.shell: ./genpw.sh
- name: run initiate.sh
ansible.builtin.shell: ./initiate.sh
args:
chdir: /home/docker/dabo.{{inventory_hostname}}
notify: Restart dabo
@@ -157,3 +149,4 @@
ansible.builtin.shell: docker compose up -d --force-recreate
args:
chdir: /home/docker/dabo.{{inventory_hostname}}

View File

@@ -1,5 +1,24 @@
#!/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
rm -r /tmp/parallel-* /tmp/overall-result-* /tmp/g_analyze.sh-*

38
dabo/calc-indicators-hist.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/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
rm -f asset-histories/*.history.*.csv.indicators-calculating
while true
do
sleep 900
g_echo_note "Next loop"
# Reload Config
. ../../dabo-bot.conf
. ../../dabo-bot.override.conf
# get all indicators first only latest until EMA800
get_indicators_all 810
get_indicators_all
rm -f asset-histories/*.history.*.csv.indicators-calculating
done

39
dabo/calc-levels.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/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
rm -f asset-histories/*.history.*.csv.levels-calculating
sleep 120
while true
do
g_echo_note "Next loop"
# Reload Config
. ../../dabo-bot.conf
. ../../dabo-bot.override.conf
# get levels
get_levels_all
rm -f asset-histories/*.history.*.csv.levels-calculating
# recalc every 6 hours
sleep 21600
done

33
dabo/create_webpage.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/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
# Reload Config
. ../../dabo-bot.conf
. ../../dabo-bot.override.conf
# get orders
webpage
sleep 120
done

View File

@@ -2,36 +2,31 @@
# Webpage URL
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"
# fee per trade in percentage on exchange (taker and maker added)
FEE="0.5"
# Interval in seconds - Should not be lower then 300
INTERVAL="900"
# Interval in seconds - Should not be lower then 300 seconds (5m is the lowest timeframe
INTERVAL="300"
## Currency used for trading
CURRENCY="USDT"
TRANSFER_CURRENCY="USD"
TRANSFER_CURRENCY="EUR"
# Only use currencies under the first X currencies sorted by market capitalization
LARGEST_MARKETCAP="250"
# Blacklist Currencies
BLACKLIST="^USDT${CURRENCY}|^DAI${CURRENCY}|^BUSD${CURRENCY}|^USDC${CURRENCY}|^USDP${CURRENCY}|^TUSD${CURRENCY}|^USDD${CURRENCY}|^GUSD${CURRENCY}|^FEI${CURRENCY}|^USTC${CURRENCY}|^FRAX${CURRENCY}|^USDJ${CURRENCY}|^LUSD${CURRENCY}|^EURS${CURRENCY}|^TRIBE${CURRENCY}|^BNB${CURRENCY}|^FDUSD${CURRENCY}"
# symbols that should be traded
SYMBOLS="ETH SOL"
## Signal Group for Notifications
SIGNAL_GROUP="Krypto-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"
NOTIFICATION_GROUP="Dabo-Bot"
# Leverage
LEVERAGE=""
LEVERAGE="2"
# margin mode (isolated or cross)
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,9 +1,26 @@
#!/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
### MAIN ###
g_echo_warn "STARTING DABO BOT $0"
g_echo_note "STARTING DABO BOT $0"
touch firstloop
export FULL_LOOP=1
@@ -12,12 +29,12 @@ export FULL_LOOP=1
echo $0 | grep -q "dabo-bot\.sh" && BOT=1
# cleanup trashlines in asset-histories (possibly generated by kill further of this progress)
find asset-histories -name "*.csv" -type f | while read csv_file
do
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}
touch -t ${csv_timestamp} "${csv_file}"
done
#find asset-histories -name "*.csv" -type f | while read csv_file
#do
# 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}"
# touch -t ${csv_timestamp} "${csv_file}"
#done
# run endless loop
@@ -28,7 +45,7 @@ do
then
rm -f firstloop
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_full_interval=$((${INTERVAL} - $(date +%s) % ${INTERVAL}))
# Check for next general interval
@@ -51,61 +68,17 @@ do
. ../../dabo-bot.conf
. ../../dabo-bot.override.conf
# Headline
export csv_headline="Date and Time,Price,Change,EMA12,EMA26,MACD,EMA9 (Sig.),Histogram,MACD Sig.,RSI5,RSI14,RSI21,RSI720,RSI60,RSI120,RSI240,RSI420,Coingecko Change 24h,Coingecko Change 7d,Coingecko Change 14d,Coingecko Change 30d,Coingecko Change 1y,Coingecko MarketCap Change 24h,RANGE DATE,LOWEST IN RANGE,HIGHEST IN RANGE,PIVOT POINT,SUPPORT1,RESIST1,GOLDEN POCKET SUPPORT,GOLDEN POCKET RESIST,GOLDEN POCKET 65 SUPPORT,GOLDEN POCKET 65 RESIST,SUPPORT3,RESIST3,EMA50,EMA100,EMA200,EMA800,Coingecko Price"
# Timestamp
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
# transactions overview
#[ ${FULL_LOOP} = 1 ] && transactions_overview
# stock data
#if [ "${STOCK_EXCHANGE}" = "BINANCE" ]
#then
# # command for current token infos (function for setting var QUANTITY_LOT_CUT
# TOKEN_INFO_CMD="binance_get_token_info"
# # command for buying/selling a token
# TRADE_CMD='binance-api-call POST /api/v3/order "&symbol=TOKEN&quoteOrderQty=QUANTITY&side=ACTION&type=MARKET"'
#elif [ "${STOCK_EXCHANGE}" = "ONETRADING" ]
#then
# TOKEN_INFO_CMD="onetrading_get_token_info"
# TRADE_CMD='onetrading-api-call POST public/v1/account/orders "--header \"Content-Type: application/json\" --data \"{\\\"instrument_code\\\":\\\"TOKEN\\\",\\\"side\\\":\\\"ACTION\\\",\\\"type\\\":\\\"MARKET\\\",\\\"amount\\\":\\\"QUANTITY\\\"}\""'
if [ "${STOCK_EXCHANGE}" = "NONE" ]
then
## stop here if STOCK_EXCHANGE not present
continue
fi
# Get current symbols
[ ${FULL_LOOP} = 1 ] && get_symbols
# Get current assets
get_assets || continue
# Sell something?
#check_for_sell
# clean old data
[ ${FULL_LOOP} = 1 ] && find asset-histories -maxdepth 1 ! -type d ! -name "*.csv" ! -name "*.levels" ! -name "*.zones" ! -name "*.indicators-calculated" -mtime +1 -delete
# Get current balance
[ ${FULL_LOOP} = 1 ] && get_balance || continue
@@ -113,16 +86,11 @@ do
# Get current positions
[ ${FULL_LOOP} = 1 ] && get_positions || continue
# Buy something?
[ ${FULL_LOOP} = 1 ] && check_for_buy
# Get current orders
[ ${FULL_LOOP} = 1 ] && get_orders || continue
# Update webpage
if jobs | egrep -q "Running.+webpage" && [ ${FULL_LOOP} = 1 ]
then
g_echo_note "webpage already running"
else
webpage &
fi
## Run strategies
[ ${FULL_LOOP} = 1 ] && run_strategies
done

View File

@@ -1,15 +1,33 @@
#!/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
# Export all functions and vars
set -a
BASEPATH=/dabo/htdocs
# load functions
. /etc/bash/gaboshlib.include
for bashfunc in $(find ${BASEPATH}/../functions -type f -name "*.sh")
do
. "$bashfunc"
done
. /etc/bash/gaboshlib.include
# vars
LANGUAGE="en_US"
@@ -21,6 +39,10 @@ set +a
# prepare directories
mkdir -p ${BASEPATH}/botdata/asset-histories
mkdir -p ${BASEPATH}/botdata/trade-histories
cd ${BASEPATH}/botdata
ECO_ASSETS="DXY DOWJONES SP500 NASDAQ MSCIEAFE 10YRTREASURY GOLD MSCIWORLD OILGAS KRE EUR-USD"
. ../../dabo-bot.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

@@ -0,0 +1,56 @@
#!/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
interval=$1
[ -z "$interval" ] && exit 1
seconds=$2
while true
do
g_echo_note "Next loop"
# Reload Config
. ../../dabo-bot.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
export f_timestamp=$(g_date_print)
# get candles and indicators
get_ohlcv-candles $interval
[[ $interval != 1w ]] && get_marketdata_all $interval
[ -n "$seconds" ] && sleeptime=$(( ( ($seconds - $(TZ=UTC printf "%(%s)T") % $seconds) % $seconds + 2 )))
#[[ $interval = 4h ]] && sleeptime=??
if [ "$interval" = "1d" ]
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"
sleep $sleeptime
done

37
dabo/fetch-orders.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/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"
# Reload Config
. ../../dabo-bot.conf
. ../../dabo-bot.override.conf
# Timestamp
export f_timestamp=$(g_date_print)
# get orders
get_symbols_ticker
get_orders
sleep 3600
done

41
dabo/fetch-symbols_ticker.sh Executable file
View File

@@ -0,0 +1,41 @@
#!/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"
# Reload Config
. ../../dabo-bot.conf
. ../../dabo-bot.override.conf
# Timestamp
export f_timestamp=$(g_date_print)
# get assets
get_symbols_ticker refetchonly || g_echo_warn "Error while refetching tickers from ${STOCK_EXCHANGE}"
#for sym_file in CCXT_SYMBOLS-$STOCK_EXCHANGE CCXT_SYMBOLS-$STOCK_EXCHANGE-by-volume CCXT_SYMBOLS-$STOCK_EXCHANGE-by-volume-trade
#do
# g_echo_note "$sym_file"
# cat "$sym_file"
#done
sleep 3
done

View File

@@ -0,0 +1,42 @@
#!/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
sleep 1800
while true
do
>ALL_TRANSACTIONS_OVERVIEW.csv.tmp
g_echo_note "Next loop"
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
done

View File

@@ -1,36 +0,0 @@
#!/bin/bash
function binance-api-call {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local method=$1
local call=$2
local params=$3
if [ -s /dabo/.binance-secrets ]
then
. /dabo/.binance-secrets
else
g_echo_error "No secrets file found"
return 1
fi
call=$(echo "$call" | sed "s/^\///")
if echo "${call}" | egrep -q "^sapi/|^api/v3/order"
then
params="recvWindow=60000${params}"
local timestamp=$(date +%s000)
params="${params}&timestamp=${timestamp}"
local signature=$(echo -n "${params}" | openssl dgst -sha256 -hmac "${API_SECRET}" | cut -d" " -f2)
params="?${params}&signature=$signature"
fi
echo "curl -s -H \"X-MBX-APIKEY: $API_KEY\" -X \"$method\" \"https://api.binance.com/${call}${params}\"" >${g_tmp}/API_CMD
echo "curl -s -H \"X-MBX-APIKEY: API_KEY\" -X \"$method\" \"https://api.binance.com/${call}${params}\"" >${g_tmp}/API_CMD_WO_KEY
g_runcmd g_retrycmd sh ${g_tmp}/API_CMD >${g_tmp}/API_CMD_OUT 2>&1
if egrep -q -i '^{"code":|error' ${g_tmp}/API_CMD_OUT
then
g_echo_error "$(cat ${g_tmp}/API_CMD_WO_KEY): $(cat ${g_tmp}/API_CMD_OUT)"
return 1
fi
}

View File

@@ -1,142 +0,0 @@
function binance_convert {
# Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# needed vars
local f_ASSET=$1
local f_CURRENCY=$2
local f_QUANTITY=$3
local f_ACTION=$4 # buy or sell
local f_COMMENT=$5
local f_QUANTITY_CURRENCY=$6
local f_DATE=$(date '+%F_%H-%M-%S')
local f_ASSET_HIST_FILE="asset-histories/${f_ASSET}${f_CURRENCY}.history.csv"
local f_market_price=$(tail -n1 ${f_ASSET_HIST_FILE} | cut -d, -f2)
local f_link="https://www.coingecko.com/de/munze/$(egrep -i ^${f_ASSET}, COINGECKO_IDS | cut -d, -f2)"
local f_CMDFILE="trade-histories/${f_DATE}-${f_CURRENCY}-${f_ACTION}-BINANCE_CONVERT-TRADE_CMD"
local f_num_converts=$(find trade-histories/*-*-*-BINANCE_CONVERT-TRADE_CMD -type f -mmin 60 | wc -l)
if [ $f_num_converts -ge 99 ]
then
g_echo_note "Already did 99 or more binance converts last hour."
return 1
fi
# get trade commission for comparison with convert
binance-api-call GET /sapi/v1/asset/tradeFee "&symbol=${f_ASSET}${f_CURRENCY}"
local FEE=$(echo "$(cat $g_tmp/API_CMD_OUT | jq -r .[].takerCommission)*100" | bc -l | sed 's/^\./0./; s/^-\./-0./')
if [ "${f_ACTION}" = "buy" ]
then
# check for enough balance for trade
get_balances
local f_CURRENCY_BALANCE=$(egrep "^${f_CURRENCY}," EXCHANGE_GET_BALANCES_CMD_OUT | cut -d"," -f2)
g_echo_note "Checking for enough balance for trade (${f_CURRENCY_BALANCE} > ${f_QUANTITY})"
if [ $(echo "${f_CURRENCY_BALANCE} > ${f_QUANTITY}" | bc -l) -eq 0 ]
then
local f_note="Not enough balance for trade (${f_CURRENCY_BALANCE} > ${f_QUANTITY}) :${f_COMMENT}
${FUNCNAME} $@"
g_echo_note "$f_note"
g_signal-notify "$f_note"
return 1
fi
# get quote on buy
binance-api-call POST /sapi/v1/convert/getQuote "&fromAsset=${f_CURRENCY}&toAsset=${f_ASSET}&fromAmount=${f_QUANTITY}&walletType=SPOT&validTime=10s" || return 1
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_QUOTE_OUT
# get convert price
local f_convert_price=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .inverseRatio | head -n1)
g_percentage-diff ${f_market_price} ${f_convert_price}
local f_price_diff=${g_percentage_diff_result}
fi
if [ "${f_ACTION}" = "sell" ]
then
# get quote on sell
binance-api-call POST /sapi/v1/convert/getQuote "&fromAsset=${f_ASSET}&toAsset=${f_CURRENCY}&fromAmount=${f_QUANTITY}&walletType=SPOT&validTime=10s" || return 1
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_QUOTE_OUT
# get convert price
local f_convert_price=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .ratio | head -n1)
g_percentage-diff ${f_convert_price} ${f_market_price}
local f_price_diff=${g_percentage_diff_result}
fi
if [ $(echo "${f_price_diff} > ${FEE}" | bc -l) -eq 1 ]
then
local f_note="Price difference between Market Price (${f_market_price} ${f_CURRENCY}) and Binance Convert Price (${f_convert_price} ${f_CURRENCY}) is higher then Trading Fee (${f_price_diff}% > ${FEE}%), so I will better use trade then convert"
g_echo_note "$f_note"
g_signal-notify "$f_note"
return 1
fi
g_echo_note "Price difference between Market Price (${f_market_price}) and Binance Convert Price (${f_convert_price}) is lower then Trading Fee (${f_price_diff} > ${FEE}), so I will use convert"
echo "cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_QUOTE_OUT
local f_quoteid=\$(cat ${g_tmp}/API_CMD_OUT | jq -r '.quoteId')
binance-api-call POST /sapi/v1/convert/acceptQuote \"&quoteId=\${f_quoteid}\"
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT
" >${f_CMDFILE}
# convert/trade
g_echo_note "Command: $(cat ${f_CMDFILE})"
. ${f_CMDFILE}
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT
g_echo_note "Command Output: $(cat ${f_CMDFILE}_OUT)"
# Check return and log trade
f_STATUS=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .orderStatus)
local f_trade_info_msg="CONVERT/TRADE - ${f_ACTION} ${f_ASSET}${f_CURRENCY}
${f_link}
Complete Overview: https://${URL}/
Comment: ${f_COMMENT}"
if echo "${f_STATUS}" | egrep -q "PROCESS|ACCEPT_SUCCESS|SUCCESS"
then
g_echo_note "CONVERT/TRADE SUCCESSFUL!"
[ "${f_ACTION}" = "buy" ] && local f_convert_price=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .inverseRatio | head -n1)
[ "${f_ACTION}" = "sell" ] && local f_convert_price=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .ratio | head -n1)
local f_COMMISSION="0"
local f_COMMISSIONASSET="${f_CURRENCY}"
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY} ${f_CURRENCY},${f_convert_price},${f_COMMISSION} ${f_COMMISSIONASSET},CONVERT ${f_COMMENT}" | head -n1 >>trade-histories/${f_ASSET}${f_CURRENCY}.history.csv
if [ "${f_ACTION}" = "buy" ]
then
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY} ${f_CURRENCY},${f_convert_price},${f_COMMISSION} ${f_COMMISSIONASSET},CONVERT ${f_COMMENT}" | head -n1 >>trade-histories/trade-$(date +%F.%T. | sed 's/:/_/g')${f_ASSET}${f_CURRENCY}-open.history.csv
fi
if [ "${f_ACTION}" = "sell" ]
then
f_tradehistfile="$(ls trade-histories/trade-*${f_ASSET}${f_CURRENCY}-open.history.csv | tail -n1)"
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY_CURRENCY} ${f_CURRENCY},${f_convert_price},${f_COMMISSION} ${f_COMMISSIONASSET},${f_COMMENT}" | head -n1 >>${f_tradehistfile}
f_tradehistfileclosed=$(echo ${f_tradehistfile} | sed 's/open.history.csv/closed.history.csv/')
mv ${f_tradehistfile} ${f_tradehistfileclosed}
fi
g_signal-notify "CONVERT/TRADE SUCCESSFUL!
${f_trade_info_msg}
Command stored: ${f_CMDFILE}[_OUT]"
[ -f DIFF_BUY_PRICE_${f_ASSET}${f_CURRENCY} ] && [ "${f_ACTION}" = "sell" ] && rm -f DIFF_BUY_PRICE_${f_ASSET}${f_CURRENCY}
# get new balances
get_balances
return 0
else
g_echo_note "CONVERT/TRADE FAILED!
$(cat ${f_CMDFILE}_OUT)"
g_signal-notify "CONVERT/TRADE FAILED!
${f_trade_info_msg}
Command ${f_CMDFILE}:
$0 $@
$(cat ${f_CMDFILE})
OUTPUT:
$(cat ${f_CMDFILE}_OUT)
"
return 1
fi
}

View File

@@ -1,46 +0,0 @@
#!/bin/bash
function binance_convert_dust {
# find BNB Balance of an conversion which ran before - Balance takes a while to be shown on BNB
# get BNB balance
binance-api-call GET sapi/v1/capital/config/getall
local f_bnb_balance=$(cat ${g_tmp}/API_CMD_OUT | jq -r '.[] | .coin + "," + .free' | grep "^BNB," | cut -d, -f2)
# convert BNB to $CURRENCY
#if echo "${f_bnb_balance}" | egrep -q "[0-9]\.[0-9]"
if [ $(echo "${f_bnb_balance} > 0.004" | bc -l) -ne 0 ]
then
binance-api-call POST /sapi/v1/convert/getQuote "&fromAsset=BNB&toAsset=${CURRENCY}&fromAmount=${f_bnb_balance}&walletType=SPOT&validTime=30s"
local f_quoteid=$(cat ${g_tmp}/API_CMD_OUT | jq -r '.quoteId')
g_signal-notify "Converting dust from ${f_bnb_balance} BNB to ${CURRENCY}
$(cat ${g_tmp}/API_CMD_OUT)"
binance-api-call POST /sapi/v1/convert/acceptQuote "&quoteId=${f_quoteid}"
fi
# Only run every 6 houres - binance doesn't allow to do it more often
[ -s BINANCE_LAST_DUST_RUN ] || date >BINANCE_LAST_DUST_RUN
find BINANCE_LAST_DUST_RUN -mmin +362 -delete
[ -s BINANCE_LAST_DUST_RUN ] && return 0
date >BINANCE_LAST_DUST_RUN
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# find dust
local f_dust_assets=""
local f_dust
binance-api-call POST /sapi/v1/asset/dust-btc
# ignore $CURRENCY and assets in open trades
for f_dust in $(cat ${g_tmp}/API_CMD_OUT | jq -r '.details[].asset' | egrep -v "${CURRENCY}")
do
ls trade-histories/trade-*.${f_dust}${CURRENCY}-open.history.csv >/dev/null 2>&1 && continue
f_dust_assets="${f_dust_assets},$f_dust"
done
f_dust_assets=$(echo ${f_dust_assets} | sed 's/^,//')
# convert dust to BNB
if [ -n "${f_dust_assets}" ]
then
g_signal-notify "Converting dust from ${f_dust_assets} to BNB"
binance-api-call POST /sapi/v1/asset/dust "&asset=${f_dust_assets}"
fi
}

View File

@@ -1,38 +0,0 @@
function binance_get_token_info {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_ASSET=$1
local f_CURRENCY=$2
local f_QUANTITY=$3
# cleanup cache
[ -s BINANCE_TOKEN_INFO_CMD_OUT ] && find BINANCE_TOKEN_INFO_CMD_OUT -mmin +60 -or -empty -delete
#echo "$BINANCE_CLI_CMD info" >BINANCE_TOKEN_INFO_CMD
#[ -s BINANCE_TOKEN_INFO_CMD_OUT ] || g_runcmd g_retrycmd sh BINANCE_TOKEN_INFO_CMD >BINANCE_TOKEN_INFO_CMD_OUT
if ! [ -s BINANCE_TOKEN_INFO_CMD_OUT ]
then
binance-api-call GET /api/v3/exchangeInfo >BINANCE_TOKEN_INFO_CMD_OUT
cat ${g_tmp}/API_CMD_OUT >BINANCE_TOKEN_INFO_CMD_OUT
fi
# cut quantity by lot-step-size
if ! [ -z "$f_QUANTITY" ]
then
local f_LOT_STEP_SIZE=$(cat BINANCE_TOKEN_INFO_CMD_OUT | jq -c "[ .symbols[] | select( .symbol==\"${f_ASSET}${f_CURRENCY}\") ]" | jq -c '.[].filters[] | select( .filterType=="LOT_SIZE")' | jq -r '.stepSize' | perl -pe 's/0+$//; s/\.$//')
if [ -z "${f_LOT_STEP_SIZE}" ]
then
g_echo "Got no LOT_STEP_SIZE from BINANCE_TOKEN_INFO_CMD_OUT for ${f_ASSET} - Assuming 0.01"
f_LOT_STEP_SIZE="0.01"
fi
local f_LOT_DIV=$(echo "scale=0; ${f_QUANTITY}/${f_LOT_STEP_SIZE}" | bc -l)
f_QUANTITY_LOT_CUT=$(echo "${f_LOT_DIV}*${f_LOT_STEP_SIZE}" | bc -l | sed 's/^\./0./;')
fi
# get min CURRENCY
f_MIN_NOTIONAL=$(cat BINANCE_TOKEN_INFO_CMD_OUT | jq -c "[ .symbols[] | select( .symbol==\"${f_ASSET}${f_CURRENCY}\") ]" | jq -c '.[].filters[] | select( .filterType=="MIN_NOTIONAL")' | jq -r '.minNotional' | perl -pe 's/0+$//; s/\.$//')
if [ -z "${f_MIN_NOTIONAL=}" ]
then
g_echo "Got no LOT_STEP_SIZE from BINANCE_TOKEN_INFO_CMD_OUT for ${f_ASSET} - Assuming 10.00000000"
f_MIN_NOTIONAL="10.00000000"
fi
}

View File

@@ -1,28 +0,0 @@
#!/bin/bash
function onetrading-api-call {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local method=$1
local call=$2
local params=$3
if [ -s /dabo/.onetrading-secrets ]
then
. /dabo/.onetrading-secrets
else
g_echo_error "No secrets file found"
return 1
fi
echo "${call}" | egrep -q "/account/" && local f_token="-H 'Authorization: Bearer ${API_TOKEN}'"
echo "curl -s -X ${method} --url https://api.onetrading.com/${call} $f_token -H 'Accept: application/json' ${params}" >${g_tmp}/API_CMD
echo "curl -s -X ${method} --url https://api.onetrading.com/${call} -H 'Accept: application/json'" >${g_tmp}/API_CMD_WO_KEY
g_runcmd g_retrycmd sh ${g_tmp}/API_CMD >${g_tmp}/API_CMD_OUT 2>&1
if egrep -q -i '^{"code":|error' ${g_tmp}/API_CMD_OUT
then
g_echo_error "$(cat ${g_tmp}/API_CMD_WO_KEY): $(cat ${g_tmp}/API_CMD_OUT)"
return 1
fi
}

View File

@@ -1,32 +0,0 @@
function onetrading_get_token_info {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_ASSET=$1
local f_CURRENCY=$2
f_QUANTITY=$3
# cleanup cache
[ -s ONETRADING_TOKEN_INFO_CMD_OUT ] && find ONETRADING_TOKEN_INFO_CMD_OUT -mmin +60 -or -empty -delete
if ! [ -s ONETRADING_TOKEN_INFO_CMD_OUT ]
then
onetrading-api-call GET public/v1/instruments >ONETRADING_TOKEN_INFO_CMD_OUT
cat ${g_tmp}/API_CMD_OUT >ONETRADING_TOKEN_INFO_CMD_OUT
fi
local f_ASSET_PRECISION=$(cat ONETRADING_TOKEN_INFO_CMD_OUT | jq -r ".[] | select(.state==\"ACTIVE\") | select(.quote.code==\"${f_CURRENCY}\") | select(.base.code==\"${f_ASSET}\") | .amount_precision")
local f_CURRENCY_PRECISION=$(cat ONETRADING_TOKEN_INFO_CMD_OUT | jq -r ".[] | select(.state==\"ACTIVE\") | select(.quote.code==\"${f_CURRENCY}\") | select(.base.code==\"${f_ASSET}\") | .quote.precision")
local f_ASSET_MINSIZE=$(cat ONETRADING_TOKEN_INFO_CMD_OUT | jq -r ".[] | select(.state==\"ACTIVE\") | select(.quote.code==\"${f_CURRENCY}\") | select(.base.code==\"${f_ASSET}\") | .min_size")
local f_ASSET_PRICE=$(tail -n1 "asset-histories/${f_ASSET}${f_CURRENCY}.history.csv" | cut -d"," -f2)
if [ -n "$f_QUANTITY" ] && [ -n "$f_ASSET_PRICE" ]
then
if [ $(echo "${f_ASSET_MINSIZE} < ${f_QUANTITY}" | bc -l) -eq 0 ]
then
f_QUANTITY=$(echo "scale=${f_CURRENCY_PRECISION}; ${f_ASSET_MINSIZE}+1" | bc -l)
fi
f_ASSET_QUANTITY=$(echo "scale=${f_ASSET_PRECISION}; ${f_QUANTITY}/${f_ASSET_PRICE}" | bc -l | sed 's/^\./0./;')
fi
}

102
dabo/functions/calc_ema.sh Normal file
View File

@@ -0,0 +1,102 @@
#!/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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# - needs array ${v_csv_array_associative[${f_column}_${i}] for example from g_read_csv
# - needs $i as position
local f_period=$1 # integer!
local f_column=$2 # column in "$v_csv_array_associative" from which ema should be calculated
local f_target_column=$3 # column with previus EMAs - if not given "ema$f_period" is used
local f_position=$i # position
# check if there is a position (i from loop through array)
[ -z "$f_position" ] && return 1
# check if there is a period (i from loop through array)
[ -z "$f_period" ] && return 2
# check if there is a column (i from loop through array)
[ -z "$f_column" ] && return 3
# get ema column
[ -z "$f_target_column" ] && local f_target_column="ema$f_period"
local f_last_value=${v_csv_array_associative[${f_column}_${f_position}]}
[ -z "$f_target_column" ] && return 4
local f_v
# reset old ema var
unset f_ema
# find last EMA
local f_last_ema_position=$((f_position-1))
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
if [ -n "$f_last_ema" ]
then
# calc EMA with previous EMA if given
g_calc "scale=10; ${f_last_value}*(2/(${f_period}+1))+${f_last_ema}*(1-(2/(${f_period}+1)))"
else
## calc SMA if previous EMA is not given (only needed on first EMA calc)
# 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
for ((f_v=$f_last_period_values_from; f_v<=${f_position}; f_v++))
do
if [ -z ${f_last_period_values} ]
then
f_last_period_values=${v_csv_array_associative[${f_column}_${f_v}]}
else
g_calc "${f_last_period_values}+${v_csv_array_associative[${f_column}_${f_v}]}"
f_last_period_values=$g_calc_result
fi
done
# calc SMA (EMA=SMA in this special first case)
g_calc "($f_last_period_values)/$f_period"
fi
# 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
f_ema=$g_calc_result
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
}

100
dabo/functions/calc_macd.sh Normal file
View File

@@ -0,0 +1,100 @@
#!/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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# - needs array ${v_csv_array_associative} for example from g_read_csv
# - needs $i as position
# - needs $p as previous position
local f_period=$1 # integer!
local f_ema12=$2 # ema12 - if not given "${v_csv_array_associative[ema12_${f_position}]}" is used
local f_ema26=$3 # ema26 - if not given "${v_csv_array_associative[ema26_${f_position}]}" is used
local f_target_column=$4 # column with previus RSIs - if not given "rsi$f_period" is used
local f_position=$i # position
# check if there is a position (i from loop through array)
[ -z "$f_position" ] && return 1
# check for EMA12 and 26
[ -z "$f_ema12" ] && f_ema12="${v_csv_array_associative[ema12_${f_position}]}"
[ -z "$f_ema12" ] && return 2
[ -z "$f_ema26" ] && f_ema26="${v_csv_array_associative[ema26_${f_position}]}"
[ -z "$f_ema26" ] && return 3
# get rsi column
[ -z "$f_target_column" ] && f_target_column="macd"
local f_macd f_macd_ema9_signal f_macd_signal f_macd_histogram_relation f_macd_histogram f_macd_histogram_max f_macd_histogram_strength
g_calc "${f_ema12}-${f_ema26}"
f_macd=$g_calc_result
v_csv_array_associative[macd_${f_position}]=$g_calc_result
# calc MACD Signal
calc_ema 9 macd macd_ema9_signal
[ -z "${v_csv_array_associative[macd_ema9_signal_${f_position}]}" ] && return 5
f_macd_ema9_signal=${v_csv_array_associative[macd_ema9_signal_${f_position}]}
# calc MACD Histogram
g_calc "${f_macd}-(${f_macd_ema9_signal})"
f_macd_histogram=$g_calc_result
v_csv_array_associative[macd_histogram_${f_position}]=$g_calc_result
# check for MACD signal up- or downtrend and buy or sell if switched histogram from - to + or + to -
f_last_histogram=${v_csv_array_associative[macd_histogram_${p}]}
if [ -n "$f_last_histogram" ]
then
f_macd_signal=uptrend
[[ $f_macd_histogram =~ ^- ]] && f_macd_signal=downtrend
[[ $f_macd_histogram =~ ^- ]] && [[ $f_last_histogram =~ ^[0-9] ]] && f_macd_signal=sell
[[ $f_macd_histogram =~ ^[0-9] ]] && [[ $f_last_histogram =~ ^- ]] && f_macd_signal=buy
v_csv_array_associative[macd_histogram_signal_${f_position}]=$f_macd_signal
fi
# check if there is a new macd max value to calculate the strength of the trend
f_macd_histogram_positive=${f_macd_histogram//-/}
f_macd_histogram_max=${v_csv_array_associative[macd_histogram_max_${p}]}
if [ -z "$f_macd_histogram_max" ]
then
# define max for the first time
v_csv_array_associative[macd_histogram_max_${f_position}]=$f_macd_histogram_positive
f_macd_histogram_max=$f_macd_histogram_positive
else
if g_num_is_higher $f_macd_histogram_positive $f_macd_histogram_max
then
v_csv_array_associative[macd_histogram_max_${f_position}]=$f_macd_histogram_positive
f_macd_histogram_max=$f_macd_histogram_positive
else
v_csv_array_associative[macd_histogram_max_${f_position}]=$f_macd_histogram_max
fi
fi
# calculate relative trend strength (percentage 100 = strongest in history)
g_percentage-diff ${f_macd_histogram_max} ${f_macd_histogram_positive}
[ -z "$g_percentage_diff_result" ] && g_percentage_diff_result=0
g_calc "100+(${g_percentage_diff_result})"
f_macd_histogram_strength=${g_calc_result}
v_csv_array_associative[macd_histogram_strength_${f_position}]=$f_macd_histogram_strength
}

107
dabo/functions/calc_rsi.sh Normal file
View File

@@ -0,0 +1,107 @@
#!/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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# - needs array ${v_csv_array_associative[${f_column}_${i}] for example from g_read_csv
# - needs $i as position
local f_period=$1 # integer!
local f_column=$2 # column in "$v_csv_array_associative" from which rsi should be calculated
local f_target_column=$3 # column with previus RSIs - if not given "rsi$f_period" is used
local f_position=$i # position
# check if there is a position (i from loop through array)
[ -z "$f_position" ] && return 1
# check if there is a period if not default to 14
[ -z "$f_period" ] && f_period=14
# check if there is a column (i from loop through array)
[ -z "$f_column" ] && return 3
# check for enough positions/values to calculate (enough values)
[ $f_position -ge $f_period ] || return 0
# get rsi column
[ -z "$f_target_column" ] && f_target_column="rsi$f_period"
local f_last_value=${v_csv_array_associative[${f_column}_${f_position}]}
[ -z "$f_target_column" ] && return 4
local v
# reset old rsi sar
unset f_rsi
# get last $f_period values
local f_last_period_values_from=$((f_position-$f_period+1))
local f_last_period_values_positive=0
local f_last_period_values_negative=0
local f_last_period_num_positive=0
local f_last_period_num_negative=0
for ((v=$f_last_period_values_from; v<=${f_position}; v++))
do
if [[ ${v_csv_array_associative[${f_column}_${v}]} =~ ^- ]]
then
((f_last_period_num_negative++))
f_last_period_values_negative="$f_last_period_values_negative+(${v_csv_array_associative[${f_column}_${v}]})"
else
((f_last_period_num_positive++))
f_last_period_values_positive="$f_last_period_values_positive+${v_csv_array_associative[${f_column}_${v}]}"
fi
done
# add positive and negative values
g_calc "$f_last_period_values_positive"
local f_positive_sum=$g_calc_result
g_calc "$f_last_period_values_negative"
local f_negative_sum=${g_calc_result//-}
# if one of both is "0" then fix results
[ ${f_negative_sum} = "0" ] && f_rsi=100
[ ${f_positive_sum} = "0" ] && f_rsi=0
# calculate RSI
if [ -z "$f_rsi" ]
then
# calculate positive/negative change averages
g_calc "${f_negative_sum}/${f_last_period_num_negative}"
local f_negative_sum_average=$g_calc_result
g_calc "${f_positive_sum}/${f_last_period_num_positive}"
local f_positive_sum_average=$g_calc_result
# calculate RS
g_calc "${f_positive_sum_average}/${f_negative_sum_average}"
local f_rs=$g_calc_result
# calculate RSI
g_calc "100-(100/(1+${f_rs}))"
printf -v f_rsi "%.0f" $g_calc_result
fi
v_csv_array_associative[${f_target_column}_${f_position}]=$f_rsi
}

View File

@@ -1,5 +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 f_ccxt {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# remove old result
unset f_ccxt_result
@@ -14,54 +37,68 @@ function f_ccxt {
return 1
fi
#unset g_ccxt_jobs
#local g_ccxt_jobs
mapfile -t g_ccxt_jobs < <(jobs -r)
# Initialize ccxt in python if not initialized
[[ ${g_ccxt_jobs[*]} =~ *python-pipeexec.py* ]] || unset f_ccxt_initialized
if [ -z "$f_ccxt_initialized" ]
then
g_echo_note "Initializing ccxt"
g_python 'import os' || return 1
g_python 'import sys' || return 1
g_python 'sys.path.append("/ccxt/python")' || return 1
g_python 'import ccxt' || return 1
fi
# Initialize exchange in ccxt if not initialized
if ! [[ "$f_ccxt_initialized" =~ $STOCK_EXCHANGE ]]
then
g_echo_note "Initializing exchange ${STOCK_EXCHANGE} in ccxt"
local f_exchange_type="swap"
[ -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}.load_markets()"
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
f_ccxt_initialized="${f_ccxt_initialized}${STOCK_EXCHANGE},"
fi
# send and receive ccxt command in python - on error kill progress
if ! g_python "$@"
then
kill -9 $(jobs -l | grep python-pipeexec.py | cut -d" " -f 2)
g_echo_warn "Resetting CCXT!!!"
g_kill_all_background_jobs "python3 -iuq"
unset f_ccxt_initialized
return 1
fi
# reference result to python-result
declare -ng f_ccxt_result=g_python_result
# Check for json output
f_ccxt_json_out=""
[[ $f_ccxt_result =~ ^\[ ]] && [[ $f_ccxt_result =~ \]$ ]] && f_ccxt_json_out=1
[[ $f_ccxt_result =~ ^\{ ]] && [[ $f_ccxt_result =~ \}$ ]] && f_ccxt_json_out=1
if [ -n "$f_ccxt_json_out" ]
# Check for json output or empty json output
unset f_ccxt_json_out
if ! [ "$f_ccxt_result" = '[]' ]
then
# make the output jq-conform
[[ $f_ccxt_result =~ ^\[ ]] && [[ $f_ccxt_result =~ \]$ ]] && f_ccxt_json_out=1
[[ $f_ccxt_result =~ ^\{ ]] && [[ $f_ccxt_result =~ \}$ ]] && f_ccxt_json_out=1
fi
if [ -z "$f_ccxt_json_out" ]
then
return 1
else
# make the output jq-conform if json poutput
# avoids errors like: "parse error: Invalid numeric literal at"
f_ccxt_result=${f_ccxt_result//\'/\"}
f_ccxt_result=${f_ccxt_result// None/ null}
f_ccxt_result=${f_ccxt_result// True/ true}
f_ccxt_result=${f_ccxt_result// False/ false}
f_ccxt_result=${f_ccxt_result//,,/,}
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 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// None/ null}
#f_ccxt_result=${f_ccxt_result// True/ true}
#f_ccxt_result=${f_ccxt_result// False/ false}
#f_ccxt_result=${f_ccxt_result//,,/,}
fi
return 0
}

28
dabo/functions/charts.sh Normal file
View File

@@ -0,0 +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 charts {
if ! find ../lightweight-charts.standalone.production.js -mtime -1 2>/dev/null | grep -q "lightweight-charts.standalone.production.js"
then
g_echo_note "Refreshing lightweight-charts.standalone.production.js from https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"
wget ${g_wget_opts} -q https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js -O ../lightweight-charts.standalone.production.js
touch ../lightweight-charts.standalone.production.js
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 check_buy_conditions {
local f_ASSET_HIST_FILE="$1"
@@ -66,42 +86,7 @@ function check_buy_conditions {
# remove CURRENCY from asset
f_ASSET=$(echo ${f_ASSET} | sed "s/${CURRENCY}//")
if [ ${STOCK_EXCHANGE} = "BINANCE" ]
then
# get stock exchange specific infos for trade (e.g. MIN_NOTIONAL)
${TOKEN_INFO_CMD} ${f_ASSET} ${CURRENCY}
# use MIN_NOTIONAL+5% as INVEST_QUANTITY if INVEST_QUANTITY is under MIN_NOTIONAL
# +5% in spite of MIN_NOTIONAL to be able to sell when the price falls a little bit
#[ $(g_calc "${f_INVEST_QUANTITY} < ${f_MIN_NOTIONAL}") -eq 0 ] || f_INVEST_QUANTITY=$(g_calc "scale=2; $f_MIN_NOTIONAL/100*105")
if ! g_num_is_lower.sh ${f_INVEST_QUANTITY} ${f_MIN_NOTIONAL}
then
g_calc "scale=2; ${f_MIN_NOTIONAL}/100*105"
f_INVEST_QUANTITY=${g_calc_result}
fi
# if there is not enough balance for buying because ${f_MIN_NOTIONAL} needed for buying to sell (workaround)
g_calc "${CURRENCY_BALANCE} < ${f_MIN_NOTIONAL}*2"
if [ ${g_calc_result} -ne 0 ]
then
g_echo_note "BUY ${f_ASSET} not enough balance ${CURRENCY_BALANCE} for buying because of MIN_NOTIONAL (${f_MIN_NOTIONAL}*2) needed for buying-to-sell (workaround)"
return 1
fi
# continue if not balance enough for lowest quantity (MIN_NOTIONAL)
g_calc "${CURRENCY_BALANCE} > ${f_INVEST_QUANTITY}"
if [ ${g_calc_result} -eq 0 ]
then
g_echo_note "BUY ${f_ASSET} not enough balance (${CURRENCY_BALANCE}) for lowest quantity (MIN_NOTIONAL - ${f_INVEST_QUANTITY})"
return 1
fi
binance_convert ${f_ASSET} ${CURRENCY} ${f_INVEST_QUANTITY} buy "$f_BUY" || \
do_trade ${f_ASSET} ${CURRENCY} ${f_INVEST_QUANTITY} buy "$f_BUY"
else
do_trade ${f_ASSET} ${CURRENCY} ${f_INVEST_QUANTITY} buy "$f_BUY"
fi
order ${f_ASSET}/${CURRENCY} ${f_INVEST_QUANTITY} buy
f_BUY=""
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 check_for_buy {
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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -19,7 +39,7 @@ function check_for_sell {
then
local f_msg="ATTENTION! EMERGENCY STOP DUE TO POOR PERFORMANCE: BALANCE (${f_COMPLETE_BALANCE}) LOWER THEN EMERGENCY_STOP-VALUE (${EMERGENCY_STOP})"
g_echo_error "${f_msg}"
do_trade ${f_ASSET} ${CURRENCY} ${f_QUANTITY_CURRENCY} sell "${f_msg}"
position_close ${f_ASSET}/${CURRENCY}
continue
fi
if tail -n1 $f_ASSET_HIST_FILE | egrep -q "^$(date +%Y-%m-%d)|$(date +%Y-%m-%d -d yesterday)"
@@ -28,7 +48,7 @@ function check_for_sell {
else
local f_msg="SELL $f_ASSET_HIST_FILE no current data of invested asset"
g_echo_warn "${f_msg}"
do_trade ${f_ASSET} ${CURRENCY} ${f_QUANTITY_CURRENCY} sell "${f_msg}"
position_close ${f_ASSET}/${CURRENCY}
fi
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 check_sell_conditions {
local f_ASSET_HIST_FILE="$1"
@@ -89,14 +109,7 @@ function check_sell_conditions {
g_echo_note "$f_SELL"
echo "${f_last_line},${f_ASSET}" >>trade.log
f_ASSET=$(echo ${f_ASSET} | sed "s/${CURRENCY}//")
# binance_convert ${f_ASSET} ${CURRENCY} ${f_QUANTITY} sell "${f_SELL}"
if [ ${STOCK_EXCHANGE} = "BINANCE" ]
then
binance_convert ${f_ASSET} ${CURRENCY} ${f_QUANTITY} sell "${f_SELL}" ${f_QUANTITY_CURRENCY} || \
do_trade ${f_ASSET} ${CURRENCY} ${f_QUANTITY_CURRENCY} sell "${f_SELL}"
else
do_trade ${f_ASSET} ${CURRENCY} ${f_QUANTITY_CURRENCY} sell "${f_SELL}"
fi
position_close ${f_ASSET}/${CURRENCY}
fi
# # ANALYZE

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 {
#g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_currency_amount=$1
local f_currency=$2
local f_currency_target=$3
local f_currency_date=$4
local f_return
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
[ -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")
# 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
[ -d asset-histories ] && f_asset_histories="asset-histories/"
[ -d asset-histories ] || mkdir asset-histories
f_asset_histories="asset-histories/"
# map USD-Stablecoins to USD
local f_stablecoins="USDT BUSD"
for f_stablecoin in $f_stablecoins
do
# Link USD Stablecoin files to USD
if [ -s ${f_asset_histories}${f_currency}${f_stablecoin}.history-raw.csv ]
then
[ -e ${f_asset_histories}${f_currency}USD.history-raw.csv ] || \
ln ${f_asset_histories}${f_currency}${f_stablecoin}.history-raw.csv ${f_asset_histories}${f_currency}USD.history-raw.csv
fi
if [ -s ${f_asset_histories}${f_currency_target}${f_stablecoin}.history-raw.csv ]
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
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}/USD}
ln -sf "$f_file" "$f_link_file"
done
cd - >/dev/null
# use USD
if [[ $f_currency_target = $f_stablecoin ]]
then
@@ -56,6 +92,29 @@ function currency_converter {
fi
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 [[ $f_currency == $f_currency_target ]]
then
@@ -63,50 +122,71 @@ function currency_converter {
return 0
fi
# try direct pair
get_marketdata_yahoo_historic "${f_currency_target}-${f_currency}" "${f_currency_target}${f_currency}" || get_marketdata_yahoo_historic "${f_currency}-${f_currency_target}" "${f_currency}${f_currency_target}"
local f_histfile_default="${f_asset_histories}${f_currency_target}${f_currency}.history-raw.csv"
local f_histfile_yahoo="${f_asset_histories}${f_currency_target}${f_currency}.history-yahoo.csv"
# reverse as backup
local f_histfile_default_reverse="${f_asset_histories}${f_currency}${f_currency_target}.history-raw.csv"
local f_histfile_yahoo_reverse="${f_asset_histories}${f_currency}${f_currency_target}.history-yahoo.csv"
# define possiblefiles
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"
# search for rate by date
for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse" "$f_histfile_yahoo" "$f_histfile_yahoo_reverse"
for f_histfile in "$f_histfile_default" "$f_histfile_default_reverse"
do
# histfile has to exist
if [ -s "$f_histfile" ]
then
# search for most precise date
f_line=$(egrep "^$f_currency_date_minute" "$f_histfile" | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_hour" "$f_histfile" | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_day" "$f_histfile" | tail -n1)
[ -z "$f_line" ] && f_line=$(egrep "^$f_currency_date_month" "$f_histfile" | 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_line =~ ^$f_currency_date_hour ]] && break
fi
fi
# search for most precise date
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)
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" ]
then
# try workaround over USD if EUR
if [[ ${f_currency_target} = EUR ]] && [[ $f_currency != USD ]]
# if EUR source or traget try way over USD as workaround
if [[ ${f_currency_target} = EUR ]] && [[ $f_currency != USD ]] && [[ $f_currency != EUR ]]
then
#g_echo_note "trying way over USD (workaround)"
if currency_converter $f_currency_amount $f_currency USD $f_currency_date
g_echo_note "trying way over USD (workaround) Target EUR"
if currency_converter $f_currency_amount $f_currency USD "$f_currency_date"
then
f_currency_amount=$f_currency_converter_result
currency_converter $f_currency_amount USD EUR $f_currency_date
return $?
currency_converter $f_currency_converter_result USD EUR "$f_currency_date" && f_return=$?
[[ $f_return == 0 ]] && echo "$@=$f_currency_converter_result" >>CACHE_CURRENCY_CONVERTER
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
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
fi
@@ -115,5 +195,6 @@ function currency_converter {
[[ $f_reverse = false ]] && g_calc "1/${f_rate}*${f_currency_amount}"
f_currency_converter_result=$g_calc_result
}
echo "$@=$f_currency_converter_result" >>CACHE_CURRENCY_CONVERTER
}

View File

@@ -1,159 +0,0 @@
function do_trade {
# Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# needed vars
local f_ASSET=$1
local f_CURRENCY=$2
local f_QUANTITY=$3
local f_ACTION=$4 # buy or sell
local f_COMMENT=$5
local f_DATE=$(date '+%F_%H-%M-%S')
local f_ASSET_HIST_FILE="asset-histories/${f_ASSET}${f_CURRENCY}.history.csv"
local f_link="https://www.coingecko.com/de/munze/$(egrep -i ^${f_ASSET}, COINGECKO_IDS | cut -d, -f2)"
# get stock exchange specific infos for trade (e.g. f_QUANTITY_LOT_CUT; f_MIN_NOTIONAL, precision and minsize)
${TOKEN_INFO_CMD} ${f_ASSET} ${f_CURRENCY} ${f_QUANTITY}
if [ ${STOCK_EXCHANGE} = "BINANCE" ]
then
# get stock exchange specific infos for trade (e.g. f_QUANTITY_LOT_CUT; f_MIN_NOTIONAL)
${TOKEN_INFO_CMD} ${f_ASSET} ${f_CURRENCY} ${f_QUANTITY}
local f_QUANTITY=${f_QUANTITY_LOT_CUT}
#### Workaround for f_QUANTITY_LOT_CUT by buy more and directly sell
g_echo_note "Checking for need of QUANTITY_LOT_CUT Workaround (${f_QUANTITY_LOT_CUT} > ${f_MIN_NOTIONAL})"
if [ $(echo "${f_QUANTITY_LOT_CUT} > ${f_MIN_NOTIONAL}" | bc -l) -eq 0 ] && [ ${f_ACTION} = sell ]
then
# add 0.5 to f_MIN_NOTIONAL and trading fee
local f_MIN_NOTIONAL_WITH_FEE=$(echo "${f_MIN_NOTIONAL}+${FEE}+0.5" | bc -l)
g_echo_note "Doing QUANTITY_LOT_CUT Workaround - buying ${f_MIN_NOTIONAL_WITH_FEE} ${f_ASSET} ${f_CURRENCY}"
do_trade ${f_ASSET} ${f_CURRENCY} ${f_MIN_NOTIONAL_WITH_FEE} buy "Workaround for selling values under QUANTITY_LOT_CUT - buy +MIN_NOTIONAL" || return 1
local f_QUANTITY=$(echo "${f_QUANTITY}+${f_MIN_NOTIONAL}" | bc -l)
fi
fi
if [ "${f_ACTION}" = "buy" ]
then
# check for enough balance for trade
get_balances
local f_CURRENCY_BALANCE=$(egrep "^${f_CURRENCY}," EXCHANGE_GET_BALANCES_CMD_OUT | cut -d"," -f2)
g_echo_note "Checking for enough balance for trade (${f_CURRENCY_BALANCE} > ${f_QUANTITY})"
if [ $(echo "${f_CURRENCY_BALANCE} > ${f_QUANTITY}" | bc -l) -eq 0 ]
then
local f_note="Not enough balance for trade (${f_CURRENCY_BALANCE} > ${f_QUANTITY}) :${f_COMMENT}
${FUNCNAME} $@"
g_echo_note "${f_note}"
g_signal-notify "${f_note}"
return 1
fi
fi
# prepare trading command
local f_CMDFILE="trade-histories/${f_DATE}-${f_CURRENCY}-TRADE_CMD"
[ ${STOCK_EXCHANGE} = "BINANCE" ] && echo "${TRADE_CMD}" | perl -pe "s/ACTION/${f_ACTION}/; s/TOKEN/${f_ASSET}${f_CURRENCY}/; s/QUANTITY/${f_QUANTITY}/" >${f_CMDFILE}
[ ${STOCK_EXCHANGE} = "ONETRADING" ] && echo "${TRADE_CMD}" | perl -pe "s/ACTION/${f_ACTION}/; s/TOKEN/${f_ASSET}_${f_CURRENCY}/; s/QUANTITY/${f_ASSET_QUANTITY}/" >${f_CMDFILE}
# trade
g_echo_note "Command: $(cat ${f_CMDFILE})"
cat ${f_CMDFILE}
#g_runcmd g_retrycmd sh ${f_CMDFILE} >${f_CMDFILE}_OUT
. ${f_CMDFILE}
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT
g_echo_note "Command Output: $(cat ${f_CMDFILE}_OUT)"
# workaround for "insufficient balance" error. lower quantity in 0.1 steps and try again (for values loosing while selling)
if [ ${STOCK_EXCHANGE} = "BINANCE" ]
then
if [ "${f_ACTION}" = "sell" ] && grep -q "Account has insufficient balance for requested action." ${f_CMDFILE}_OUT
then
g_echo_note "workaround for \"insufficient balance\" error."
local f_tries=10
local f_try=1
until (grep -q "FILLED" ${f_CMDFILE}_OUT)
do
sleep 1
f_QUANTITY=$(echo "$f_QUANTITY-0.1" | bc -l | sed 's/^\./0./;')
g_echo_note "lower $f_QUANTITY by -0.1"
echo "${TRADE_CMD}" | perl -pe "s/ACTION/${f_ACTION}/; s/TOKEN/${f_ASSET}${f_CURRENCY}/; s/QUANTITY/${f_QUANTITY}/" >${f_CMDFILE}
#g_runcmd g_retrycmd sh ${f_CMDFILE} >${f_CMDFILE}_OUT
. ${f_CMDFILE}
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT
[ ${f_try} -eq ${f_tries} ] && break
((f_try=f_try+1))
done
fi
fi
# Check return and log trade
[ ${STOCK_EXCHANGE} = "BINANCE" ] && f_STATUS=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .status)
[ ${STOCK_EXCHANGE} = "ONETRADING" ] && f_STATUS=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .order_id)
local f_trade_info_msg="TRADE - ${f_ACTION} ${f_ASSET}${f_CURRENCY}
${f_link}
Complete Overview: https://${URL}/
Comment: ${f_COMMENT}"
if [ "${f_STATUS}" = "FILLED" ] || echo ${f_STATUS} | egrep -q '.+-.+-.+-.+'
then
g_echo_note "TRADE SUCCESSFUL!"
[ ${STOCK_EXCHANGE} = "BINANCE" ] && local f_PRICE=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .fills[].price | head -n1)
[ ${STOCK_EXCHANGE} = "BINANCE" ] && local f_COMMISSION=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .fills[].commission) | head -n1
[ ${STOCK_EXCHANGE} = "BINANCE" ] && local f_COMMISSIONASSET=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .fills[].commissionAsset | head -n1)
if [ ${STOCK_EXCHANGE} = "ONETRADING" ]
then
sleep 10
onetrading-api-call GET public/v1/account/trades
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT_ONETRADING_TRADE
local f_PRICE=$(cat ${f_CMDFILE}_OUT_ONETRADING_TRADE | jq -r ".trade_history | .[] | select(.trade.order_id==\"${f_STATUS}\") | .trade.price")
local f_COMMISSION=$(cat ${f_CMDFILE}_OUT_ONETRADING_TRADE | jq -r ".trade_history | .[] | select(.trade.order_id==\"${f_STATUS}\") | .fee.fee_amount")
local f_COMMISSIONASSET=$(cat ${f_CMDFILE}_OUT_ONETRADING_TRADE | jq -r ".trade_history | .[] | select(.trade.order_id==\"${f_STATUS}\") | .fee.fee_currency")
fi
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY} ${f_CURRENCY},${f_PRICE},${f_COMMISSION} ${f_COMMISSIONASSET},${f_COMMENT}" | head -n1 >>trade-histories/${f_ASSET}${f_CURRENCY}.history.csv
if [ "${f_ACTION}" = "buy" ]
then
if echo ${f_COMMENT} | grep -q "Workaround for selling values under QUANTITY_LOT_CUT"
then
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY} ${f_CURRENCY},${f_PRICE},${f_COMMISSION} ${f_COMMISSIONASSET},${f_COMMENT}" | head -n1 >>trade-histories/trade-*${f_ASSET}${f_CURRENCY}-open.history.csv
else
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY} ${f_CURRENCY},${f_PRICE},${f_COMMISSION} ${f_COMMISSIONASSET},${f_COMMENT}" | head -n1 >>trade-histories/trade-$(date +%F.%T. | sed 's/:/_/g')${f_ASSET}${f_CURRENCY}-open.history.csv
fi
fi
if [ "${f_ACTION}" = "sell" ]
then
f_tradehistfile="$(ls trade-histories/trade-*${f_ASSET}${f_CURRENCY}-open.history.csv | tail -n1)"
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY} ${f_CURRENCY},${f_PRICE},${f_COMMISSION} ${f_COMMISSIONASSET},${f_COMMENT}" | head -n1 >>${f_tradehistfile}
f_tradehistfileclosed=$(echo ${f_tradehistfile} | sed 's/open.history.csv/closed.history.csv/')
mv ${f_tradehistfile} ${f_tradehistfileclosed}
fi
g_signal-notify "TRADE SUCCESSFUL!
${f_trade_info_msg}
Command stored: ${f_CMDFILE}[_OUT]"
[ -f DIFF_BUY_PRICE_${f_ASSET}${f_CURRENCY} ] && [ "${f_ACTION}" = "sell" ] && rm -f DIFF_BUY_PRICE_${f_ASSET}${f_CURRENCY}
# get new balances
get_balances
else
g_echo_note "TRADE FAILED!
$(cat ${f_CMDFILE}_OUT)"
g_signal-notify "TRADE FAILED!
${f_trade_info_msg}
Command ${f_CMDFILE}:
$0 $@
$(cat ${f_CMDFILE})
OUTPUT:
$(cat ${f_CMDFILE}_OUT)
"
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 genchart {
# generate css chart (line diagram) from csv file or simple file with number per line - needed charts.css included in webppage
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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -8,7 +28,11 @@ function get_asset {
[ -f "${f_ASSET_HIST_FILE}" ] || echo "Date and Time,Price" >"${f_ASSET_HIST_FILE}"
local f_line="${f_timestamp},$(grep "^${f_ASSET}," CCXT_TICKERS | cut -d, -f2)"
#local f_line="${f_timestamp},$(grep "^${f_ASSET}," CCXT_TICKERS | cut -d, -f2)"
local f_price=$(grep "^${f_ASSET}," CCXT_TICKERS | cut -d, -f2)
# exponential number (9.881e-05) to normal
[[ $f_price =~ ^(-)?(\.)?[0-9]+(\.)?([0-9]+)?(e-[0-9]+)?$ ]] && printf -v f_price -- "%.10f" "$f_price"
local f_line="$f_timestamp,$f_price"
echo "${f_line}" >>${f_ASSET_HIST_FILE}
local f_linecount=0
@@ -31,7 +55,7 @@ function get_asset {
return 0
fi
[ ${FULL_LOOP} == 0 ] && return 0
#[ ${FULL_LOOP} == 0 ] && return 0
grep -q "^$(echo "${f_timestamp}" | cut -d: -f1,2)" "${f_ASSET_HIST_FILE}" || return 0
f_ASSET_HIST_FILE="asset-histories/${f_ASSET}.history.csv"
#if find "${f_ASSET_HIST_FILE}" -mmin -${INTERVAL_MIN} | grep -q "${f_ASSET_HIST_FILE}"
@@ -41,7 +65,7 @@ function get_asset {
#fi
# headline
#[ -s "${f_ASSET_HIST_FILE}" ] || echo "${csv_headline}" >"${f_ASSET_HIST_FILE}"
[ -s "${f_ASSET_HIST_FILE}" ] || echo "${csv_headline}" >"${f_ASSET_HIST_FILE}"
if [ -s "${f_ASSET_HIST_FILE}" ]
then
sed -i -e 1c"$csv_headline" "${f_ASSET_HIST_FILE}"

View File

@@ -1,43 +0,0 @@
function get_assets {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
## determine assets with prices
if [ ${STOCK_EXCHANGE} = "NONE" ]
then
f_no_exchange=1
return 0
else
f_ccxt "print(${STOCK_EXCHANGE}.fetch_tickers())" && [ -n "$f_ccxt_json_out" ] && echo $f_ccxt_result >CCXT_TICKERS_RAW
fi
jq -r '.[] | .symbol + "," + (.last|tostring)' CCXT_TICKERS_RAW | sed "s/:${CURRENCY},/,/; s/\///" | grep "${CURRENCY}," >CCXT_TICKERS
# Write file with asset list and ignore marketcap under LARGEST_MARKETCAP
cat CCXT_TICKERS | cut -d"," -f1 | while read f_ASSET
do
# ignore marketcap under LARGEST_MARKETCAP
f_assetwocurrency=$(echo ${f_ASSET} | sed "s/$CURRENCY$//")
if ! egrep -q "^${f_assetwocurrency}$" SORTMARKETCAP
then
#g_echo_note "Ignoring $f_ASSET because of lower marketcap then Top ${LARGEST_MARKETCAP}"
continue
fi
echo ${f_ASSET} >>ASSETS.tmp
done
mv ASSETS.tmp ASSETS
## write histfiles parallel
local f_ASSET
local f_parallel_arg
echo -n "parallel -j3 bash -c --" >/tmp/parallel
for f_ASSET in $(cat ASSETS | egrep -v "${BLACKLIST}")
do
#get_asset "${f_ASSET}"
echo -n " \"get_asset ${f_ASSET}\"" >>/tmp/parallel
done
export f_timestamp
export csv_headline
. /tmp/parallel
}

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_balance {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
f_ccxt "print(${STOCK_EXCHANGE}.fetch_balance ({\"currency\": \"$CURRENCY\"}))" && [ -n "$f_ccxt_json_out" ] && echo $f_ccxt_result >CCXT_BALANCE
f_ccxt "print(${STOCK_EXCHANGE}.fetch_balance ({\"currency\": \"$CURRENCY\"}))" && echo $f_ccxt_result >CCXT_BALANCE
# get current investmentbalance
f_CURRENCY_BALANCE=$(jq -r ".${CURRENCY}.free" CCXT_BALANCE)
@@ -12,6 +32,7 @@ function get_balance {
printf -v CURRENCY_BALANCE %.2f ${f_CURRENCY_BALANCE}
else
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
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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
@@ -38,7 +58,7 @@ function get_bitpanda_api_transactions {
select(.effective_leverage!= null) |
.time.date_iso8601 + ",leverage-" + .type + "," + .cryptocoin_symbol + "," + .amount_cryptocoin + ",EUR," + .amount_fiat + ",Bitpanda"
' 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
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 {
# get data from coingecko
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 {
local f_hist_file="$1"

View File

@@ -0,0 +1,237 @@
#!/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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_last_intervals="$1"
local f_histfile f_symbol
# 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
if [ -s "${f_histfile}.fetching" ] || [ -s "${f_histfile}.indicators-calculating" ]
then
g_echo_note "Fetching/Indicators-calculating already active on ${f_histfile}"
continue
fi
# do the job
printf "$0 %(%Y-%m-%d %H:%M:%S)T" >"${f_histfile}.indicators-calculating"
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
#f_add_missing_ohlcv_intervals "${f_histfile}"
rm -f "${f_histfile}.indicators-calculating"
done
shopt -s nullglob
# find all history files of traded symbols
get_symbols_ticker
for f_symbol in "${f_symbols_array_trade[@]}"
do
f_symbol=${f_symbol%%:*}
f_symbol=${f_symbol//\/}
for f_histfile in "asset-histories/${f_symbol}.history."[0-5][5dhwm]*.csv
do
if [ -s "$f_histfile" ]
then
# check for already running jobs
if [ -s "${f_histfile}.fetching" ] || [ -s "${f_histfile}.indicators-calculating" ]
then
g_echo_note "Fetching/Indicators-calculating active on ${f_histfile}"
continue
fi
# do the job
printf "$0 %(%Y-%m-%d %H:%M:%S)T" >"${f_histfile}.indicators-calculating"
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"
fi
done
done
shopt -u nullglob
}
function get_indicators {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_histfile="$1"
local f_last_intervals="$2"
local f_fill_missing_ohlcv_intervals=$3
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
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_rsis="5 14 21"
local f_ema f_change f_changed f_line f_valid_data f_ath f_last_year
local f_columns_space="${f_columns//,/ }"
g_read_csv "${f_histfile}" "${f_last_intervals}" "$f_columns"
for ((i=0; i<=${#g_csv_array[@]}-1; i++))
do
if [ -z "${v_csv_array_associative[date_${i}]}" ] || [ -z "${v_csv_array_associative[open_${i}]}" ]
then
g_echo_note "No data $f_histfile:${v_csv_array_associative[date_${i}]}"
return 0
fi
#g_echo_note "=== $0 for $f_histfile:${v_csv_array_associative[date_${i}]},$f_histfile:${v_csv_array_associative[close_${i}]}"
# get previous position
p=$((i-1))
### check for unfilled fields
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
if [ -z "${v_csv_array_associative[change_${i}]}" ]
then
# special for changes watched per year like CPI,...
if [[ $f_histfile = "asset-histories/MARKETDATA_US_CONSUMER_PRICE_INDEX_CPI.history.1d.csv" ]] || \
[[ $f_histfile = "asset-histories/MARKETDATA_US_UNEMPLOYMENT_RATE.history.1d.csv" ]]
then
if [ $i -ge 12 ]
then
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
# ath (all-time-high) of present data
if [ -z "${v_csv_array_associative[ath_${p}]}" ]
then
# define max for the first time
v_csv_array_associative[ath_${i}]=${v_csv_array_associative[high_${i}]}
else
#echo "g_num_is_higher ${v_csv_array_associative[high_${i}]} ${v_csv_array_associative[ath_${p}]}"
if g_num_is_higher ${v_csv_array_associative[high_${i}]} ${v_csv_array_associative[ath_${p}]}
then
v_csv_array_associative[ath_${i}]=${v_csv_array_associative[high_${i}]}
else
v_csv_array_associative[ath_${i}]=${v_csv_array_associative[ath_${p}]}
fi
fi
# check for missing EMAs
for f_ema_column in $f_emas
do
# check for enough values/lines to calculate EMA if no previous EMA given
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
if [ -z "${v_csv_array_associative[ema${f_ema_column}_${i}]}" ]
then
calc_ema ${f_ema_column} close && f_change=1
fi
done
# check for missing RSI
for f_rsi_column in $f_rsis
do
# check for enough values/lines to calculate RSI
[ $i -ge $f_rsi_column ] || continue
# calculate RSI
[ -z "${v_csv_array_associative[rsi${f_rsi_column}_${i}]}" ] && calc_rsi ${f_rsi_column} change && f_change=1
done
# check for missing macd
[ $i -ge 26 ] && [ -z "${v_csv_array_associative[macd_${i}]}" ] && calc_macd && f_change=1
# write to file if change is provided
if [ -n "$f_change" ]
then
# find line by date
f_line_date="${v_csv_array_associative[date_${i}]}"
oldIFS=$IFS
IFS=,
f_line=""
# build line
for f_column in $f_columns
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" ]
then
f_line="${v_csv_array_associative[${f_column}_${i}]}"
else
f_line="$f_line,${v_csv_array_associative[${f_column}_${i}]}"
fi
done
g_echo_note "Changing values with date ${v_csv_array_associative[date_${i}]} in \"${f_histfile}\""
# replace line by date
sed -i "s/$f_line_date,.*/$f_line/" "$f_histfile"
IFS=$oldIFS
fi
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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -0,0 +1,210 @@
#!/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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_levelsfile f_level f_symbol f_symbol_in_array t_timeframe f_lines $f_relevant_lines
get_symbols_ticker
for f_symbol in "${f_symbols_array_trade[@]}"
do
f_symbol=${f_symbol%%:*}
f_symbol=${f_symbol//\/}
# get current price to reduce the range, save cpu-power and time
f_symbol_in_array=${f_symbol/ /}
f_price=${f_tickers_array[$f_symbol_in_array]}
for f_timeframe in 1w 1d #4h 1h 15m
do
f_levelsfile="asset-histories/${f_symbol}.history.$f_timeframe.csv"
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
}
function get_levels {
# estimates the relevant levels from price list from array f_prices and put then in array f_levels
# needs levels csv file with prices in ohlcv
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# reset old levels var
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
# # some key points
local f_lowest_price=${f_prices[-1]}
local f_highest_price=${f_prices[1]}
local f_number_of_prices=${#f_prices[@]}
# calc percentual price range
g_percentage-diff $f_highest_price $f_lowest_price
# calc threshold (avarage of percentual price difference)
local f_price_range_percentage=${g_percentage_diff_result//-/}
# g_calc "$f_price_range_percentage / $f_number_of_prices * 0.07" || return 1
# local f_threshold=$g_calc_result
# # calc threshold in range (1/100 of percentual range)
# g_calc "$f_threshold * 11 " || return 1
# local f_threshold_in_range=$g_calc_result
# how much occurencies / same prices have so show up for a defined level
local f_min_occurrences=7
if [[ $f_levelsfile =~ \.1w\. ]]
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
for ((i=0; i<${#f_prices[@]}-1; i++))
do
#echo "$i of ${#f_prices[@]}"
# pair this and next element
j=$((i+1))
f_threshold_test=$f_threshold
f_baseprice=${f_prices[i]}
# if we are in a level use current avarage price of level
if [ -n "$f_level_count" ]
then
#g_calc "($f_level_prices)/$f_level_count"
#f_baseprice=$g_calc_result
f_baseprice=$f_level_first_price
f_threshold_test=$f_threshold_in_range
fi
# pair similiar?
if g_num_is_approx ${f_prices[j]} $f_baseprice $f_threshold_test $f_threshold_test
then
# first number of similars?
if [ -z "$f_level_count" ]
then
# new level
unset f_zone
f_level_count=2
f_level_prices="${f_prices[i]}+${f_prices[j]}"
f_level_first_price=${f_prices[i]}
f_zone+=("${f_prices[i]}")
f_zone+=("${f_prices[j]}")
else
# add values to level
f_level_count=$((f_level_count+1))
f_level_prices="$f_level_prices+${f_prices[j]}"
f_zone+=("${f_prices[j]}")
fi
#echo "level ($f_level_count): $f_level_prices"
else
if [ -n "$f_level_count" ]
then
# end of level
#if [ "$f_level_count" -ge "$f_min_occurrences" ]
if g_num_is_higher_equal $f_level_count $f_min_occurrences
then
g_median ${f_zone[@]}
f_levels+=("$g_median_result")
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
f_level_prices=""
f_level_count=""
f_level_first_price=""
fi
fi
done
}

View File

@@ -1,123 +0,0 @@
function get_macd_indicator {
#g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# get histfile
local f_hist_file="$1"
# define or clean gloval macdvars
f_macd_ema12=""
f_macd_ema26=""
f_macd=""
f_macd_ema9_signal=""
f_macd_signal=""
if ! [ -s "$f_hist_file" ]
then
g_echo_warn "${FUNCNAME} $@: Histfile $f_hist_file does not exist or is empty"
return 1
fi
# read last two lines
local f_lastline=$(tail -n1 "$f_hist_file" | grep ^2)
# force min 15min 2 last lines
local f_second_lastline=$(tail -n2 "$f_hist_file" | head -n1 | grep ^2)
# Try to get current MACD values
local f_macd_lastprice=$(echo "$f_lastline" | cut -d, -f2)
f_macd_ema12=$(echo "$f_lastline" | cut -d, -f4)
f_macd_ema26=$(echo "$f_lastline" | cut -d, -f5)
f_macd=$(echo "$f_lastline" | cut -d, -f6)
f_macd_ema9_signal=$(echo "$f_lastline" | cut -d, -f7)
# if data is complete
if [ -n "${f_macd_ema12}" ] && [ -n "${f_macd_ema26}" ] && [ -n "${f_macd}" ] && [ -n "${f_macd_ema9_signal}" ]
then
g_echo_note "${FUNCNAME} $@: Looks like current MACD was already calculated"
return 1
fi
# Try to get last MACD values
f_macd_last_ema12=$(echo "$f_second_lastline" | cut -d, -f4)
f_macd_last_ema26=$(echo "$f_second_lastline" | cut -d, -f5)
f_macd_last=$(echo "$f_second_lastline" | cut -d, -f6)
f_macd_last_ema9_signal=$(echo "$f_second_lastline" | cut -d, -f7)
f_macd_last_histogram=$(echo "$f_second_lastline" | cut -d, -f8)
# calc EMA12
get_ema "${f_hist_file}" 2 12 "${f_macd_last_ema12}" "${f_macd_lastprice}"
if [ -z "${f_ema}" ]
then
g_echo_note "${FUNCNAME} $@: Not enough data for calculating EMA12 - waiting for more values"
echo -n ",,,,,," >>"${f_hist_file}"
return 0
fi
f_macd_ema12=${f_ema}
echo -n ",${f_macd_ema12}" >>"${f_hist_file}"
# calc EMA26
if [ -z "${f_macd_last_ema12}" ]
then
echo -n ",,,,," >>"${f_hist_file}"
return 0
fi
get_ema "${f_hist_file}" 2 26 "${f_macd_last_ema26}" "${f_macd_lastprice}"
if [ -z "${f_ema}" ]
then
g_echo_note "${FUNCNAME} $@: Not enough data for calculating EMA26 - waiting for more values"
echo -n ",,,,," >>"${f_hist_file}"
return 0
fi
f_macd_ema26=${f_ema}
echo -n ",${f_macd_ema26}" >>"${f_hist_file}"
# calc MACD
if [ -z "${f_macd_ema26}" ]
then
echo -n ",,,," >>"${f_hist_file}"
return 0
fi
#[ -z "${f_macd_ema12}" ] && return 0
f_macd=$(echo "scale=8; ${f_macd_ema12}-${f_macd_ema26}" | bc | sed 's/^\./0./; s/^-\./-0./')
echo -n ",${f_macd}" >>"${f_hist_file}"
# calc MACD Signal
if [ -z "${f_macd}" ]
then
echo -n ",,," >>"${f_hist_file}"
return 0
fi
get_ema "${f_hist_file}" 6 9 "${f_macd_last_ema9_signal}" "${f_macd}"
if [ -z "${f_ema}" ]
then
g_echo_note "${FUNCNAME} $@: Not enough data for calculating EMA9 Signal - waiting for more values"
echo -n ",,," >>"${f_hist_file}"
return 0
fi
f_macd_ema9_signal=${f_ema}
echo -n ",${f_macd_ema9_signal}" >>"${f_hist_file}"
# calc MACD Histogram
f_macd_histogram=$(echo "scale=10; ${f_macd}-(${f_macd_ema9_signal})" | bc | sed 's/^\./0./; s/^-\./-0./')
echo -n ",${f_macd_histogram}" >>"${f_hist_file}"
# check for MACD buy or sell signal
echo ${f_macd_histogram} | grep -q "^-" && echo ${f_macd_last_histogram} | grep -q "^[0-9]" && f_macd_signal="sell"
echo ${f_macd_histogram} | grep -q "^[0-9]" && echo ${f_macd_last_histogram} | grep -q "^-" && f_macd_signal="buy"
# calculate MACD Histogram relation
if [ $(tail -n36 "${f_hist_file}" | wc -l) -ge 35 ]
then
local f_macd_histogram_max=$(tail -n350 "${f_hist_file}" | cut -d"," -f8 | egrep "^[0-9]|^-[0-9]" | sed 's/^-//' | sort -n | tail -n1)
g_percentage-diff ${f_macd_histogram_max} ${f_macd_histogram}
#local f_macd_histogram_relation=$(echo "100+$(g_percentage-diff ${f_macd_histogram_max} ${f_macd_histogram})" | bc | sed 's/^\./0./; s/^-\./-0./' | cut -d\. -f1)
g_calc "100+${g_percentage_diff_result}"
local f_macd_histogram_relation=${g_calc_result}
fi
echo -n ",${f_macd_histogram_relation}|${f_macd_signal}" >>"${f_hist_file}"
}

View File

@@ -1,100 +1,162 @@
#!/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_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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
get_marketdata_from_url YM=F DOW-JONES-INDEX
get_marketdata_from_url ES=F SP500-INDEX
get_marketdata_from_url NQ=F NASDAQ-INDEX
get_marketdata_from_url MFS=F MSCI-EAFE-INDEX
get_marketdata_from_url ZB=F 10-YEAR-TREASURY-YIELD-INDEX
get_marketdata_from_url MCL=F OIL-INVERTED-INDEX
get_marketdata_from_url GC=F GOLD-INDEX
get_marketdata_from_url IWDA.AS MSCI-WORLD-INDEX
get_marketdata_from_url IEO OIL-GAS-INVERTED-INDEX
get_marketdata_from_url KRE KRE-BANKING-INDEX
get_marketdata_from_url DX=F DXY-INVERTED-INDEX
get_marketdata_from_url EURUSD=X EURUSD
get_marketdata_from_url https://www.investing.com/economic-calendar/unemployment-rate-300/ US-UNEMPLOYMENT-INDEX
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
get_marketdata_from_url '"https://fapi.binance.com/futures/data/globalLongShortAccountRatio?symbol=BTCUSDT&period=5m" | jq -r .[].longShortRatio | tail -n1' BINANCE-BTC-GlobalLongShortAccountRatio
get_marketdata_from_url '"https://fapi.binance.com/futures/data/takerlongshortRatio?symbol=BTCUSDT&period=5m" | jq -r .[].buySellRatio | tail -n1' BINANCE-BTC-TakerLongShortRatio
get_marketdata_from_url '"https://fapi.binance.com/futures/data/openInterestHist?symbol=BTCUSDT&period=5m" | jq -r .[].sumOpenInterest | tail -n1' BINANCE-BTC-OpenInterest
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
find asset-histories/*INDEX* -type f -mtime +6 -delete
}
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
function get_marketdata_from_url {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_url="$1"
local f_name="$2"
## get data for analysis
if find asset-histories/${f_name}.history.csv -mmin -${INTERVAL_MIN} 2>/dev/null | grep -q "asset-histories/${f_name}.history.csv"
# download
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
if [ -n "$f_failed" ]
then
g_echo_note "asset-histories/${f_name}.history.csv already downloaded in the last ${INTERVAL_MIN} minutes"
f_get_marketdata_price=$(cat MARKET_DATA_CMD_OUT-${f_name})
return 0
echo "g_wget -O \"${f_histfile}.wget.tmp\" $f_wget 2>\"${f_histfile}.err\"" >"${f_histfile}.err"
fi
# check source platform for parsing parameters, prepare and run wget command
>MARKET_DATA_CMD
if echo "${f_url}" | grep -q "boerse.de"
# jd
if [ -z "$f_failed" ] && [ -n "$f_jq" ]
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
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
get_marketdata_yahoo_historic "$f_url" "$f_name"
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
if ! jq -r "$f_jq" "${f_histfile}.wget.tmp" >"${f_histfile}.tmp" 2>"${f_histfile}.err.tmp"
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
g_echo_note "${f_name}: ${f_get_marketdata_price_tmp}"
mv MARKET_DATA_CMD_OUT-${f_name}.tmp MARKET_DATA_CMD_OUT-${f_name}
fi
else
g_echo_warn "MARKET_DATA_CMD_OUT-${f_name}.tmp has wrong Syntax. - Not updating ${f_name} Index.
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
if ! [ -e "MARKET_DATA_CMD_OUT-${f_name}" ]
then
local f_old_value=$(tail -n 1 asset-histories/${f_name}.history.csv | cut -d, -f2)
if echo ${f_old_value} | egrep -q "^[0-9]*\.[0-9]+"
then
echo ${f_old_value} >MARKET_DATA_CMD_OUT-${f_name}
else
echo 0 >MARKET_DATA_CMD_OUT-${f_name}
mv "${f_histfile}.tmp" "${f_histfile}.wget.tmp"
fi
fi
f_get_marketdata_price=$(cat MARKET_DATA_CMD_OUT-${f_name})
echo "${f_timestamp},${f_get_marketdata_price}" >>asset-histories/${f_name}.history.csv
# 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
else
mv "${f_histfile}.wget.tmp" "${f_histfile}.tmp"
fi
# 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
cat "${f_histfile}.err.tmp" >>"${f_histfile}.err"
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
cat "${g_tmp}/${FUNCNAME}.tmp" >"${f_histfile}"
fi
fi
rm "${f_histfile}.tmp"
# 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,71 +0,0 @@
function get_marketdata_yahoo_historic {
#g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_item="$1"
local f_name="$2"
local f_targetcsv="asset-histories/${f_name}.history-yahoo.csv"
local f_targetcsvtmp="${g_tmp}/${f_name}.history-yahoo.csv"
[[ $f_item = "USD-EUR" ]] && f_item="USDEUR=X"
[[ $f_item = "EUR-USD" ]] && f_item="EURUSD=X"
[[ $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"
# end if already failed the last hour
if [ -f FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD ]
then
find "FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD" -mmin +60 -delete
if [ -f FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD ]
then
#g_echo_note "${f_targetcsv} already failed to downloaded within last hour"
return 1
fi
fi
# end if already exists and modified under 1 day
if [ -s "${f_targetcsv}" ] && find "${f_targetcsv}" -mtime -1 | grep -q "${f_targetcsv}"
then
#g_echo_note "${f_targetcsv} has already been downloaded within a day"
return 0
fi
local f_sec
printf -v f_sec '%(%s)T'
# cleanup
rm -f "$f_targetcsvtmp" "${f_targetcsvtmp}".err
# Download historical data from yahoo
#g_echo_note "Fetching Yahoo-Historical data of $f_name"
g_wget -O ${f_targetcsvtmp} "https://query1.finance.yahoo.com/v7/finance/download/${f_item}?period1=0&period2=${f_sec}&interval=1d&events=history" 2>"${f_targetcsvtmp}".err
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_targetcsvtmp}" "${f_targetcsv}" | sort -u >"${f_targetcsv}.tmp"
mv "${f_targetcsv}.tmp" "${f_targetcsv}"
elif [ -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_targetcsvtmp}" >"$f_targetcsv"
else
# report error
# g_echo_note "Fetching historical data of $f_name from Yahoo failed!
#CMD:
#wget -q -O ${f_targetcsvtmp} ${g_wget_opts} \"https://query1.finance.yahoo.com/v7/finance/download/${f_item}?period1=0&period2=${f_sec}&interval=1d&events=history\"
#
#OUT:
#$(cat "${f_targetcsvtmp}")
#
#ERR:
#$(cat "${f_targetcsvtmp}".err)
#"
mv ${f_targetcsvtmp}.err FAILED_YAHOO_${f_name}_HISTORIC_DOWNLOAD
return 1
fi
}

View File

@@ -0,0 +1,162 @@
#!/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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_item="$1"
local f_name="$2"
local f_timeframe="$3"
#local f_targetcsv="asset-histories/${f_name}.history-yahoo.csv"
local f_targetcsvtmp="${g_tmp}/${f_name}.history-yahoo.csv"
local f_targetjsontmp="${g_tmp}/${f_name}.history-yahoo.json"
rm -f "$f_targetcsvtmp" "$f_targetjsontmp"
[ -z "$f_timeframe" ] && f_timeframe="1d"
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_histfile_yahoo="$f_targetcsv"
# transform CCXT symbols to Yahoo symbol
if [[ $f_item =~ / ]]
then
# change / to -
f_item=${f_item////-}
# remove :* (:USDT in contract markets)
f_item=${f_item//:*}
# remove spaces
f_item=${f_item/ /}
fi
# USDT to USD
f_item=${f_item//USDT/USD}
# BUSD to USD
f_item=${f_item//BUSD/USD}
# special names of some economy data/indexes of yahoo finance
[[ $f_item = "DXY" ]] && f_item="DX=F"
[[ $f_item = "DOWJONES" ]] && f_item="YM=F"
[[ $f_item = "SP500" ]] && f_item="ES=F"
[[ $f_item = "NASDAQ" ]] && f_item="NQ=F"
[[ $f_item = "MSCIEAFE" ]] && f_item="MFS=F"
[[ $f_item = "MSCIWORLD" ]] && f_item="IWDA.AS"
[[ $f_item = "10YRTREASURY" ]] && f_item="ZB=F"
[[ $f_item = "OIL" ]] && f_item="MCL=F"
[[ $f_item = "GOLD" ]] && f_item="GC=F"
[[ $f_item = "OILGAS" ]] && f_item="IEO"
[[ $f_item = "USD-EUR" ]] && f_item="USDEUR=X"
[[ $f_item = "EUR-USD" ]] && f_item="EURUSD=X"
# end if already failed the last 5 minutes
if [ -f "FAILED_YAHOO/${f_name}_HISTORIC_DOWNLOAD" ]
then
find "FAILED_YAHOO/${f_name}_HISTORIC_DOWNLOAD" -mmin +5 -delete
if [ -f "FAILED_YAHOO/${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
local f_sec
printf -v f_sec '%(%s)T'
# cleanup
rm -f "$f_targetcsvtmp" "${f_targetcsvtmp}".err ${f_targetjsontmp} "${f_targetjsontmp}".err
local f_from
[ "$f_timeframe" = "5m" ] && f_from=$(date -d "now -86000 minutes" +%s)
[ "$f_timeframe" = "15m" ] && f_from=$(date -d "now -86000 minutes" +%s)
[ "$f_timeframe" = "1h" ] && f_from=$(date -d "now -17510 hour" +%s)
[ "$f_timeframe" = "1d" ] && f_from=1
[ "$f_timeframe" = "1wk" ] && f_from=1
[ "$f_timeframe" = "1mo" ] && f_from=1
# Download data from yahoo
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
# Create csv from json
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
# remove last/open timeframe (use only closed)
sed -i '$d' "${f_targetcsvtmp}.unixtime"
# change unix time to human readable and fill unfilled lines, ignore lines not with 00 secolds (last line)
local date_time open high low close lastopen lasthigh lastlow lastclose volume
while IFS=, read -r timestamp open high low close volume
do
if [ "$f_timeframe" = "1d" ] || [ "$f_timeframe" = "1mo" ]
then
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
if ! [ -s "${f_targetcsvtmp}" ]
then
mkdir -p FAILED_YAHOO
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)
return 1
fi
# put the csvs together
# history-yahoo file
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
# 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

@@ -0,0 +1,667 @@
#!/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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_histfile f_symbol f_timeframe f_1h_histfile f_1d_histfile
local f_timeframes="1w 1d 4h 1h 15m 5m"
[ -n $1 ] && f_timeframes=$1
# fetch economy candles from yahoo finance
local f_eco_asset
for f_eco_asset in $ECO_ASSETS
do
for f_timeframe in $f_timeframes
do
g_echo_note "Fetching/Refreshing $f_eco_asset $f_timeframe"
f_histfile="asset-histories/ECONOMY-${f_eco_asset}.history.${f_timeframe}.csv"
# 4h timeframe does not exist on yahoo finance so calc from 1h
if [ "$f_timeframe" = "4h" ]
then
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"
f_add_missing_ohlcv_intervals "$f_histfile" 4h
else
#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
# refresh latest indicators
[ -s "${f_histfile}" ] && get_indicators "${f_histfile}" 51
done
done
# fetch crypto candles
get_symbols_ticker
for f_symbol in BTC/$CURRENCY "${f_symbols_array_trade[@]}"
do
# fetch only single symbols (for debugging)
#[ "$f_symbol" = "BTC/USDT:USDT" ] || continue
g_echo_note "Fetching/Refreshing $f_symbol $f_timeframe"
for f_timeframe in $f_timeframes
do
f_asset="${f_symbol//:*}"
f_asset="${f_asset///}"
f_histfile="asset-histories/$f_asset.history.$f_timeframe.csv"
#f_histfile_week="asset-histories/$f_asset.history.1w.csv"
if [ -s "${f_histfile}.indicators-calculating" ]
then
g_echo_note "Indicators calculating active on ${f_histfile}"
continue
fi
# get data
printf '%(%Y-%m-%d %H:%M:%S)T' >"${f_histfile}.fetching"
get_ohlcv-candle "$f_symbol" $f_timeframe "${f_histfile}" && printf '%(%Y-%m-%d %H:%M:%S)T' >>"$f_histfile.fetched"
# refresh latest indicators
get_indicators "${f_histfile}" 51
rm -f "${f_histfile}.fetching"
done
done
}
function get_ohlcv-candle {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
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_timeframe=$2
local f_histfile="$3"
local f_asset=$4
unset f_histfile_yahoo f_histfile_coinmarketcap
#[ -n "$f_asset" ] && f_extdata=1
#local f_histfile_week="$4"
# fetch >=1d from coinmarketcap
if [ "$f_timeframe" = "1d" ] || [ "$f_timeframe" = "1w" ] || [ "$f_timeframe" = "1mo" ] || [ -n "$f_asset" ]
then
f_extdata=1
if [ -z "$f_asset" ]
then
f_asset=${f_symbol///}
f_asset=${f_asset//:*}
fi
if [[ $f_asset =~ ^ECONOMY- ]]
then
# economy from yahoo finance
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
# fetch OHLCV data (loop because of multiple chunks on exchanges)
while true
do
# fetch data
if [ -z "$f_extdata" ]
then
# find latest time which is not fetched already create f_since
get_ohlcv-candle-latest "$f_symbol" "$f_histfile"
[ -z $f_since ] && break
# from exchange
g_echo_note "Get $f_symbol OHLCV-candle $f_timeframe data since $f_since_date"
f_ccxt "print($STOCK_EXCHANGE.fetchOHLCV(symbol='$f_symbol', timeframe='$f_timeframe', since=$f_since))" || return 1
# parse the result to array f_data_array
f_data=${f_ccxt_result//[}
f_data=${f_data//, /,}
f_data=${f_data//]]}
f_data=${f_data//],/+}
g_array $f_data f_data_ref +
else
# from coinmarketcap/yahoo
g_array "$f_histfile_extdata" f_data_ref
fi
f_data_array=("${f_data_ref[@]}")
# check if last data already in history file and end if already present
g_array "${f_data_array[-1]}" f_last_data_unit_ref ,
[ -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_extdata" ] && f_last_unit_date="${f_last_data_unit_ref[0]}"
# exit if we have already in the newest date
[ -s "$f_histfile" ] && grep -q ^"${f_last_unit_date}," "$f_histfile" && break
# go through data and write to history file if new units available
for f_data_unit in "${f_data_array[@]}"
do
# use array for each unit and assigned values to vars
g_array "$f_data_unit" f_data_unit_ref ,
[ -z "$f_extdata" ] && printf -v f_unit_date '%(%Y-%m-%d %H:%M:%S)T' ${f_data_unit_ref[0]::-3}
[ -n "$f_extdata" ] && f_unit_date="${f_last_data_unit_ref[0]}"
# check if date is already in history file
[ -s "$f_histfile" ] && grep -q ^"$f_unit_date" "$f_histfile" && continue
# define field vars and convert exponential number (for example 9.881e-05) to "normal" notation
f_open=$f_last_unit_close
if [ -z "$f_open" ]
then
f_open=${f_data_unit_ref[1]}
fi
g_num_exponential2normal "$f_open" && f_open=$g_num_exponential2normal_result
f_high=${f_data_unit_ref[2]}
g_num_exponential2normal "$f_high" && f_high=$g_num_exponential2normal_result
f_low=${f_data_unit_ref[3]}
g_num_exponential2normal "$f_low" && f_low=$g_num_exponential2normal_result
f_close=${f_data_unit_ref[4]}
g_num_exponential2normal "$f_close" && f_close=$g_num_exponential2normal_result
f_last_unit_close=$f_close
f_volume=${f_data_unit_ref[5]}
# coinmarketcap historic volume col 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
# check date for valid date
if ! [[ $f_unit_date =~ ^2[0-1][0-9][0-9]-[0-1][0-9]-[0-3][0-9]( [0-2][0-9]:[0-5][0-9]:[0-5][0-9])?$ ]]
then
g_echo_warn "Date $f_unit_date \"$f_data_unit\" seems to be invalid @$f_histfile:$f_data_unit"
break
fi
# check vars for valid numbers
if ! g_num_valid_number "$f_open" "$f_high" "$f_low" "$f_close" "$f_volume"
then
g_echo_warn "Data in \"$f_data_unit\" seems to be invalid @$f_histfile:$f_unit_date
$f_open $f_high $f_low $f_close $f_volume"
break
fi
# write history file
#echo "$f_unit_date,$f_open,$f_high,$f_low,$f_close,$f_volume"
echo "$f_unit_date,$f_open,$f_high,$f_low,$f_close,$f_volume" >>"$f_histfile"
done
# end if coinmarketcap (complete file and not time chunks)
[ -n "$f_extdata" ] && break
# end if lates refresh is this day
printf -v f_date '%(%Y-%m-%d)T\n'
#echo "[ $f_date = $f_since_date ]"
if [ $f_date = $f_since_date ]
then
break
fi
done
}
function get_ohlcv-candle-latest {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_symbol="$1"
local f_histfile="$2"
#local f_histfile_week="$3"
# find latest time which is not fetched already
[ -s "$f_histfile" ] && local f_last_line=$(tail -n1 "$f_histfile" | grep ^[0-9] | cut -d, -f1,5)
if [ -n "$f_last_line" ]
then
# get latest date from histfile if it exists
local f_last_line=$(tail -n1 "$f_histfile" | grep ^[0-9] | cut -d, -f1,5)
f_since=$(date -d "${f_last_line/,*/}" +%s000)
f_last_unit_close=${f_last_line/*,/}
else
# if hist does not exist
# get week to find the oldest point in time available in exchange
f_ccxt "print($STOCK_EXCHANGE.fetchOHLCV(symbol='$f_symbol', timeframe='1w'))" || return 0
# parse oldest point in time from json output
f_since=${f_ccxt_result//[}
f_since=${f_since//, /,}
f_since=${f_since//]*}
f_since=${f_since//,*}
fi
# get the date
printf -v f_since_date '%(%Y-%m-%d)T\n' ${f_since::-3}
}
function convert_ohlcv_1h_to_4h {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_input_file="$1"
local f_output_file="$2"
local f_high=0
local f_volume=0
local f_tz f_hour f_lastdate f_currentdate f_latest_date f_go_on f_1h_open f_1h_high f_1h_low f_1h_close f_1h_volume f_date f_open f_low f_close f_4hintervals f_rest
# possibloe 4h intervals
local f_4hintervals0='^0$|^4$|^8$|^12$|^16$|^20$'
local f_4hintervals1='^1$|^5$|^9$|^13$|^17$|^21$'
local f_4hintervals2='^2$|^6$|^10$|^14$|^18$|^22$'
local f_4hintervals3='^3$|^7$|^11$|^15$|^19$|^23$'
# check for already converted lines
if [ -s "$f_output_file" ]
then
f_latest_date=$(tail -n1 "$f_output_file" | cut -d, -f1)
else
f_go_on=1
fi
# Read the input file line by line
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
# check for already converted lines
if [[ $f_latest_date = $f_date ]]
then
f_go_on=1
continue
fi
[ -z "$f_go_on" ] && continue
f_currentdate="${f_date:0:13}"
# define intervals by considering local/servers TZ with summer and winter season
f_hour=${f_date:11:2}
f_hour=${f_hour#0}
f_tz=$(date -d "$f_currentdate" +%:z)
f_tz=${f_tz//:*}
f_tz=${f_tz#+}
f_tz=${f_tz#-}
f_tz=${f_tz#0}
f_4hintervals=$f_4hintervals0
[[ $f_tz =~ ^1$|^5$|^9$|^13$ ]] && f_4hintervals=$f_4hintervals1
[[ $f_tz =~ ^2$|^6$|^10$|^14$ ]] && f_4hintervals=$f_4hintervals2
[[ $f_tz =~ ^3$|^7$|^11$ ]] && f_4hintervals=$f_4hintervals3
# is there a new 4h interval
if [[ $f_hour =~ $f_4hintervals ]]
then
# If it's not the first loop, print the previous 4h interval before cleaning the variables
#if [ -n "$f_lastdate" ]
if [ -n "$f_open" ]
then
echo "${f_lastdate}:00:00,$f_open,$f_high,$f_low,$f_close,$f_volume"
fi
# reset the variables for the new 4h interval
f_low=""
f_high=0
f_lastdate=$f_currentdate
f_volume=0
# set open for next interval to close from last interval
f_open=$f_close
fi
# set close to 1h close
f_close=$f_1h_close
# check if the current value is higher or lower than the current high/low
g_num_is_higher_equal $f_1h_high $f_high && f_high=$f_1h_high
[ -z "$f_low" ] && f_low=$f_1h_low
g_num_is_lower_equal $f_1h_low $f_low && f_low=$f_1h_low
# add volume to the current 4h volume
g_calc "$f_volume + $f_1h_volume"
f_volume=$g_calc_result
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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_histfile="$1"
local f_interval="$2"
[[ $f_interval = 5m ]] && f_interval=300
[[ $f_interval = 15m ]] && f_interval=900
[[ $f_interval = 1h ]] && f_interval=3600
[[ $f_interval = 4h ]] && f_interval=14400
[[ $f_interval = 1d ]] && f_interval=86400
# get interval from filename if not given
if [ -z "$f_interval" ]
then
[[ $f_histfile =~ \.5m\. ]] && f_interval=300
[[ $f_histfile =~ \.15m\. ]] && f_interval=900
[[ $f_histfile =~ \.1h\. ]] && f_interval=3600
[[ $f_histfile =~ \.4h\. ]] && f_interval=14400
[[ $f_histfile =~ \.1d\. ]] && f_interval=86400
fi
# 1w should be complete in every case
[[ $f_interval = 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 f_open f_counter
# 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
do
#echo "$f_curr_date" 1>&2
# if prev date is not empty
if [ -z "$f_prev_date" ]
then
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"
continue
fi
#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
((f_counter++))
#echo "$f_curr_date xx $f_counter" 1>&2
# get second timestamps
f_prev_date_in_seconds=$(date -d"$f_prev_date" +%s)
f_curr_date_in_seconds=$(date -d"$f_curr_date" +%s)
# echo [ "$f_prev_date_in_seconds" -gt "$f_curr_date_in_seconds" ] # && break
# calculate/check the next timestamp from previous
# and check for summer/winter time in 4h or greater interval
if [ $f_interval -gt 3600 ]
then
# 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"
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"
fi
if [ $g_calc_result -gt $f_interval ]
then
# 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 ))
# and calculate next timestamp
g_calc "$f_curr_date_in_seconds - $f_prev_date_in_seconds"
# change date format if day or week
if [ $f_interval -lt 86400 ]
then
f_missing_date=$(date -d"@$f_curr_date_in_seconds" +"%F %T")
else
f_missing_date=$(date -d"@$f_curr_date_in_seconds" +"%F")
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
[ -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
else
f_prev_date=$f_curr_date
[ -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
fi
done
done < "$f_histfile" > $g_tmp/f_add_missing_ohlcv_intervals_result
# replace old file with new if they are different
if ! cmp --silent "$f_histfile" "$g_tmp/f_add_missing_ohlcv_intervals_result"
then
g_echo_note "Replacing $f_histfile"
#diff "$g_tmp/f_add_missing_ohlcv_intervals_result" "$f_histfile"
cat "$g_tmp/f_add_missing_ohlcv_intervals_result" >"$f_histfile"
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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

View File

@@ -0,0 +1,135 @@
#!/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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_symbol=$1
local f_symbol_file
# get orders of all symbols available if symbol argument is not given
local f_symbols=()
if [ -z "$f_symbol" ]
then
for f_symbol in "${f_symbols_array_trade[@]}"
do
if [ -z "$LEVERAGE" ]
then
[[ $f_symbol =~ /${CURRENCY}$ ]] && f_symbols+=("$f_symbol")
else
[[ $f_symbol =~ /${CURRENCY}:${CURRENCY}$ ]] && f_symbols+=("$f_symbol")
fi
done
else
f_symbols+=("$f_symbol")
fi
[ -z "$f_symbols" ] && return 1
for f_symbol in ${f_symbols_array_trade[@]}
do
f_symbol_file=${f_symbol//:*}
f_symbol_file=${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}'))"
then
echo $f_ccxt_result | tee "CCXT_ORDERS_${f_symbol_file}_RAW" | jq -r "
.[] |
select(.status==\"open\") |
.symbol + \",\" + .type + \",\" + .side + \",\" + (.price|tostring) + \",\" + (.amount|tostring) + \",\" + .id + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring) + \",\" + (.stopPrice|tostring)
" >"CCXT_ORDERS_${f_symbol_file}"
else
rm -f "CCXT_ORDERS_${f_symbol_file}_RAW" "CCXT_ORDERS_${f_symbol_file}"
continue
fi
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,11 +1,33 @@
#!/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 {
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
for f_symbol in "${f_symbols_array[@]}"
for f_symbol in "${f_symbols_array_trade[@]}"
do
if [ -z "$LEVERAGE" ]
then
@@ -16,46 +38,133 @@ function get_positions {
done
[ -z "$f_symbols" ] && return 1
f_ccxt "print($STOCK_EXCHANGE.fetchPositions(symbols=[${f_symbols}]))" && [ -n "$f_ccxt_json_out" ] && 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 "
.[] |
select(.entryPrice != 0) |
.symbol + \",\" + (.notional|tostring) + \",\" + (.entryPrice|tostring) + \",\" + (.markPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring)
" CCXT_POSITIONS_RAW >POSITIONS
.symbol + \",\" + (.collateral|tostring) + \",\" + (.entryPrice|tostring) + \",\" + .side + \",\" + (.leverage|tostring) + \",\" + (.liquidationPrice|tostring) + \",\" + (.stopLossPrice|tostring) + \",\" + (.takeProfitPrice|tostring) + \",\" + (.contracts|tostring)
" 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 {
g_array POSITIONS f_get_positions_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
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 {
local f_pos_line=$1
g_array $f_pos_line f_position_array ,
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_current_price=${f_position_array[3]}
f_position_side=${f_position_array[4]}
p[${f_asset}_entry_price]=$f_position_entry_price
# 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"
f_position_leverage=${f_position_array[5]}
[ -z "$f_position_leverage" ] && f_position_leverage="1"
g_percentage-diff $f_position_entry_price $f_position_current_price
[ "$f_position_side" = short ] && g_percentage-diff $f_position_current_price $f_position_entry_price
f_position_pnl_percentage=$g_percentage_diff_result
if [ -n $f_position_leverage ]
p[${f_asset}_side]=$f_position_side
f_position_leverage=${f_position_array[4]}
[[ $f_position_leverage = null ]] && f_position_leverage="1"
p[${f_asset}_leverage]=$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
g_calc "$f_position_pnl_percentage*$f_position_leverage"
f_position_pnl_percentage=$g_calc_result
g_calc "$f_position_currency_amount/$f_position_leverage"
f_position_currency_amount=$g_calc_result
g_calc "$f_position_currency_amount/100*$f_position_pnl_percentage"
f_position_pnl=$g_calc_result
unset p[${f_asset}_stoploss_price]
unset f_position_stoploss_price
else
p[${f_asset}_stoploss_price]=${f_position_array[6]}
f_position_stoploss_price=${f_position_array[6]}
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
# 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 {
#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 {
#g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# get histfile

View File

@@ -1,28 +0,0 @@
function get_symbols {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
f_ccxt "print($STOCK_EXCHANGE.symbols)"
if [ -z "$f_ccxt_json_out" ]
then
g_echo_warn "Could not get symbols list - no json output"
return 1
fi
local f_symbols=${f_ccxt_result}
f_symbols=${f_symbols//\"}
f_symbols=${f_symbols//, /+}
f_symbols=${f_symbols//\[}
f_symbols=${f_symbols//\]}
if [ -z "$f_symbols" ]
then
g_echo_warn "Could not get symbols list - empty"
return 1
fi
g_array "$f_symbols" f_symbols_array +
printf '%s\n' "${f_symbols_array[@]}" >SYMBOLS-$STOCK_EXCHANGE
}

View File

@@ -0,0 +1,129 @@
#!/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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_fetch=$1
local f_symbols
## determine assets with prices
[ ${STOCK_EXCHANGE} = "NONE" ] && return 0
# refetch from exchange
if [ "$f_fetch" = "refetchonly" ]
then
# fetch from exchange
rm -f CCXT_TICKERS-${STOCK_EXCHANGE}.tmp
f_ccxt "print(${STOCK_EXCHANGE}.fetch_tickers())" && echo $f_ccxt_result >CCXT_TICKERS_RAW-${STOCK_EXCHANGE}
# parse relevant tokens
local f_grep="${CURRENCY},"
[ -n "$LEVERAGE" ] && f_grep="${CURRENCY}:${CURRENCY},"
[ -s CCXT_TICKERS_RAW-${STOCK_EXCHANGE} ] && jq -r '.[] | .symbol + "," + (.last|tostring)' CCXT_TICKERS_RAW-${STOCK_EXCHANGE} | grep "${f_grep}" | egrep ".+,[0-9]" >CCXT_TICKERS-${STOCK_EXCHANGE}.tmp
if [ -s CCXT_TICKERS-${STOCK_EXCHANGE}.tmp ]
then
cat CCXT_TICKERS-${STOCK_EXCHANGE}.tmp >CCXT_TICKERS-$STOCK_EXCHANGE
cut -d, -f1 CCXT_TICKERS-${STOCK_EXCHANGE}.tmp >CCXT_SYMBOLS-${STOCK_EXCHANGE}
## get symbols by volume from history files and check with CCXT_SYMBOLS-$STOCK_EXCHANGE
[ -n "$LEVERAGE" ] && f_naming="${CURRENCY}:${CURRENCY}"
tail -n1 asset-histories/*.history.1w.csv 2>/dev/null \
| perl -pe "s/<==\n//; s/==> //; s/\.csv /,/g; s/\//./; s/$CURRENCY\.history\.1w/\/${f_naming}./" \
| grep ",$(date +%Y)-" \
| sort -r -n -t, -k7 \
| cut -d. -f2 \
>CCXT_SYMBOLS-$STOCK_EXCHANGE-by-volume.tmp
# add mising (not yet fetched) symbols
awk 'NR==FNR{a[$0];next} !($0 in a)' CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp CCXT_SYMBOLS-$STOCK_EXCHANGE >>CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp
# remove (no more) existing symbols
awk 'NR==FNR{a[$0];next} !($0 in a)' CCXT_SYMBOLS-$STOCK_EXCHANGE CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp \
| while read f_remove_symbol
do
sed -i "\#${f_remove_symbol}#d" CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp
done
# write filan volume file
[ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp ] && mv CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume.tmp CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume
# write file with symbols that should be traded
rm -f CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade.tmp
for f_symbol in $SYMBOLS
do
grep "^$f_symbol/$CURRENCY" CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume >>CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade.tmp
done
[ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade.tmp ] && mv CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade.tmp CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade
else
return 1
fi
return 0
fi
# create associative ticker array
if [ -s CCXT_TICKERS-$STOCK_EXCHANGE ]
then
g_array CCXT_TICKERS-$STOCK_EXCHANGE f_tickers_array_ref
local f_ticker f_symbol f_price
declare -Ag f_tickers_array
declare -Ag v
declare -Ag vr
for f_ticker in "${f_tickers_array_ref[@]}"
do
f_symbol=${f_ticker%%:*}
f_symbol=${f_symbol//\/}
#f_symbol=${f_symbol/ /}
f_price=${f_ticker/*,/}
g_num_exponential2normal $f_price && f_price=$g_num_exponential2normal_result
f_tickers_array[$f_symbol]=$f_price
vr[${f_symbol}_price]=$f_price
v[${f_symbol}_price]=$f_price
done
fi
# create array with ccxt symbols sorted by volume
[ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume ] && g_array CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume f_symbols_array_ref
f_symbols_array=("${f_symbols_array_ref[@]}")
# create array with ccxt symbols sorted by volume which sould be traded
[ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade ] && g_array CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume-trade f_symbols_array_trade_ref
f_symbols_array_trade=("${f_symbols_array_ref[@]}")
# create f_symbols var
[ -s CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume ] && f_symbols=$(cat CCXT_SYMBOLS-${STOCK_EXCHANGE}-by-volume)
f_symbols=${f_symbols//$'\n'/'+'}
if [ -z "$f_symbols" ]
then
if [ "$f_fetch" = "retry" ]
then
g_echo_warn "Could not get symbols list - empty"
return 1
fi
sleep 5
g_echo_note "Could not get symbols list - empty - retrying"
get_symbols_ticker retry || return 1
fi
}

View File

@@ -1,9 +1,31 @@
#!/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 {
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_LEVERAGE=$LEVERAGE
for f_exchange in /dabo/.*-secrets;
do
@@ -18,13 +40,16 @@ function get_transactions {
g_echo_note "Exchange: $f_exchange"
get_symbols
#f_ccxt "print(${STOCK_EXCHANGE}.symbols)"
#f_symbols=${f_ccxt_result}
#f_symbols=${f_symbols//\"}
#f_symbols=${f_symbols//, /+}
#f_symbols=${f_symbols//\[}
#f_symbols=${f_symbols//\]}
# refetch symbols if not default exchange
if ! [[ $DEFAULT_STOCK_EXCHANGE = $STOCK_EXCHANGE ]]
then
unset LEVERAGE
get_symbols_ticker refetchonly
LEVERAGE=$DEFAULT_LEVERAGE
fi
# load symbols to array
get_symbols_ticker
# transfer-dir
mkdir -p "TRANSACTIONS-$f_exchange"
@@ -32,15 +57,11 @@ function get_transactions {
touch --time=mtime -t $(date -d "now -1 day" +%Y%m%d%H%M) TRANSACTIONS-TIMESTAMP
# go through symbols
#local f_orig_IFS=$IFS
#IFS=+
#for f_symbol in $f_symbols
for f_symbol in "${f_symbols_array[@]}"
do
#echo $f_symbol
#[[ $f_symbol =~ ETH|BTC ]] || continue
#IFS=$f_orig_IFS
# binance does not allow derivate trading in germany so ignore because of 400-Error
#f_symbol=${f_symbol//,*}
# binance does not allow derivate trading in many countries so ignore because of 400-Error
[[ $f_symbol =~ : ]] && [[ $f_exchange = binance ]] && continue
f_symbol_file="TRANSACTIONS-$f_exchange/${f_symbol//\/}"
@@ -49,19 +70,31 @@ function get_transactions {
# fetch only if not exists
[ -f "$f_symbol_file" ] && continue
g_echo_note "fetching closed orders of $f_symbol on $f_exchange"
f_ccxt "print(${STOCK_EXCHANGE}.fetchMyTrades(symbol='$f_symbol', limit=500, params={'paginate': True}))"
g_echo_note "fetching closed orders of $f_symbol on ${STOCK_EXCHANGE}"
# write to file
#cat ${g_python_out} >"$f_symbol_file"
[[ $f_ccxt_result = \[\] ]] && f_ccxt_result=""
# fetch and reset/store return code
f_return=""
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"
# continue if no trade
[ -z "$f_ccxt_result" ] && continue
# continue if fetch failed/empty
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)
g_array $f_symbol f_symbol_array /
g_array "$f_symbol" f_symbol_array /
f_asset=${f_symbol_array[0]}
f_currency=${f_symbol_array[1]}
@@ -77,8 +110,7 @@ function get_transactions {
f_leverage="leverage-"
# get funding fees
f_ccxt "print(${STOCK_EXCHANGE}.fetchFundingHistory('$f_symbol', limit=200, params={'paginate': True}))"
[[ $f_ccxt_result = \[\] ]] || 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 "
.[] |
.datetime + \",fundingfee,$f_asset,0,\" + .code + \",0\" + \",$f_exchange,\" + .code + \",\" + (.amount|tostring)
@@ -90,33 +122,33 @@ function get_transactions {
fi
# generate csv
# get longs (posSide=="1")
# get spot buy/sell (posSide=="1")
cat "$f_symbol_file" | jq -r "
.[] |
select(.side==\"buy\" or .side==\"sell\") |
select(.info.posSide==\"1\") |
select(.symbol!= null) |
.datetime + \",$f_leverage\" + .side + \",$f_asset,\" + (.amount|tostring) + \",$f_currency,\" + (.cost|tostring) + \",$f_exchange,\" + .fee.currency + \",\" + (.fee.cost|tostring)
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) + \",\" + .id
" >>"$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 "
.[] |
select(.side==\"sell\") |
select(.info.posSide==\"2\") |
select(.symbol!= null) |
.side = \"sell\" |
.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"
cat "$f_symbol_file" | jq -r "
.[] |
select(.side==\"buy\") |
select(.info.posSide==\"2\") |
select(.symbol!= null) |
.side = \"buy\" |
.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"
# # get longs (posSide=="1")
# cat "$f_symbol_file" | jq -r "
#.[] |
# select(.side==\"buy\" or .side==\"sell\") |
# select(.info.posSide=\"1\") |
# select(.symbol!= null) |
#.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"
#
# # get shorts (posSide=="2") sell first, then buy (https://github.com/ccxt/ccxt/issues/22518)
# cat "$f_symbol_file" | jq -r "
#.[] |
# select(.side==\"buy\" or .side==\"sell\") |
# select(.info.posSide==\"2\") |
# select(.symbol!=null) |
#.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"
if [ -s "$f_symbol_file_csv_tmp" ]
then
@@ -137,6 +169,7 @@ function get_transactions {
## Get converts on supported exchanges since 2022
if [[ $f_exchange = binance ]]
then
local m y
printf -v f_convert_end_year '%(%Y)T'
for ((y=2022;y<=$f_convert_end_year;y++))
do
@@ -145,15 +178,15 @@ function get_transactions {
for ((m=1;m<=$f_convert_end_month;m++))
do
f_start_date="$(date -d "$y-$m-1" +%s)001"
em=$((m+1))
[ $em = 13 ] && em=1
f_end_date="$(date -d "$y-$em-1" +%s)000"
#em=$((m+1))
#[ $em = 13 ] && em=1
#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"
[ -s "${f_convert_file}.csv" ] && continue
f_ccxt "print(${f_exchange}.fetchConvertTradeHistory(since=${f_start_date}, params={'until': ${f_end_date}}))"
[[ $f_ccxt_result = \[\] ]] && f_ccxt_result=""
f_ccxt "print(${f_exchange}.fetchConvertTradeHistory(since=${f_start_date}, params={'until': ${f_end_date}}))" || f_ccxt_result=""
echo -n $f_ccxt_result >"$f_convert_file"
if [ -s "$f_convert_file" ]
@@ -174,14 +207,20 @@ function get_transactions {
done
fi
# put all sorted n one file
if [ -s TRANSACTIONS-$f_exchange.csv ]
then
cat "TRANSACTIONS-$f_exchange/"*.csv TRANSACTIONS-$f_exchange.csv | sort -u >TRANSACTIONS-$f_exchange.csv.tmp
mv TRANSACTIONS-$f_exchange.csv.tmp TRANSACTIONS-$f_exchange.csv
else
cat "TRANSACTIONS-$f_exchange/"*.csv | sort -u >TRANSACTIONS-$f_exchange.csv
fi
# put all sorted in one file. duplicates check with id
local f_line f_date f_sym
touch "TRANSACTIONS-$f_exchange.csv"
grep -vh ,fundingfee, "TRANSACTIONS-$f_exchange/"*.csv | while read f_line
do
f_id=$(echo "$f_line" | cut -d, -f10)
grep -q "$f_id" "TRANSACTIONS-$f_exchange.csv" || echo $f_line >>"TRANSACTIONS-$f_exchange.csv"
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
f_fiats="USD EUR"
@@ -195,7 +234,7 @@ function get_transactions {
g_echo_note "Switched some fiat/krypto sides"
#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.tmp | sort >TRANSACTIONS-$f_exchange.csv
cat TRANSACTIONS-$f_exchange.csv.tmp >TRANSACTIONS-$f_exchange.csv
fi
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 {
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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"

226
dabo/functions/order.sh Normal file
View File

@@ -0,0 +1,226 @@
#!/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 {
# Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# needed vars
local f_symbol=$1
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_price=$4 # price for limit order - if "0" do market order - "stoploss" for pure StopLoss Order and "takeprofit" for pure TakeProfit Order
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 ###
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]
[[ $f_symbol =~ /$CURRENCY ]] || return 1
# check side
if [ "$f_side" = "long" ] || [ "$f_side" = "buy" ]
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
# check order type limit/market
if [[ $f_price = 0 ]]
then
f_type="market"
elif [[ $f_price = stoploss ]]
then
f_type="stoploss"
f_price="None"
elif [[ $f_price = takeprofit ]]
then
f_type="takeprofit"
f_price="None"
else
f_type="limit"
fi
### validity checks end ###
# get amount in target asset
if [[ $f_amount =~ ^asset_amount: ]]
then
# if given in target
f_amount=${f_amount//asset_amount:}
else
# on market order use current price
if [[ $f_type = market ]]
then
# if given in $CURRENCY
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
if [ -n "$LEVERAGE" ]
then
# do some margin things
# check for CCXT swap symbol :$CURRENCY
[[ $f_symbol =~ : ]] || f_symbol="$f_symbol:$CURRENCY"
# set position mode
f_ccxt "$STOCK_EXCHANGE.setPositionMode(hedged=False, symbol='$f_symbol')" || return 1
# set leverage
f_ccxt "$STOCK_EXCHANGE.setLeverage($LEVERAGE, '$f_symbol')" || return 1
# define margin mode isolated/cross
#[[ $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
# short/sell not possible in spot market
[[ $f_side =~ ^sell$ ]] || return 1
fi
# 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_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,30 +0,0 @@
#!/bin/bash
# https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md
function phemex-api-call {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local method=$1
local call=$2
local params=$3
if [ -s /dabo/.phemex-secrets ]
then
. /dabo/.phemex-secrets
else
g_echo_error "No secrets file found"
return 1
fi
echo "${call}" | egrep -q "/account/" && local f_token="-H 'Authorization: Bearer ${API_TOKEN}'"
echo "curl -s -X ${method} --url https://api.phemex.com/${call} $f_token -H 'Accept: application/json' ${params}" >${g_tmp}/API_CMD
echo "curl -s -X ${method} --url https://api.phemex.com/${call} -H 'Accept: application/json'" >${g_tmp}/API_CMD_WO_KEY
g_runcmd g_retrycmd sh ${g_tmp}/API_CMD >${g_tmp}/API_CMD_OUT 2>&1
if egrep -q -i '^{"code":|error' ${g_tmp}/API_CMD_OUT
then
g_echo_error "$(cat ${g_tmp}/API_CMD_WO_KEY): $(cat ${g_tmp}/API_CMD_OUT)"
return 1
fi
}

View File

@@ -0,0 +1,42 @@
#!/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 {
# Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_symbol=$1
local f_position
get_symbols_ticker
get_positions
get_position_array
for f_position in "${f_get_positions_array[@]}"
do
get_position_line_vars "$f_position"
if [ "$f_symbol" = "$f_position_symbol" ]
then
f_side="sell"
[ "$f_position_side" = "short" ] && f_side="buy"
order $f_symbol crypto_amount:$f_position_contracts $f_side
fi
done
}

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 {
[ -z "${s_score}" ] && s_score=0
#s_score=$((s_score${1}))
@@ -7,3 +27,4 @@ function score {
s_score_hist="${s_score_hist}
s_score=${s_score} (${1}) ${2}"
}

View File

@@ -1,12 +1,33 @@
#!/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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
get_transactions
get_bitpanda_api_transactions
get_justtrade_csv_transactions
get_onetrading_csv_transactions
get_transactions
get_phemex_csv_transactions
>ALL_TRANSACTIONS_OVERVIEW.csv.tmp
>ALL_TRANSACTIONS_OVERVIEW_WARN.csv.tmp
@@ -14,7 +35,7 @@ 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
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}
do
@@ -22,6 +43,10 @@ function transactions_overview {
f_asset=${f_asset_per_exchange_array[0]}
f_exchange=${f_asset_per_exchange_array[1]%$'\n'}
# check values
[ -z "$f_asset" ] && continue
[ -z "$f_exchange" ] && continue
# Ignore stableCoins, EUR, USD
[[ $f_asset = USDT ]] && 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)
for f_transaction in "${f_transactions_array[@]}"
do
g_echo_note "Transaction: $f_transaction"
mapfile -d, -t f_transaction_array < <(echo $f_transaction)
f_date=${f_transaction_array[0]}
f_type=${f_transaction_array[1]}
f_asset_amount=${f_transaction_array[3]}
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_eur=0
f_fee_currency=${f_transaction_array[7]}
@@ -78,7 +109,7 @@ function transactions_overview {
f_fee_currency=$f_currency
else
#g_echo_warn "!!!!!! Could not convert currency $f_fee_currency to $f_currency"
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,Could not convert currency $f_fee_currency to $f_currency"
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,Could not convert currency $f_fee_currency to $f_currency" 1>&2
continue
fi
fi
@@ -125,6 +156,7 @@ function transactions_overview {
[[ $f_type =~ stake ]] && continue
# 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 ]]
then
g_calc "$f_currency_spent+$f_currency_amount"
@@ -178,14 +210,14 @@ function transactions_overview {
if [ $f_currency_spent = 0 ]
then
#g_echo_warn "!!!!!! Sell never buyed!? Spent currency on $f_asset is 0"
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"
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
fi
# if sell wahats not exists!?
# if sell what not exists!?
if [ $f_asset_quantity = 0 ]
then
#g_echo_warn "!!!!!! Sell never buyed!? Buyed asset $f_asset is 0"
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!? Buyed asset $f_asset is 0"
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!? Buyed asset $f_asset is 0" 1>&2
continue
fi
fi
@@ -209,6 +241,7 @@ function transactions_overview {
## Check for ended trade (asset-quantity=0 or tttt)
# if all is sold trade ended and calculate PNL
local f_trade_end=0
local f_trade_partial_end=0
local f_dust=0
local f_dust_eur=0
g_calc "$f_asset_quantity_sold==$f_asset_quantity"
@@ -217,12 +250,12 @@ function transactions_overview {
# Alterntively check for remaining dust only to find end of trade and calculate PNL
if [ ${g_calc_result} -eq 0 ]
then
currency_converter $f_asset_quantity_remaining $f_asset $f_currency "${f_date}"
currency_converter $f_asset_quantity_remaining $f_asset $f_currency "${f_date}" || g_echo_warn "Error converting currency"
f_currency_remaining=$f_currency_converter_result
if g_num_is_between $f_currency_remaining -5 5
then
f_dust=$f_currency_remaining
currency_converter $f_asset_quantity_remaining $f_asset EUR "${f_date}"
currency_converter $f_asset_quantity_remaining $f_asset EUR "${f_date}" || g_echo_warn "Error converting currency to EUR"
f_dust_eur=$f_currency_converter_result
g_echo_note "Quantity ($f_asset_quantity $f_asset - $f_dust (USD) looks like dust - Ending trade" >>ALL_TRANSACTIONS_OVERVIEW.log
f_note="$f_asset_quantity $f_asset - $f_dust (USD) looks like dust - Ending trade"
@@ -244,10 +277,11 @@ function transactions_overview {
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
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
if [ ${f_trade_end} -eq 1 ]
if [ ${f_trade_end} -eq 1 ] || [ ${f_trade_partial_end} -eq 1 ]
then
echo "Buy price: $f_currency_spent $f_currency ($f_currency_spent_eur EUR)" >>ALL_TRANSACTIONS_OVERVIEW.log
@@ -274,16 +308,19 @@ function transactions_overview {
g_calc "$f_result_eur+($f_sell_result_eur)"
f_result_eur=$g_calc_result
# reset vars
f_asset_quantity=0
f_asset_quantity_sold=0
f_asset_quantity_remaining=0
f_currency_spent=0
printf -v f_currency_spent_eur_tax %.2f $f_currency_spent_eur
f_currency_spent_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
if [ ${f_trade_end} -eq 1 ]
then
# reset vars
f_asset_quantity=0
f_asset_quantity_sold=0
f_asset_quantity_remaining=0
f_currency_spent=0
printf -v f_currency_spent_eur_tax %.2f $f_currency_spent_eur
f_currency_spent_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
# at leverage always full taxable
@@ -344,6 +381,7 @@ function transactions_overview {
## completely tax free if over 1 year
f_taxable=0
f_one_year_ago="yes"
f_tax_type="Kauf >1 Jahr zurück"
# reduce tax free volume
g_calc "$f_asset_amount_tax_free-$f_asset_amount"
f_asset_amount_tax_free=$g_calc_result
@@ -407,6 +445,8 @@ function transactions_overview {
# 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"
if [[ $f_type =~ sell|leverage-sell ]]
then
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 {
local f_watch_assets_array

View File

@@ -1,11 +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 {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
webpage_transactions
# Get charts.css
[ -e ../charts.min.css ] || wget ${g_wget_opts} -q https://raw.githubusercontent.com/ChartsCSS/charts.css/main/dist/charts.min.css -O ../charts.min.css
get_symbols_ticker
charts
# create status webpage
echo "<html>
@@ -21,11 +40,11 @@ function webpage {
<h1>State of Dabo-Bot! on ${STOCK_EXCHANGE} - ${URL} (ReadOnly)</h1>
<h1>Last update $(date '+%F %T')</h1>" >../index.html.tmp
# historic overview
echo '<a href=TRANSACTIONS_OVERVIEWS.html><h2>Historic Overview</h2></a>' >>../index.html.tmp
# balance
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)
g_calc "$f_COMPLETE_BALANCE-$f_USED_BALANCE"
printf -v CURRENCY_BALANCE %.2f $g_calc_result
echo '<h2>Overview</h2>' >>../index.html.tmp
echo "<table>
<tr>
@@ -43,12 +62,12 @@ function webpage {
</table>" >>../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
do
f_balance_at_date=$(grep "^$(date -d "1 $f_balance_date ago" +"%Y-%m-%d ")" asset-histories/BALANCECOMPLETE${CURRENCY}.history.csv | head -n1 | cut -d, -f2)
if g_num_valid_number "$f_balance_at_date"
if g_num_valid_number "$f_balance_at_date" 2>/dev/null
then
printf -v f_balance_at_date %.2f $f_balance_at_date
g_calc "$f_COMPLETE_BALANCE-$f_balance_at_date"
@@ -62,18 +81,73 @@ function webpage {
echo '<h2>Open Positions</h2>' >>../index.html.tmp
echo "<table width='100%'><tr><td>Symbol</td><td>Aount</td><td>Entry Price</td><td>Current Price</td><td>Profit/Loss</td><td>Notes</td></tr>" >>../index.html.tmp
for f_position in "${f_get_positions_array[@]}"
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
for f_symbol in ${f_symbols_array_trade[@]}
do
get_position_line_vars "$f_position"
echo "<tr><td>$f_position_symbol</td><td>$f_position_currency_amount</td><td>$f_position_entry_price</td><td>$f_position_current_price</td><td>$f_position_pnl ( ${f_position_pnl_percentage}%)</td><td>$f_position_side ${f_position_leverage}X</td></tr>" >>../index.html.tmp
f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
[ -z "${p[${f_asset}_entry_price]}" ] && 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>${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
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
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 "<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
local f_result_complete=0
local f_spent_complete=0
@@ -81,23 +155,26 @@ function webpage {
local f_sold_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
for f_asset_per_exchange in $(cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d, -f2,4 | sort -u)
for f_asset_per_exchange in $(cat ALL_TRANSACTIONS_OVERVIEW.csv 2>/dev/null | cut -d, -f2,4 | sort -u)
do
mapfile -d, -t f_asset_per_exchange_array < <(echo $f_asset_per_exchange)
f_asset=${f_asset_per_exchange_array[1]%$'\n'}
f_exchange=${f_asset_per_exchange_array[0]}
[[ "$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_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)
if ! [ "$f_amount" = 0 ]
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
g_calc "$f_currency_amount+($f_sold)"
f_currency_amount=$g_calc_result
#f_currency_amount=$g_calc_result
printf -v f_currency_amount %.2f $g_calc_result
g_calc "$f_spent-($f_sold)"
f_spent=$g_calc_result
#f_spent=$g_calc_result
printf -v f_spent %.2f $g_calc_result
if [ "$f_spent" = 0 ]
then
@@ -107,238 +184,56 @@ function webpage {
f_result_percent=$g_percentage_diff_result
fi
g_calc "$f_currency_amount-($f_spent)"
f_result=$g_calc_result
printf -v f_result %.2f $g_calc_result
#f_result=$g_calc_result
### Calc Complete values
g_calc "$f_result_complete+($f_result)"
f_result_complete=$g_calc_result
#f_result_complete=$g_calc_result
printf -v f_result_complete %.2f $g_calc_result
g_calc "$f_currency_amount_complete+($f_currency_amount)"
f_currency_amount_complete=$g_calc_result
#f_currency_amount_complete=$g_calc_result
printf -v f_currency_amount_complete %.2f $g_calc_result
g_calc "$f_spent_complete+($f_spent)"
f_spent_complete=$g_calc_result
#f_spent_complete=$g_calc_result
printf -v f_spent_complete %.2f $g_calc_result
g_calc "$f_sold_complete+($f_sold)"
f_sold_complete=$g_calc_result
#f_sold_complete=$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
done
g_percentage-diff $f_spent_complete $f_currency_amount_complete
f_result_percent_complete=$g_percentage_diff_result
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 -n -k3 -t'>' -r ../index.html.tmp.tmp >>../index.html.tmp
# 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
# Sort by Spent Amount
sort -n -k7 -t'>' -r ../index.html.tmp.tmp >>../index.html.tmp
rm ../index.html.tmp.tmp
echo "</table>" >>../index.html.tmp
echo "<h2>Market Performance ( $(cat MARKET_PERFORMANCE_LATEST)%)</h2>" >>../index.html.tmp
#echo "<table width='100%'><tr><td><details><summary>Charts</summary>" >>../index.html.tmp
echo "<details><summary>Charts</summary>" >>../index.html.tmp
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
# Closed positions
echo "<h2>Closed Positions and (german) tax declaration notes</h2>" >>../index.html.tmp
ls ../TRANSACTIONS_OVERVIEW-* | while read f_html
do
echo "<td><b>${f_mperfcol}</b></td>" >>../index.html.tmp
done
echo "</tr>" >>../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
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>" >>../index.html.tmp
done
echo "$(cat ALL_TRANSACTIONS_OVERVIEW_WARN.csv | cut -d, -f1,2,20)<br>" >>../index.html.tmp
echo "</table></details>" >>../index.html.tmp
echo "<a href=\"botdata/MARKET_PERFORMANCE.csv\">Complete list</a>" >>../index.html.tmp
echo '<h2>Latest trades</h2>' >>../index.html.tmp
echo '<h3>Open</h3>' >>../index.html.tmp
echo "<table width='100%'><tr>" >>../index.html.tmp
echo "<td>Date</td>
<td>Asset</td>
<td>Action</td>
<td>${CURRENCY} Quantity</td>
<td>${CURRENCY} Price</td>
<td>Commission</td>
<td>Comment</td></tr>" >>../index.html.tmp
local f_trade_file
for f_trade_file in $(ls -t trade-histories/trade-*-open.history.csv 2>/dev/null)
do
local tradeline=$(tail -n1 ${f_trade_file})
local asset=$(echo ${f_trade_file} | cut -d. -f3 | cut -d- -f1)
local interimfile=$(echo ${f_trade_file} | sed 's/open\.history\.csv/interim\.history\.csv/')
echo "<td>$(echo ${tradeline} | cut -d, -f1)</td>
<td><a href=\"botdata/asset-histories/${asset}.history.csv\">${asset}</a> <a href=\"https://www.coingecko.com/de/munze/$(egrep -i ^$(echo ${asset} | sed "s/${CURRENCY}$//"), COINGECKO_IDS | cut -d, -f2 )\">🔗</a></td>
<td>$(echo ${tradeline} | cut -d, -f2)</td>
<td>$(echo ${tradeline} | cut -d, -f4)</td>
<td>$(echo ${tradeline} | cut -d, -f5)</td>
<td>$(echo ${tradeline} | cut -d, -f6)</td>
<td>$(echo ${tradeline} | cut -d, -f7,8,9,10,11,12,13,14,15)</td>
</tr>" >>../index.html.tmp
echo "<tr><td colspan='7'><details><summary>Chart</summary>" >>../index.html.tmp
genchart "$interimfile" >>../index.html.tmp
echo "</details></td></tr>" >>../index.html.tmp
done
echo "</table>" >>../index.html.tmp
echo '<h3>Closed</h3>' >>../index.html.tmp
echo "<table width='100%'><tr>" >>../index.html.tmp
echo "<td>Date</td>
<td>Asset</td>
<td>Action</td>
<td>${CURRENCY} Quantity</td>
<td>${CURRENCY} Price (result)</td>
<td>Commission</td>
<td>Comment</td></tr>" >>../index.html.tmp
for f_trade_file in $(ls -t trade-histories/trade-*-closed.history.csv 2>/dev/null | head -n 50)
do
local tradeline
cat ${f_trade_file} | while read tradeline
do
local f_action=$(echo ${tradeline} | cut -d, -f2)
local f_price=$(echo ${tradeline} | cut -d, -f5)
local tradedate=$(echo ${tradeline} | cut -d, -f1 | perl -pe 's/_([0-9][0-9])-([0-9][0-9])-([0-9][0-9])/ $1:$2/')
if echo ${f_action} | grep -q buy
then
echo ${f_price} >${g_tmp}/buyprice
local tradedatebuy=${tradedate}
fi
if echo ${f_action} | grep -q sell
then
if [ -s "${f_trade_file}.result" ]
then
local f_profit=$(cat "${f_trade_file}.result")
f_price="${f_price} ( ${f_profit}%)"
else
g_percentage-diff $(cat ${g_tmp}/buyprice) ${f_price}
local f_profit=${g_percentage_diff_result}
f_price="${f_price} ( ${f_profit}%)"
echo "${f_profit}" >"${f_trade_file}.result"
fi
fi
local asset=$(echo ${f_trade_file} | cut -d. -f3 | cut -d- -f1)
interimfile=$(echo ${f_trade_file} | sed 's/closed\.history\.csv/interim\.history\.csv/')
echo "<td>${tradedate}</td>
<td><a href=\"botdata/asset-histories/${asset}.history.csv\">${asset}</a> <a href=\"https://www.coingecko.com/de/munze/$(egrep -i ^$(echo ${asset} | sed "s/${CURRENCY}$//"), COINGECKO_IDS | cut -d, -f2 )\">🔗</a></td>
<td>${f_action}</td>
<td>$(echo ${tradeline} | cut -d, -f4)</td>
<td>${f_price}</td>
<td>$(echo ${tradeline} | cut -d, -f6)</td>
<td>$(echo ${tradeline} | cut -d, -f7,8,9,10,11,12,13,14,15)</td> ">>../index.html.tmp
if echo ${f_action} | grep -q sell
then
echo "<tr><td colspan='7'><details><summary>Charts</summary>" >>../index.html.tmp
local tradeintervals=$(cat ${interimfile} | wc -l)
head -n1 asset-histories/${asset}.history.csv >${g_tmp}/trade.csv
grep -A ${tradeintervals} "${tradedatebuy}:" asset-histories/${asset}.history.csv >>${g_tmp}/trade.csv
# cache old trade charts
if ! [ -s "${interimfile}.chart" ]
then
echo "Price, EMA, Levels" >${interimfile}.chart
genchart "${g_tmp}/trade.csv" ${tradeintervals} 2,25,26,27,28,29,30,31,32,33,34,35,4,36,37,38,39 green,DarkSlateGrey,DarkSlateGrey,Gold,DarkOrange,DarkOrange,GoldenRod,GoldenRod,GoldenRod,GoldenRod,DarkOrange,DarkOrange,MidnightBlue,Indigo,DarkSlateBlue,DodgerBlue,DeepSkyBlue >>${interimfile}.chart
echo "MACD" >>${interimfile}.chart
genchart "${g_tmp}/trade.csv" ${tradeintervals} 8,6,7 >>${interimfile}.chart
echo "RSIs" >>${interimfile}.chart
genchart "${g_tmp}/trade.csv" ${tradeintervals} 10,11,12,14,15,16,17,13 >>${interimfile}.chart
fi
cat "${interimfile}.chart" >>../index.html.tmp
echo "</details></td></tr>" >>../index.html.tmp
else
echo "</tr>" >>../index.html.tmp
fi
done
done
echo "</table>" >>../index.html.tmp
#echo "<h2>Current config</h2>" >>../index.html.tmp
#echo "<pre>$(cat ../../dabo-bot.conf | perl -pe 's/\</&#60;/g; s/\>/&#62;/g;')</pre>" >>../index.html.tmp
echo '<h2>Available Assets and histories</h2>' >>../index.html.tmp
echo "<table width='100%'><tr>" >>../index.html.tmp
echo "<tr><td>Asset</td><td>Date</td><td>Price ${CURRENCY}</td><td>24h change (USD)</td></tr>" >>../index.html.tmp
local asset
cat ASSETS | egrep -v "${BLACKLIST}" | sort | while read asset
do
[ -s asset-histories/${asset}.history.csv ] || continue
echo "<td><a href=\"botdata/asset-histories/${asset}.history.csv\">${asset}</a> <a href=\"https://www.coingecko.com/de/munze/$(egrep -i ^$(echo ${asset} | sed "s/${CURRENCY}$//"), COINGECKO_IDS | cut -d, -f2 )\">🔗</a></td>" >>../index.html.tmp
kcurrency=$(echo ${asset} | sed "s/${CURRENCY}//")
#get_rate_percentage_min_before_and_now ${kcurrency} ${CURRENCY} 1440
local assetin=($(cat asset-histories/${asset}.history.csv | egrep -v "0.00000000$" | tail -n2 | head -n1 | sed 's/,/ /g'))
echo "<td>${assetin[0]} ${assetin[1]}</td>
<td>${CURRENCY} ${assetin[2]}</td>
<td> $(grep "^$kcurrency," ASSET_PRICE_CHANGE_PERCENTAGE_24H | cut -d, -f2)%</td>
</tr><tr><td colspan='4'>" >>../index.html.tmp
echo "<details><summary>${asset} Charts</summary>" >>../index.html.tmp
echo "Price, EMA, Levels" >>../index.html.tmp
genchart asset-histories/${asset}.history.csv 50 2,25,26,27,28,29,30,31,32,33,34,35,5,36,37,38 green,DarkSlateGrey,DarkSlateGrey,Gold,DarkOrange,DarkOrange,GoldenRod,GoldenRod,GoldenRod,GoldenRod,DarkOrange,DarkOrange,MidnightBlue,Indigo,DarkSlateBlue,DodgerBlue,DeepSkyBlue >>../index.html.tmp
echo "MACD" >>../index.html.tmp
genchart asset-histories/${asset}.history.csv 50 8,6,7 >>../index.html.tmp
echo "RSIs" >>../index.html.tmp
genchart asset-histories/${asset}.history.csv 50 10,11,12,14,15,16,17,13 >>../index.html.tmp
echo "</details></td></tr>" >>../index.html.tmp
done
echo "</table>" >>../index.html.tmp
echo "<h2>Top/Flop</h2>" >>../index.html.tmp
ls -1 trade-histories/*.result | cut -d . -f3-6 | sort -u | while read f_asset_results
do
f_asset=$(echo ${f_asset_results} | cut -d\- -f1)
echo $(cat trade-histories/*${f_asset_results} | awk "{ SUM += \$1} END { printf(\"%.2f\", SUM)}") >trade-histories/${f_asset}.complete_result
done
echo "<h3>Top 10</h3>" >>../index.html.tmp
grep [0-9] trade-histories/*.complete_result | sort -t: -k2 -rn | head -n 10 | cut -d/ -f2 | perl -pe 's/\.complete_result:/ /; s/$/%<br>/' >>../index.html.tmp
echo "<h3>Flop 10</h3>" >>../index.html.tmp
grep [0-9] trade-histories/*.complete_result | sort -t: -k2 -n | head -n 10 | cut -d/ -f2 | perl -pe 's/\.complete_result:/ /; s/$/%<br>/' >>../index.html.tmp
echo '<h2>Complete trading histories</h2>' >>../index.html.tmp
echo "<table>" >>../index.html.tmp
find trade-histories -type f -name *.history.csv | cut -d/ -f2 | cut -d. -f1 | sort | while read asset
do
[ -s trade-histories/${asset}.history.csv ] || continue
echo "<tr><td><a href=\"botdata/trade-histories/${asset}.history.csv\">${asset}</a> <a href=\"https://www.coingecko.com/de/munze/$(egrep -i ^$(echo ${asset} | sed "s/${CURRENCY}$//"), COINGECKO_IDS | cut -d, -f2 )\">🔗</a></td></tr>" >>../index.html.tmp
done
echo "</table>" >>../index.html.tmp
# THE END
echo "</body></html>" >>../index.html.tmp
# 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
#mv ../index.html.tmp ../index.html
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@ finished"

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 {
# calculate totals from csv
@@ -7,7 +27,7 @@ function webpage_transactions {
#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 "Giveaway Result: $f_giveaway EUR"
#echo -e "Instand Trade Bonus: $f_instant_trade_bonus EUR\n"
@@ -17,15 +37,16 @@ function webpage_transactions {
local f_tax_year
cat ALL_TRANSACTIONS_OVERVIEW.csv | cut -d- -f1 | sort -u | while read f_tax_year
do
echo "========== Tax year $f_tax_year (German Tax Law) =========="
#echo "========== Tax year $f_tax_year (German Tax Law) =========="
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
do
#echo "$f_exchange_tax_type"
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=$(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
@@ -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>
" >TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
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 " EUR </td><td>"}
{printf("%.2f", $17)}
{printf " EUR</td><td>"$13"</td><td>"}
{printf("%.2f", $14)}
{print " EUR</td></tr>"}' >>TRANSACTIONS_OVERVIEW-${f_exchange}-${f_tax_year}.html.tmp
cat ALL_TRANSACTIONS_OVERVIEW.csv | grep "^${f_tax_year}-" | grep ",${f_exchange}," | awk -F, '
{
printf "<tr><td>%s</td><td>%s</td><td>%s %s</td><td>%.2f EUR</td><td>", $1, $3, $5, $4, $15
if ($17 != "") {
printf "%.2f EUR", $17
}
printf "</td><td>%s</td><td>%.2f EUR</td></tr>\n", $13, $14
}' >>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
@@ -65,34 +86,8 @@ $(cat ${g_tmp}/tax_summary_$f_exchange-$f_tax_year)
done
echo ""
#echo ""
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

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

View File

@@ -1,4 +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/>.
mkdir final
ls -1 *.history.csv | while read x
do

View File

@@ -1,10 +0,0 @@
#!/bin/bash
. /dabo/dabo-prep.sh
while true
do
transactions_overview
sleep 3600
done

View File

@@ -1 +0,0 @@
ASSET,ALERTS,BUYPRICE,BUYDATE,BUYQUANTITY,SELLPRICE,SELLDATE,SELLQUANTITY,COMMENT
1 ASSET ALERTS BUYPRICE BUYDATE BUYQUANTITY SELLPRICE SELLDATE SELLQUANTITY COMMENT

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"]::-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%; }
/* for VPN Login */
@@ -173,12 +116,20 @@ pre,#footer {
font:16px sans-serif;
}
.headline {
font-size:18px;
background-color: #808080;
font-weight: bold;
color: black;
}
.statusok {
font:18px sans-serif;
background-color: #00BF40;
color: black;
}
.statusnok {
font:18px sans-serif;
background-color: #E10020;

23
data/charts.html Normal file
View File

@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"
/>
<title>Charts</title>
<script type="text/javascript" src="lightweight-charts.standalone.production.js"></script>
<style>
body {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id="container" style="position: absolute; width: 100%; height: 100%"></div>
<script type="text/javascript" src="charts.js"></script>
</body>
</html>

542
data/charts.js Normal file
View File

@@ -0,0 +1,542 @@
const urlParams = new URLSearchParams(window.location.search);
const symbol = urlParams.get('symbol');
const time = urlParams.get('time');
const symbol2 = urlParams.get('symbol2');
const heightrsimacdchart = 100
function timeToLocal(originalTime) {
const d = new Date(originalTime * 1000);
return Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()) / 1000;
}
function parseCSV(data) {
const rows = data.split("\n");
const result = [];
let start = Math.max(rows.length - 1000, 0);
let lastElements = rows.slice(start)
for (let i = start; i < rows.length; i++) {
const cols = rows[i].split(",");
if (cols.length >= 23 && cols.every(element => element !== undefined && element !== null)) { // check for existing lines
// parse the date so seconds since 1970
cols[0] = Date.parse(cols[0])/1000,result.push(cols);
cols[0] = timeToLocal(cols[0]);
// coloring for MACD-Histogram
if (cols[20] < 0) {
cols[100] = "orange";
if (cols[23] > 20) {
cols[100] = "red";
}
}
else {
cols[100] = "lightgreen";
if (cols[23] > 20) {
cols[100] = "green";
}
}
}
else {
console.log("invalid line on linenr " + i + ": " +rows[i]);
}
}
return result;
}
function getCrosshairDataPoint(series, param) {
if (!param.time) {
return null;
}
const dataPoint = param.seriesData.get(series);
return dataPoint || null;
}
function syncCrosshair(chart, series, dataPoint) {
if (dataPoint) {
chart.setCrosshairPosition(dataPoint.value, dataPoint.time, series);
return;
}
chart.clearCrosshairPosition();
}
// Create the Lightweight Chart within the container element
const chart = LightweightCharts.createChart(document.getElementById('container'),
{
rightPriceScale: {
minimumWidth: 100,
borderVisible: false
},
height: 500,
crosshair: {
mode: 0,
},
timeScale: {
timeVisible: true,
secondsVisible: false,
},
layout: {
background: {
type: 'solid',
color: '#222',
},
textColor: '#DDD',
},
grid: {
vertLines: { color: '#444' },
horzLines: { color: '#444' },
},
});
chart.applyOptions({
watermark: {
visible: true,
fontSize: 18,
horzAlign: 'top',
vertAlign: 'left',
color: '#DDD',
text: symbol + " " + time,
}
});
// define chart
const candleSeries = chart.addCandlestickSeries({upColor: 'green', wickUpColor: 'green', downColor: 'red', wickDownColor: 'red', borderVisible: false,});
const lineSeriesEMA12 = chart.addLineSeries({ color: 'red', lineWidth: 1, priceLineVisible: false, title: 'EMA12'});
const lineSeriesEMA26 = chart.addLineSeries({ color: 'pink', lineWidth: 1, lineStyle: 2, priceLineVisible: false, title: 'EMA26'});
const lineSeriesEMA50 = chart.addLineSeries({ color: 'cyan', lineWidth: 1, priceLineVisible: false, title: 'EMA50'});
const lineSeriesEMA100 = chart.addLineSeries({ color: 'yellow', lineWidth: 1, priceLineVisible: false, title: 'EMA100'});
const lineSeriesEMA200 = chart.addLineSeries({ color: 'white', lineWidth: 1, priceLineVisible: false, title: 'EMA200'});
const lineSeriesEMA400 = chart.addLineSeries({ color: 'orange', lineWidth: 1, priceLineVisible: false, title: 'EMA400'});
const lineSeriesEMA800 = chart.addLineSeries({ color: 'purple', lineWidth: 1, priceLineVisible: false, title: 'EMA800'});
// RSI Chart
const chartrsi = LightweightCharts.createChart(document.getElementById("container"),
{
rightPriceScale: {
minimumWidth: 100,
borderVisible: false
},
height: heightrsimacdchart,
timeScale: {
visible: false,
},
layout: {
background: {
type: 'solid',
color: '#222',
},
textColor: '#DDD',
},
grid: {
vertLines: { color: '#444' },
horzLines: { color: '#444' },
},
});
chartrsi.applyOptions({
watermark: {
visible: true,
fontSize: 18,
horzAlign: 'top',
vertAlign: 'left',
color: '#DDD',
text: 'RSI 5,14,21',
}
});
const lineSeriesRSI5 = chartrsi.addLineSeries({ color: 'orange', lineWidth: 1, lineStyle: 2, priceLineVisible: false, title: 'RSI5'});
const lineSeriesRSI14 = chartrsi.addLineSeries({ color: 'yellow', lineWidth: 2, priceLineVisible: false, title: 'RSI14'});
const lineSeriesRSI21 = chartrsi.addLineSeries({ color: 'lightgreen', lineWidth: 1, lineStyle: 2, priceLineVisible: false, title: 'RSI21'});
// MACD Chart
const chartmacd = LightweightCharts.createChart(document.getElementById("container"),
{
rightPriceScale: {
minimumWidth: 100,
borderVisible: false
},
height: heightrsimacdchart,
timeScale: {
timeVisible: true,
secondsVisible: false,
},
layout: {
background: {
type: 'solid',
color: '#222',
},
textColor: '#DDD',
},
grid: {
vertLines: { color: '#444' },
horzLines: { color: '#444' },
},
});
chartmacd.applyOptions({
watermark: {
visible: true,
fontSize: 18,
horzAlign: 'top',
vertAlign: 'left',
color: '#DDD',
text: 'MACD 12 26',
}
});
const lineSeriesMACD = chartmacd.addLineSeries({ color: 'blue', lineWidth: 1, lineStyle: 0, priceLineVisible: false, title: 'MACD'});
const lineSeriesMACDSignal = chartmacd.addLineSeries({ color: 'orange', lineWidth: 1, lineStyle: 0, priceLineVisible: false, title: 'Signal'});
const histogramSeriesMACD = chartmacd.addHistogramSeries({
priceFormat: {
type: 'volume',
color: 'orange',
},
priceLineVisible: false,
});
fetch("/botdata/asset-histories/" + symbol + ".history." + time + ".csv", { cache: 'no-store' })
.then(response => response.text())
.then(data => {
const parsedData = parseCSV(data);
// OHLC Data
const bars = parsedData.map(item => ({
time: item[0],
open: item[1],
high: item[2],
low: item[3],
close: item[4]
}));
candleSeries.setData(bars);
// EMA Data
candleSeries.setData(bars);
const lineSeriesEMA12Data = parsedData.map(item => ({
time: item[0],
value: item[8]
}));
lineSeriesEMA12.setData(lineSeriesEMA12Data);
const lineSeriesEMA26Data = parsedData.map(item => ({
time: item[0],
value: item[9]
}));
lineSeriesEMA26.setData(lineSeriesEMA26Data);
const lineSeriesEMA50Data = parsedData.map(item => ({
time: item[0],
value: item[10]
}));
lineSeriesEMA50.setData(lineSeriesEMA50Data);
const lineSeriesEMA100Data = parsedData.map(item => ({
time: item[0],
value: item[11]
}));
lineSeriesEMA100.setData(lineSeriesEMA100Data);
const lineSeriesEMA200Data = parsedData.map(item => ({
time: item[0],
value: item[12]
}));
lineSeriesEMA200.setData(lineSeriesEMA200Data);
const lineSeriesEMA400Data = parsedData.map(item => ({
time: item[0],
value: item[13]
}));
lineSeriesEMA400.setData(lineSeriesEMA400Data);
const lineSeriesEMA800Data = parsedData.map(item => ({
time: item[0],
value: item[14]
}));
lineSeriesEMA800.setData(lineSeriesEMA800Data);
// RSI Data
const lineSeriesRSI5Data = parsedData.map(item => ({
time: item[0],
value: item[15]
}));
lineSeriesRSI5.setData(lineSeriesRSI5Data);
const lineSeriesRSI14Data = parsedData.map(item => ({
time: item[0],
value: item[16]
}));
lineSeriesRSI14.setData(lineSeriesRSI14Data);
const lineSeriesRSI21Data = parsedData.map(item => ({
time: item[0],
value: item[17]
}));
lineSeriesRSI21.setData(lineSeriesRSI21Data);
// MACD Data
const lineSeriesMACDData = parsedData.map(item => ({
time: item[0],
value: item[18]
}));
lineSeriesMACD.setData(lineSeriesMACDData);
const lineSeriesMACDSignalData = parsedData.map(item => ({
time: item[0],
value: item[19]
}));
lineSeriesMACDSignal.setData(lineSeriesMACDSignalData);
const histogramSeriesMACDData = parsedData.map(item => ({
time: item[0],
value: item[20],
color: item[100]
}));
histogramSeriesMACD.setData(histogramSeriesMACDData);
});
// Lines for price levels
fetch("/botdata/asset-histories/" + symbol + ".history." + time + ".csv.levels", { cache: 'no-store' })
.then(response => response.text())
.then(text => {
const levels = text.split(' ');
levels.forEach(function(level) {
candleSeries.createPriceLine({price: level, color: "blue", lineWidth: 0.5, lineStyle: 3, axisLabelVisible: true, title: 'Level'});
});
});
// Lines for RSIs
lineSeriesRSI14.createPriceLine({price: 45, color: "green", lineWidth: 0.5, lineStyle: 3, axisLabelVisible: false});
lineSeriesRSI14.createPriceLine({price: 50, color: "lightyellow", lineWidth: 0.5, lineStyle: 3, axisLabelVisible: false});
lineSeriesRSI14.createPriceLine({price: 55, color: "red", lineWidth: 0.5, lineStyle: 3, axisLabelVisible: false});
// DXY //
const DXYchart = LightweightCharts.createChart(document.getElementById('container'),
{
rightPriceScale: {
minimumWidth: 100,
borderVisible: false
},
height: 500,
crosshair: {
mode: 0,
},
timeScale: {
timeVisible: true,
secondsVisible: false,
},
layout: {
background: {
type: 'solid',
color: '#222',
},
textColor: '#DDD',
},
grid: {
vertLines: { color: '#444' },
horzLines: { color: '#444' },
},
});
DXYchart.applyOptions({
watermark: {
visible: true,
fontSize: 18,
horzAlign: 'top',
vertAlign: 'left',
color: '#DDD',
text: symbol2 + " " + time,
}
});
// define DXY chart
const DXYcandleSeries = DXYchart.addCandlestickSeries({upColor: 'green', wickUpColor: 'green', downColor: 'red', wickDownColor: 'red', borderVisible: false,});
const DXYlineSeriesEMA200 = DXYchart.addLineSeries({ color: 'white', lineWidth: 1, priceLineVisible: false, title: 'EMA200'});
const DXYlineSeriesEMA800 = DXYchart.addLineSeries({ color: 'purple', lineWidth: 1, priceLineVisible: false, title: 'EMA800'});
const DXYlineSeriesEMA50 = DXYchart.addLineSeries({ color: 'cyan', lineWidth: 1, priceLineVisible: false, title: 'EMA50'});
// DXY RSI Chart
const DXYchartrsi = LightweightCharts.createChart(document.getElementById("container"),
{
rightPriceScale: {
minimumWidth: 100,
borderVisible: false
},
height: heightrsimacdchart,
timeScale: {
visible: false,
},
layout: {
background: {
type: 'solid',
color: '#222',
},
textColor: '#DDD',
},
grid: {
vertLines: { color: '#444' },
horzLines: { color: '#444' },
},
});
DXYchartrsi.applyOptions({
watermark: {
visible: true,
fontSize: 18,
horzAlign: 'top',
vertAlign: 'left',
color: '#DDD',
text: 'DXY RSI 5,14,21',
}
});
const DXYlineSeriesRSI5 = DXYchartrsi.addLineSeries({ color: 'orange', lineWidth: 1, lineStyle: 2, priceLineVisible: false, title: 'RSI5'});
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'});
fetch("/botdata/asset-histories/" + symbol2 + ".history." + time + ".csv", { cache: 'no-store' })
.then(response => response.text())
.then(data => {
const DYXparsedData = parseCSV(data);
// OHLC Data
const DXYbars = DYXparsedData.map(item => ({
time: item[0],
open: item[1],
high: item[2],
low: item[3],
close: item[4]
}));
DXYcandleSeries.setData(DXYbars);
const DXYlineSeriesEMA50Data = DYXparsedData.map(item => ({
time: item[0],
value: item[10]
}));
DXYlineSeriesEMA50.setData(DXYlineSeriesEMA50Data);
const DXYlineSeriesEMA200Data = DYXparsedData.map(item => ({
time: item[0],
value: item[12]
}));
DXYlineSeriesEMA200.setData(DXYlineSeriesEMA200Data);
const DXYlineSeriesEMA800Data = DYXparsedData.map(item => ({
time: item[0],
value: item[14]
}));
DXYlineSeriesEMA800.setData(DXYlineSeriesEMA800Data);
// RSI Data
const DXYlineSeriesRSI5Data = DYXparsedData.map(item => ({
time: item[0],
value: item[15]
}));
DXYlineSeriesRSI5.setData(DXYlineSeriesRSI5Data);
const DXYlineSeriesRSI14Data = DYXparsedData.map(item => ({
time: item[0],
value: item[16]
}));
DXYlineSeriesRSI14.setData(DXYlineSeriesRSI14Data);
const DXYlineSeriesRSI21Data = DYXparsedData.map(item => ({
time: item[0],
value: item[17]
}));
DXYlineSeriesRSI21.setData(DXYlineSeriesRSI21Data);
});
// Sync charts timeScale
chart.timeScale().fitContent();
chart.timeScale().subscribeVisibleLogicalRangeChange(timeRange => {
chartrsi.timeScale().setVisibleLogicalRange(timeRange);
chartmacd.timeScale().setVisibleLogicalRange(timeRange);
DXYchartrsi.timeScale().setVisibleLogicalRange(timeRange);
DXYchart.timeScale().setVisibleLogicalRange(timeRange);
});
chartrsi.timeScale().subscribeVisibleLogicalRangeChange(timeRange => {
chart.timeScale().setVisibleLogicalRange(timeRange);
});
chartmacd.timeScale().subscribeVisibleLogicalRangeChange(timeRange => {
chart.timeScale().setVisibleLogicalRange(timeRange);
});
DXYchart.timeScale().subscribeVisibleLogicalRangeChange(timeRange => {
chart.timeScale().setVisibleLogicalRange(timeRange);
});
DXYchartrsi.timeScale().subscribeVisibleLogicalRangeChange(timeRange => {
chart.timeScale().setVisibleLogicalRange(timeRange);
});
chart.subscribeCrosshairMove(param => {
const dataPoint = getCrosshairDataPoint(lineSeriesEMA50, param);
syncCrosshair(chartrsi, lineSeriesRSI14, dataPoint);
const dataPointmacd = getCrosshairDataPoint(lineSeriesEMA50, param);
syncCrosshair(chartmacd, lineSeriesMACD, dataPointmacd);
const DXYdataPoint = getCrosshairDataPoint(lineSeriesEMA50, param);
syncCrosshair(DXYchart, DXYlineSeriesEMA50, DXYdataPoint);
});
chartrsi.subscribeCrosshairMove(param => {
const dataPoint = getCrosshairDataPoint(lineSeriesRSI14, param);
syncCrosshair(chart, lineSeriesEMA50, dataPoint);
const dataPointmacd = getCrosshairDataPoint(lineSeriesRSI14, param);
syncCrosshair(chartmacd, lineSeriesMACD, dataPointmacd);
const DXYdataPoint = getCrosshairDataPoint(lineSeriesRSI14, param);
syncCrosshair(DXYchart, DXYlineSeriesEMA50, DXYdataPoint);
});
chartmacd.subscribeCrosshairMove(param => {
const dataPoint = getCrosshairDataPoint(lineSeriesMACD, param);
syncCrosshair(chart, lineSeriesEMA50, dataPoint);
const dataPointrsi = getCrosshairDataPoint(lineSeriesMACD, param);
syncCrosshair(chartrsi, lineSeriesRSI14, dataPointrsi);
const DXYdataPoint = getCrosshairDataPoint(lineSeriesMACD, param);
syncCrosshair(DXYchart, DXYlineSeriesEMA50, DXYdataPoint);
});
DXYchart.subscribeCrosshairMove(param => {
const dataPoint = getCrosshairDataPoint(DXYlineSeriesEMA50, param);
syncCrosshair(chart, lineSeriesEMA50, dataPoint);
const dataPointrsi = getCrosshairDataPoint(DXYlineSeriesEMA50, param);
syncCrosshair(chartrsi, lineSeriesRSI14, dataPointrsi);
const dataPointmacd = getCrosshairDataPoint(DXYlineSeriesEMA50, param);
syncCrosshair(chartmacd, lineSeriesMACD, dataPointrsi);
});

View File

@@ -10,12 +10,207 @@ services:
- ./dabo:/dabo:ro
- ./strategies:/dabo/strategies:ro
- ./dabo-bot.conf:/dabo/dabo-bot.override.conf
- ./watch-assets.csv:/dabo/watch-assets.csv
# - ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro
deploy:
resources:
limits:
cpus: '2'
memory: 1024M
dabo-symbols_ticker:
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-symbols_ticker.sh
deploy:
resources:
limits:
cpus: '1'
memory: 512M
dabo-ohlcv-candles-indicators-5m:
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
- ./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-ohlcv-candles-indicators.sh 5m 300
dabo-ohlcv-candles-indicators-15m:
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
- ./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-ohlcv-candles-indicators.sh 15m 900
dabo-ohlcv-candles-indicators-1h:
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
- ./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-ohlcv-candles-indicators.sh 1h 3600
dabo-ohlcv-candles-indicators-4h:
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
- ./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-ohlcv-candles-indicators.sh 4h 3600
dabo-ohlcv-candles-indicators-1d:
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
- ./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-ohlcv-candles-indicators.sh 1d
dabo-ohlcv-candles-indicators-1w:
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
- ./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-ohlcv-candles-indicators.sh 1w
dabo-calc-indicators-hist:
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/calc-indicators-hist.sh
cpu_shares: 128
deploy:
resources:
limits:
cpus: '1'
memory: 512M
dabo-calc-levels:
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:rw
- /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/calc-levels.sh
deploy:
resources:
limits:
cpus: '1'
memory: 1024M
dabo-orders:
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-orders.sh
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
dabo-transaction-history:
build:
@@ -27,13 +222,88 @@ services:
- ./dabo:/dabo:ro
- ./strategies:/dabo/strategies:ro
- ./dabo-bot.conf:/dabo/dabo-bot.override.conf
- ./watch-assets.csv:/dabo/watch-assets.csv
# - ./watch-assets.csv:/dabo/watch-assets.csv
- ./data:/dabo/htdocs:rw
- ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro
- /usr/local/etc/notify.conf:/usr/local/etc/notify.conf:ro
- ./notify.local.conf:/usr/local/etc/notify.conf:ro
- /etc/localtime:/etc/localtime:ro
entrypoint: /dabo/transaction-history.sh
entrypoint: /dabo/fetch-transaction-history.sh
cpu_shares: 128
deploy:
resources:
limits:
cpus: '0.5'
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:
# build:
# context: .
# dockerfile: Dockerfile
# restart: no
# 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/test.sh
# cpu_shares: 128
# deploy:
# resources:
# limits:
# cpus: '0.5'
# memory: 512M
dabo-webpage:
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/create_webpage.sh
deploy:
resources:
limits:
cpus: '1'
memory: 128M
dabo-web:
image: nginx:latest
@@ -41,4 +311,11 @@ services:
volumes:
- ./data:/usr/share/nginx/html:ro
- /etc/localtime:/etc/localtime:ro
deploy:
resources:
limits:
cpus: '1'
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"