Krypto-trading-bot: Idea: Load quoting params file from command line

Created on 16 Sep 2018  路  16Comments  路  Source: ctubio/Krypto-trading-bot

Every time I want to restart a bot with a blank database, I have to start it with the GUI so that I can paste my saved config in JSON format into the web browser. Usually, I have configs in JSON format saved in a file.

So my suggestion would be to have a command line argument for the bot with the config file location.

What do you think about this?

improvement

Most helpful comment

should be doable; please note the "config file" currently is K.sh; i think you want a new file to save/reuse the quoting parameters; lets call this file "params file" :D

then we just need a new arg to set the path to "params file", and if the arg is set, reuse params from the file; if is not set, reuse params from the database (if any like now does)

All 16 comments

should be doable; please note the "config file" currently is K.sh; i think you want a new file to save/reuse the quoting parameters; lets call this file "params file" :D

then we just need a new arg to set the path to "params file", and if the arg is set, reuse params from the file; if is not set, reuse params from the database (if any like now does)

Like how we use the "backup" button of the UI to import/export the quoting parameters, can't we just save the "backup" parameters to a file and reread that file when the bot restarts?

another option, is there way to manipulate the parameters using REST PUTs/PATCHs?

whichever way looks easier and faster for you carles :-)

just a note that this can be done now with sqlite3 using the database file. the bot loads the parameters from table 'f' of /var/lib/K/db/[filename].db . so to save params you can do anything like (while the bot is _not_ running):

sqlite3 /var/lib/K/db/K-trading-bot.[EXCHANGE].[BASE].[QUOTE].db '.dump f'  | sed -ne 's/INSERT INTO/INSERT OR REPLACE INTO/p' > params.sql

and to restore them (while the bot is _off_):

sqlite3 /var/lib/K/db/K-trading-bot.[EXCHANGE].[BASE].[QUOTE].db < params.sql

The file is automatically updated when params are changed, and is read from to restore them when the bot boots up.

In comparison, it would certainly be incredibly convenient to have the requested features.

Thanks for the great reply and possible solution @xloem , while it does not allow live patching this certainly helps me implement what I have in mind, just stop the bot, modify parameters and start again :)

@nonkreon for completion, you can do live patching over the websocket roughly the same way.

sudo npm install -g wscat

Sending =f retrieves the current parameters. This script removes the decoration from the output to store it as json:

 sleep 1 | wscat -n --connect wss://127.0.0.1:3000/ -x =f | sed 's/=f\[\(.*\)\]/\1/' > params.json

Sending -f{json obj content} sets the current parameters:

sleep 1 | wscat -n --connect wss://127.0.0.1:3000/ -x -f"$(<params.json)"

Both assume the bot replies within 1 second.

EDIT: I haven't tested the above on a live bot. There might be notifications that complicate things. To get a quick idea of the websocket protocol, you can open your browser developer tools with the UI page open, navigate to the network pane, reload the page, click the websocket connection once it displays, and switch to the subpane that shows the websocket data. The bot can be completely controlled via the websocket.

Well the existence of UI login seems to complicate things the way you are afraid of, nevertheless offline updating should work well and I thank you very much for sharing this solution with us

I tried the above wscat way but I can't connect:

wscat -n --connect wss://127.0.0.1:3000 -x =f

gives me

Client network socket disconnected before secure TLS connection was established

And yes, I used the correct port and I even tried with --auth

morning @Pat71
that conneciton fails cos the TLS is homemade, you need to provide a valid certificate, or allow wscat to read homemade certificates, or not use SSL with --without-ssl argument (and ws:// protocol)

i can tell wscat works cos is what im using for testing websocket communications

ok, I'm running K --without-ssl, how do I use wscat without ssl? (Sorry for being dumb ;-))

gnaaaa...just use ws: instead of wss:, yes.... now it works

It's me again:
when I try (see #953):
wscat -n --connect ws://127.0.0.1:3000 -x -d{"agree":0}
I get:
terminate called after throwing an instance of 'nlohmann::detail::out_of_range' what(): [json.exception.out_of_range.403] key 'agree' not found 06/25 20:03:38.018016 Errrror: Aborted (Three-Headed Monkey found):

@Pat71 does wscat -n --connect ws://127.0.0.1:3000 -x '-d{"agree":0}' help? you're losing the quotes around "agree" due to shell parameter interpretion.

D'oh...yes, of course that does it.

It's definitely too hot today :-/

I am very happy that there is supposed to be another solution for having some K-bot parameter to load the quoting parameters. It is also straightforward to simply install node-js. However, I don't know what you guys are using for the wscat version as I am not able to follow any of the described steps.

` wscat --auth keeroo:1337 -n -c wss://127.0.0.1:3000 -x

error: unknown option -x'

My first guess whould be about the wscat version. But I am also not finding anything on the internet about the wscat -x option.

$ wscat -V 1.1.0

Any suggestions how I could proceed regarding these situations?

Install a newer wscat that has this option:
wscat -V
2.2.1

:koala: the solution at https://github.com/ctubio/Krypto-trading-bot/issues/811#issuecomment-485596189 using wscat is awesome and is the way to go :P; thank you for your time'隆

Was this page helpful?
0 / 5 - 0 ratings

Related issues

juaxix picture juaxix  路  4Comments

rscott7 picture rscott7  路  4Comments

rconnelly picture rconnelly  路  4Comments

Camille92 picture Camille92  路  6Comments

gusiri picture gusiri  路  3Comments