Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly write pps.toml on exit for ib and kraken #475

Merged
merged 2 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions piker/brokers/ib/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,17 @@ async def trades_dialogue(
# open ledger and pptable wrapper for each
# detected account.
ledger = ledgers[acctid] = lstack.enter_context(
open_trade_ledger('ib', acctid)
open_trade_ledger(
'ib',
acctid,
)
)
table = tables[acctid] = lstack.enter_context(
open_pps('ib', acctid)
open_pps(
'ib',
acctid,
write_on_exit=True,
)
)

for account, proxy in proxies.items():
Expand Down
10 changes: 7 additions & 3 deletions piker/brokers/kraken/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ async def cache_assets(self) -> None:

async def get_trades(
self,
fetch_limit: int = 10,
fetch_limit: int | None = None,

) -> dict[str, Any]:
'''
Expand All @@ -233,7 +233,10 @@ async def get_trades(
trades_by_id: dict[str, Any] = {}

for i in itertools.count():
if i >= fetch_limit:
if (
fetch_limit
and i >= fetch_limit
):
break

# increment 'ofs' pagination offset
Expand All @@ -246,7 +249,8 @@ async def get_trades(
by_id = resp['result']['trades']
trades_by_id.update(by_id)

# we can get up to 50 results per query
# can get up to 50 results per query, see:
# https://docs.kraken.com/rest/#tag/User-Data/operation/getTradeHistory
if (
len(by_id) < 50
):
Expand Down
23 changes: 2 additions & 21 deletions piker/brokers/kraken/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ async def trades_dialogue(
open_pps(
'kraken',
acctid,
write_on_exit=True,
) as table,

open_trade_ledger(
Expand Down Expand Up @@ -627,7 +628,7 @@ def has_pp(
cost_scalar=1,
)
log.info(
'Updated {dst} from transfers:\n'
f'Updated {dst} from transfers:\n'
f'{pformat(updated)}'
)

Expand Down Expand Up @@ -1212,23 +1213,3 @@ def norm_trade_records(
)

return records


@cm
def open_ledger(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, and i have no idea what the heck this was from lul

acctid: str,
trade_entries: list[dict[str, Any]],

) -> set[Transaction]:
'''
Write recent session's trades to the user's (local) ledger file.

'''
with open_trade_ledger(
'kraken',
acctid,
) as ledger:
yield ledger

# update on exit
ledger.update(trade_entries)