Skip to content

Commit b10657d

Browse files
committed
Make beancounter.py into a standalone script that
uses a remote Spotbit server.
1 parent 19e7df0 commit b10657d

File tree

4 files changed

+188
-154
lines changed

4 files changed

+188
-154
lines changed

app.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ class Network(enum.Enum):
88
if __name__ == '__main__':
99

1010
import typer
11-
1211
import server
1312

1413
def make_cli(logger):
1514

16-
import beancounter
17-
beancounter.logger = logger
1815

1916
cli = typer.Typer()
2017

@@ -24,7 +21,7 @@ def run():
2421
import uvicorn
2522

2623
assert logger
27-
logger.info(f'server.app.debug: {server.app.debug}')
24+
logger.info(f'debug: {server.app.debug}')
2825
uvicorn.run('server:app',
2926
host ='127.0.0.1',
3027
port = 5000,
@@ -34,39 +31,6 @@ def run():
3431
reload_includes = ['spotbit.config'] # FIXME(nochiel) Does nothing?
3532
)
3633

37-
default_exchange_id = list(server.supported_exchanges.keys())[0]
38-
default_currency = server.settings.currencies[0]
39-
@cli.command()
40-
def beancount(descriptor: beancounter.Descriptor,
41-
network: str = Network.TESTNET.value,
42-
exchange: server.ExchangeName = default_exchange_id,
43-
currency: server.CurrencyName = default_currency):
44-
'''
45-
Generate a beancount file using the transactions found by generating addresses from the bitcoin mainnet descriptor.
46-
47-
Ref. https://beancount.github.io/docs/trading_with_beancount.html
48-
'''
49-
50-
typer.echo(f'Generating beancount report for descriptor: {descriptor}')
51-
typer.echo(f'Using currency: {currency}')
52-
typer.echo(f'Using exchange: {exchange}')
53-
54-
import bdkpython as bdk
55-
bdk_network = bdk.Network.TESTNET
56-
match network:
57-
case Network.BITCOIN:
58-
bdk_network = bdk.Network.BITCOIN
59-
case Network.TESTNET:
60-
bdk_network = bdk.Network.TESTNET
61-
try:
62-
beancounter.make_beancount_from_descriptor(descriptor = descriptor,
63-
exchange = exchange,
64-
currency = currency,
65-
network = bdk_network)
66-
except Exception as e:
67-
typer.echo(f'An error occurred while generating a beancount file: {e}')
68-
69-
7034
return cli
7135

7236
cli = make_cli(server.logger)

0 commit comments

Comments
 (0)