1
0

Compare commits

..

No commits in common. "02d663ed5383c939523b863a002ed8c478bcd188" and "3533c515ae9a0fa60e60dc40bd7db8567dcce3df" have entirely different histories.

6 changed files with 51 additions and 151 deletions

View File

@ -6,11 +6,12 @@
Automatic one-way trades. Automatic one-way trades.
This program is a wrapper around This is a wrapper about [`fin_depo`](https://gitfub.space/Jmaa/fin-depo/) for
[`fin_depo`](https://gitfub.space/Jmaa/fin-depo/) for automatically trading automatically trading one way trades, by using repeated trades
one-way trades, by using repeated trades over a period. Can be used to slowly over a period.
enter or exit positions, for example low-volume crypto currencies, or as an
automated investment savings system. The primary motivation is for trading low-volume crypto assets slowly without
affecting the price too much.
Supported sites: Supported sites:
@ -26,51 +27,23 @@ pip install -r requirements.txt
## Usage ## Usage
1. Create configuration file. See below and in `examples/` folder for inspiration. Run using from the top directory:
2. [Create KuCoin API key](https://www.kucoin.com/account/api) with **General**
and **Spot Trading** permissions. ```shell
3. Add KuCoin API key secrets (`KUCOIN_KEY`, `KUCOIN_SECRET`, `KUCOIN_PASS`) to python -m crypto_seller
an [`secret_loader` accessible ```
location](https://gitfub.space/Jmaa/secret_loader#user-content-accessible) .
4. Run script using `python -m crypto_seller --config CONFIG_FILE`.
The script will now automatically sell assets over time. The interval between The script will now automatically sell assets over time. The interval between
sell-offs are randomized to avoid front-running, and the amounts are also sell-offs are randomized to avoid front-running, and the amounts are also
randomized to avoid certain attacks (only relevant for smallish intervals of randomized to avoid too consistent behaviour.
less than a week).
The log will both be displayed in the shell, and be placed in a log file The log will both be displayed in the shell, and be placed in a log file
`output/log.txt`. Every sell-off will be logged to the `output/trades.csv` `output/log.txt`. Every sell-off will be logged to the `output/trades.csv`
file, with as much information as possible. Keep both of these for tax file, with as much information as possible. Keep both of these for tax
purposes, if relevant. purposes, if relevant.
## Configuration
Example configurations can be found in the `examples/` folder.
Configurations are `.json` files, with the following fields:
```json
{
"input_asset": str,
"output_asset": str,
"input_amount_low": float,
"input_amount_high": float,
"interval_minutes_low": int,
"interval_minutes_high": int
}
```
While `input_amount_low` and `input_amount_high` can be identical (and
the same for `interval_minutes_XX`) it is discouraged, to avoid frontrunning attacks.
## Auditing information ## Auditing information
As mentioned before, this program is mostly glue code and wrappering around
library functionality. The glue application code allows for running the main
loop of checking balance, selling amount and sleeping until the next iteration,
with some argument and configuration parsing thrown in.
The most relevant libraries for auditing are: The most relevant libraries for auditing are:
- [`fin_depo`](https://gitfub.space/Jmaa/fin-depo): Library for programmatic - [`fin_depo`](https://gitfub.space/Jmaa/fin-depo): Library for programmatic
@ -78,11 +51,8 @@ The most relevant libraries for auditing are:
This is the library that reads balances and places market orders. This is the library that reads balances and places market orders.
- [`fin_defs`](https://gitfub.space/Jmaa/fin-defs): Definitions of financial - [`fin_defs`](https://gitfub.space/Jmaa/fin-defs): Definitions of financial
assets and instruments. Used by `fin_depo`. assets and instruments. Used by `fin_depo`.
- [`secret_loader`](https://gitfub.space/Jmaa/secret_loader): Library for - [`python-kucoin`](https://python-kucoin.readthedocs.io/en/latest/) is used by
loading of secrets (passwords, API keys, secret keys, configuration files, `fin_depo` for providing KuCoin support.
etc.) from standardized locations.
- [`python-kucoin`](https://python-kucoin.readthedocs.io/en/latest/): Used by
`fin_depo` to provide KuCoin backend.
## Taxation ## Taxation
@ -107,8 +77,8 @@ most mature on the danish market, and does support KuCoin.
* Catch runtime errors when selling * Catch runtime errors when selling
* Show errors to log. * Show errors to log.
* Stop loop and exit with results, and error indicator. * Stop loop and exit with results, and error indicator.
- [X] Document configuration - [ ] Document configuration
- [X] Document code auditing - [ ] Document code auditing
- [X] Parse configuration from json. - [X] Parse configuration from json.
- [X] Ensure sell time is included in order details - [X] Ensure sell time is included in order details
- [X] Log all trades to CSV file. - [X] Log all trades to CSV file.

View File

@ -2,11 +2,12 @@
Automatic one-way trades. Automatic one-way trades.
This program is a wrapper around This is a wrapper about [`fin_depo`](https://gitfub.space/Jmaa/fin-depo/) for
[`fin_depo`](https://gitfub.space/Jmaa/fin-depo/) for automatically trading automatically trading one way trades, by using repeated trades
one-way trades, by using repeated trades over a period. Can be used to slowly over a period.
enter or exit positions, for example low-volume crypto currencies, or as an
automated investment savings system. The primary motivation is for trading low-volume crypto assets slowly without
affecting the price too much.
Supported sites: Supported sites:
@ -22,51 +23,23 @@ pip install -r requirements.txt
## Usage ## Usage
1. Create configuration file. See below and in `examples/` folder for inspiration. Run using from the top directory:
2. [Create KuCoin API key](https://www.kucoin.com/account/api) with **General**
and **Spot Trading** permissions. ```shell
3. Add KuCoin API key secrets (`KUCOIN_KEY`, `KUCOIN_SECRET`, `KUCOIN_PASS`) to python -m crypto_seller
an [`secret_loader` accessible ```
location](https://gitfub.space/Jmaa/secret_loader#user-content-accessible) .
4. Run script using `python -m crypto_seller --config CONFIG_FILE`.
The script will now automatically sell assets over time. The interval between The script will now automatically sell assets over time. The interval between
sell-offs are randomized to avoid front-running, and the amounts are also sell-offs are randomized to avoid front-running, and the amounts are also
randomized to avoid certain attacks (only relevant for smallish intervals of randomized to avoid too consistent behaviour.
less than a week).
The log will both be displayed in the shell, and be placed in a log file The log will both be displayed in the shell, and be placed in a log file
`output/log.txt`. Every sell-off will be logged to the `output/trades.csv` `output/log.txt`. Every sell-off will be logged to the `output/trades.csv`
file, with as much information as possible. Keep both of these for tax file, with as much information as possible. Keep both of these for tax
purposes, if relevant. purposes, if relevant.
## Configuration
Example configurations can be found in the `examples/` folder.
Configurations are `.json` files, with the following fields:
```json
{
"input_asset": str,
"output_asset": str,
"input_amount_low": float,
"input_amount_high": float,
"interval_minutes_low": int,
"interval_minutes_high": int
}
```
While `input_amount_low` and `input_amount_high` can be identical (and
the same for `interval_minutes_XX`) it is discouraged, to avoid frontrunning attacks.
## Auditing information ## Auditing information
As mentioned before, this program is mostly glue code and wrappering around
library functionality. The glue application code allows for running the main
loop of checking balance, selling amount and sleeping until the next iteration,
with some argument and configuration parsing thrown in.
The most relevant libraries for auditing are: The most relevant libraries for auditing are:
- [`fin_depo`](https://gitfub.space/Jmaa/fin-depo): Library for programmatic - [`fin_depo`](https://gitfub.space/Jmaa/fin-depo): Library for programmatic
@ -74,11 +47,8 @@ The most relevant libraries for auditing are:
This is the library that reads balances and places market orders. This is the library that reads balances and places market orders.
- [`fin_defs`](https://gitfub.space/Jmaa/fin-defs): Definitions of financial - [`fin_defs`](https://gitfub.space/Jmaa/fin-defs): Definitions of financial
assets and instruments. Used by `fin_depo`. assets and instruments. Used by `fin_depo`.
- [`secret_loader`](https://gitfub.space/Jmaa/secret_loader): Library for - [`python-kucoin`](https://python-kucoin.readthedocs.io/en/latest/) is used by
loading of secrets (passwords, API keys, secret keys, configuration files, `fin_depo` for providing KuCoin support.
etc.) from standardized locations.
- [`python-kucoin`](https://python-kucoin.readthedocs.io/en/latest/): Used by
`fin_depo` to provide KuCoin backend.
## Taxation ## Taxation
@ -103,8 +73,8 @@ most mature on the danish market, and does support KuCoin.
* Catch runtime errors when selling * Catch runtime errors when selling
* Show errors to log. * Show errors to log.
* Stop loop and exit with results, and error indicator. * Stop loop and exit with results, and error indicator.
- [X] Document configuration - [ ] Document configuration
- [X] Document code auditing - [ ] Document code auditing
- [X] Parse configuration from json. - [X] Parse configuration from json.
- [X] Ensure sell time is included in order details - [X] Ensure sell time is included in order details
- [X] Log all trades to CSV file. - [X] Log all trades to CSV file.

View File

@ -1 +1 @@
__version__ = '0.1.3' __version__ = '0.1.2'

View File

@ -1,17 +1,12 @@
import csv import csv
import dataclasses
from pathlib import Path from pathlib import Path
import fin_depo import fin_depo
@dataclasses.dataclass(frozen=True)
class CsvFileLogger: class CsvFileLogger:
"""Outputs the given `TradeOrderDetails` to the CSV file at the specified def __init__(self, path: Path):
path. self.path = path
"""
path: Path
def __call__(self, trade_order: fin_depo.data.TradeOrderDetails): def __call__(self, trade_order: fin_depo.data.TradeOrderDetails):
fieldnames: list[str] = [ fieldnames: list[str] = [
@ -26,10 +21,6 @@ class CsvFileLogger:
'raw_order_details', 'raw_order_details',
] ]
# Ensure that directory exists
self.path.parent.mkdir(parents=True, exist_ok=True)
# Write row in CSV file
with open(self.path, 'a') as f: with open(self.path, 'a') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames) writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writerow(trade_order.__dict__) writer.writerow(trade_order.__dict__)

View File

@ -1,5 +1,4 @@
"""Handles secrets for the `crypto_seller` system.""" """Handles secrets for the `crypto_seller` system."""
from secret_loader import SecretLoader from secret_loader import SecretLoader
__all__ = ['KUCOIN_KEY', 'KUCOIN_SECRET', 'KUCOIN_PASS'] __all__ = ['KUCOIN_KEY', 'KUCOIN_SECRET', 'KUCOIN_PASS']

View File

@ -15,11 +15,12 @@ PACKAGE_DESCRIPTION = """
Automatic one-way trades. Automatic one-way trades.
This program is a wrapper around This is a wrapper about [`fin_depo`](https://gitfub.space/Jmaa/fin-depo/) for
[`fin_depo`](https://gitfub.space/Jmaa/fin-depo/) for automatically trading automatically trading one way trades, by using repeated trades
one-way trades, by using repeated trades over a period. Can be used to slowly over a period.
enter or exit positions, for example low-volume crypto currencies, or as an
automated investment savings system. The primary motivation is for trading low-volume crypto assets slowly without
affecting the price too much.
Supported sites: Supported sites:
@ -35,51 +36,23 @@ pip install -r requirements.txt
## Usage ## Usage
1. Create configuration file. See below and in `examples/` folder for inspiration. Run using from the top directory:
2. [Create KuCoin API key](https://www.kucoin.com/account/api) with **General**
and **Spot Trading** permissions. ```shell
3. Add KuCoin API key secrets (`KUCOIN_KEY`, `KUCOIN_SECRET`, `KUCOIN_PASS`) to python -m crypto_seller
an [`secret_loader` accessible ```
location](https://gitfub.space/Jmaa/secret_loader#user-content-accessible) .
4. Run script using `python -m crypto_seller --config CONFIG_FILE`.
The script will now automatically sell assets over time. The interval between The script will now automatically sell assets over time. The interval between
sell-offs are randomized to avoid front-running, and the amounts are also sell-offs are randomized to avoid front-running, and the amounts are also
randomized to avoid certain attacks (only relevant for smallish intervals of randomized to avoid too consistent behaviour.
less than a week).
The log will both be displayed in the shell, and be placed in a log file The log will both be displayed in the shell, and be placed in a log file
`output/log.txt`. Every sell-off will be logged to the `output/trades.csv` `output/log.txt`. Every sell-off will be logged to the `output/trades.csv`
file, with as much information as possible. Keep both of these for tax file, with as much information as possible. Keep both of these for tax
purposes, if relevant. purposes, if relevant.
## Configuration
Example configurations can be found in the `examples/` folder.
Configurations are `.json` files, with the following fields:
```json
{
"input_asset": str,
"output_asset": str,
"input_amount_low": float,
"input_amount_high": float,
"interval_minutes_low": int,
"interval_minutes_high": int
}
```
While `input_amount_low` and `input_amount_high` can be identical (and
the same for `interval_minutes_XX`) it is discouraged, to avoid frontrunning attacks.
## Auditing information ## Auditing information
As mentioned before, this program is mostly glue code and wrappering around
library functionality. The glue application code allows for running the main
loop of checking balance, selling amount and sleeping until the next iteration,
with some argument and configuration parsing thrown in.
The most relevant libraries for auditing are: The most relevant libraries for auditing are:
- [`fin_depo`](https://gitfub.space/Jmaa/fin-depo): Library for programmatic - [`fin_depo`](https://gitfub.space/Jmaa/fin-depo): Library for programmatic
@ -87,11 +60,8 @@ The most relevant libraries for auditing are:
This is the library that reads balances and places market orders. This is the library that reads balances and places market orders.
- [`fin_defs`](https://gitfub.space/Jmaa/fin-defs): Definitions of financial - [`fin_defs`](https://gitfub.space/Jmaa/fin-defs): Definitions of financial
assets and instruments. Used by `fin_depo`. assets and instruments. Used by `fin_depo`.
- [`secret_loader`](https://gitfub.space/Jmaa/secret_loader): Library for - [`python-kucoin`](https://python-kucoin.readthedocs.io/en/latest/) is used by
loading of secrets (passwords, API keys, secret keys, configuration files, `fin_depo` for providing KuCoin support.
etc.) from standardized locations.
- [`python-kucoin`](https://python-kucoin.readthedocs.io/en/latest/): Used by
`fin_depo` to provide KuCoin backend.
## Taxation ## Taxation
@ -116,8 +86,8 @@ most mature on the danish market, and does support KuCoin.
* Catch runtime errors when selling * Catch runtime errors when selling
* Show errors to log. * Show errors to log.
* Stop loop and exit with results, and error indicator. * Stop loop and exit with results, and error indicator.
- [X] Document configuration - [ ] Document configuration
- [X] Document code auditing - [ ] Document code auditing
- [X] Parse configuration from json. - [X] Parse configuration from json.
- [X] Ensure sell time is included in order details - [X] Ensure sell time is included in order details
- [X] Log all trades to CSV file. - [X] Log all trades to CSV file.