pikers / piker

(e2e) foss trading for non-tinas
GNU Affero General Public License v3.0
103 stars 17 forks source link

LIFO/"breakeven" pps for `ib` #336

Closed goodboy closed 2 years ago

goodboy commented 2 years ago

Proper attempt at #307 and a local "trades" ledger system using .toml files under <confdir>/ledgers/ where files will be named something like: trades_<brokername>_<accountname>.toml

So far ledger contents looking something like this:

Click to expand! ```toml [ib.20220512.977661167] accountId = "DUDUDUDUD" acctAlias = "" model = "" currency = "USD" fxRateToBase = 1.3046 assetCategory = "FUT" symbol = "MGCM2" description = "MGC 28JUN22" conid = 430360671 securityID = "" securityIDType = "" cusip = "" isin = "" listingExchange = "NYMEX" underlyingConid = 79702479 underlyingSymbol = "MGC" underlyingSecurityID = "" underlyingListingExchange = "" issuer = "" multiplier = 10 strike = "" expiry = 20220628 tradeID = 977661167 putCall = "" reportDate = 20220512 principalAdjustFactor = "" dateTime = "20220512;115003" tradeDate = 20220512 settleDateTarget = 20220513 transactionType = "ExchTrade" exchange = "NYMEX" quantity = 1 tradePrice = 1834.3 tradeMoney = 18343 proceeds = -18343 taxes = 0 ibCommission = -0.77 ibCommissionCurrency = "USD" netCash = -97.77 closePrice = 1824.6 openCloseIndicator = "O" notes = "" cost = 18343.77 fifoPnlRealized = 0 fxPnl = 0 mtmPnl = -97 origTradePrice = 0 origTradeDate = "" origTradeID = "" origOrderID = 0 clearingFirmID = "" transactionID = 3896422621 buySell = "BUY" ibOrderID = 398090454 ibExecID = "0000e1a7.627cece5.01.01" brokerageOrderID = "00dd230498015d2347c93b9.0001" orderReference = "" volatilityOrderLink = "" exchOrderId = "00d345980012a0234dd49[2]" extExecID = "237147708B" orderTime = "20220512;115003" openDateTime = "" holdingPeriodDateTime = "" whenRealized = "" whenReopened = "" levelOfDetail = "EXECUTION" changeInPrice = 0 changeInQuantity = 0 orderType = "LMT" traderID = "" isAPIOrder = "Y" accruedInt = 0 serialNumber = "" deliveryType = "" commodityType = "" fineness = 0.0 weight = "0.0 ()" ```

And, as of right now pps.toml entries lookin more or less like this (example only):

[ib.algopaper."mnq.globex.20220916"]
size = 58.0
be_price = 11703.458965517251
bsuid = 497954580
expiry = "2022-09-16T00:00:00+00:00"
clears = [
 { tid = "0000e1a7.629f3c2d.01.01", cost = 0.57 },
 { tid = "0000e1a7.629fa5c0.01.01", cost = 0.57 },
 { tid = "0000e1a7.62a0a898.01.01", cost = 0.57 },
 { tid = "0000e1a7.62a0fb24.01.01", cost = 0.57 },
]

REQUIREMENT:


TODO: (oustandings moved to #345)


Probably as follow up PR(s): -> See #345 for all deferrals and detailed write up of all these

goodboy commented 2 years ago

Marking this ready to get some eyes, but it's still super ib-specific and I want to still finesse a buncha stuff and make follow up issues for a more general solution / API for ledgers.

goodboy commented 2 years ago

Aight, as of right now pps.toml entries lookin more or less like this (example only):

[ib.algopaper."mnq.globex.20220916"]
size = 58.0
be_price = 11703.458965517251
bsuid = 497954580
expiry = "2022-09-16T00:00:00+00:00"
clears = [
 { tid = "0000e1a7.629f3c2d.01.01", cost = 0.57 },
 { tid = "0000e1a7.629fa5c0.01.01", cost = 0.57 },
 { tid = "0000e1a7.62a0a898.01.01", cost = 0.57 },
 { tid = "0000e1a7.62a0fb24.01.01", cost = 0.57 },
]

includes a table of .clears which is the minimal amount of data parsed from the corresponding backend ledger in order to produce the high level details.

As further refinemen we could probably,