Skip to content

multi: specify lots as a parameter to RequiredOrderFunds#594

Merged
chappjc merged 1 commit into
decred:masterfrom
buck54321:fix-req-funds
Aug 18, 2020
Merged

multi: specify lots as a parameter to RequiredOrderFunds#594
chappjc merged 1 commit into
decred:masterfrom
buck54321:fix-req-funds

Conversation

@buck54321
Copy link
Copy Markdown
Member

@buck54321 buck54321 commented Aug 11, 2020

RequiredOrderFunds was calculating the maximum number of possible transactions (maxSwaps = # lots) internally based on the order quantity and the lot size. But for the quote asset, the maximum number of possible transactions is not based on the quote asset lot size, it's based on the rate-equivalent quantity of base asset and it's lot size. This was causing @chappjc's over-allocation from here, because the BTC lot size was set relatively low. This could also go the other way, and under-allocate, potentially causing trouble.

Rule of thumb: Lot size is only meaningful for the base asset.

I'm leaving this in draft for a minute while I look it through and think about testing.

Comment thread client/asset/interface.go Outdated
// not be returned in subsequent calls to Fund or calculated in calls to
// Available, unless they are unlocked with ReturnCoins.
FundOrder(uint64, *dex.Asset) (Coins, error)
FundOrder(value, lots uint64, assetInfo *dex.Asset) (Coins, error)
Copy link
Copy Markdown
Member

@chappjc chappjc Aug 11, 2020

Choose a reason for hiding this comment

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

Since this can be confusing ("why do I have to specify value and lots?"), the API could frame this as, say, maxSwaps instead of lots since what this really gets to is maximum number of swap contract txns to account for in funding the fees.

I suspect that we neglected the full relevance of the fields of the dex.Asset (coin.LotSize doesn't apply to buy orders) because we didn't spell out just what they were for and which fields were used and how. So as an alternative to passing dex.Asset, we could rethink the FundOrder api to possibly use a OrderFundSpec or ContractAsset struct with just the relevant fields named explicitly for their purpose in funding an order. With this, value/maxSwaps could be a separate arg or part of this hypothetical struct. But if we document FundOrder in detail about the purpose of the passed dexAsset, which fields are pertinent to order funding, and any other args, then I have no problem with continuing to use dex.Asset.

@buck54321 buck54321 force-pushed the fix-req-funds branch 2 times, most recently from d9b77eb to 44922d5 Compare August 17, 2020 16:41
@buck54321 buck54321 marked this pull request as ready for review August 17, 2020 16:44
Comment thread client/core/core.go Outdated
@chappjc
Copy link
Copy Markdown
Member

chappjc commented Aug 18, 2020

Some minor conflicts from the funding mutex changes.

@chappjc
Copy link
Copy Markdown
Member

chappjc commented Aug 18, 2020

OK to squash if that makes the rebase cleaner.

Copy link
Copy Markdown
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

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

All good. Just needs the minor conflict resolution.

use struct for FundOrder arguments

tests and improved logging

move original coin logging up

lower case new error messages in Trade
@chappjc chappjc merged commit c7e1206 into decred:master Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants