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

Map out trades input and output data structures for CLI #27

Closed
Isaiah-Turner opened this issue Jul 6, 2020 · 1 comment
Closed

Map out trades input and output data structures for CLI #27

Isaiah-Turner opened this issue Jul 6, 2020 · 1 comment
Assignees

Comments

@Isaiah-Turner
Copy link
Contributor

What

We need to map out what information we get about trades from the new ingestion system. We also need to know what the output to BigQuery should look like. Part of #19.

Why

This issue helps us know what information about trades we can get from the ingestion system and what information may have to be reconstructed or omitted.

@Isaiah-Turner
Copy link
Contributor Author

Trades are more complicated because they can happen in a variety of different ways. Trades are effects of operations, not operations themselves. The operations that can cause a trade to occur are: OperationTypeManageBuyOffer, OperationTypeManageSellOffer, OperationTypeCreatePassiveSellOffer, OperationTypePathPaymentStrictSend, and OperationTypePathPaymentStrictReceive. We can use a LedgerTransactionReader to look through all the transactions and their operations. If one of previously listed operations is part of the transaction and it is successful, then by checking the corresponding entry in the Results field, we can get more info. The entry in Results contains types like PathPaymentStrictReceiveResult or ManageOfferResult, depending on the base type of the operation. These structs have a Success field, which has a slice of the Offers that got claimed while creating the operation. These ClaimOfferAtom structs look like

type ClaimOfferAtom struct {
    SellerId     AccountId
    OfferId      Int64
    AssetSold    Asset
    AmountSold   Int64
    AssetBought  Asset
    AmountBought Int64
}

Each one represents a trade that occurred as an effect from the base operation. For a given transaction tx, we can get the transaction itself as info := tx.Envelope.V1.Tx and we can get the trade array as
trades := tx.Result.Results[operationIndex].Tr.(operationType)Result.Success.Offers. In order to reconstruct the trade table we need:

order: integer - get from the offer's index in the slice
ledger_closed_at: timestamp - from ledger.LedgerHeader.ScpValue.CloseTime
offer_id: integer - get from trades[order].OfferId
base_account_id: integer - get from trades[order].SellerId
base_asset_id: integer - get from trades[order].AssetSold
base_amount: integer - get from trades[order].AmountSold
counter_account_id: integer - get from info.SourceAccount.ToAccountId()
counter_asset_id: integer - get from trades[order].AssetBought
counter_amount: integer - get from trades[order].AmountBought
base_is_seller: boolean - true
base_offer_id: integer - TODO: horizon uses synthetic ids here; figure out how to replicate
counter_offer_id: integer - TODO: horizon uses synthetic ids here; figure out how to replicate

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

No branches or pull requests

1 participant