Cash flow steps - datacratic/rtbkit GitHub Wiki
This doc describes how a bid request arrives to stack, as a consequence, an internal auction is performed, a bid response is sent but loses the auction at the exchange.
Assumptions :
- All accounts have just been created and thus they are all clean
- Only one bid request arrives to the stack
###Account structure
The example uses the following account structure.
nemi |--> saturno | |--> router.slaveBanker | |--> postAuction.slaveBanker | |--> jupiter |--> router.slaveBanker |--> postAuction.slaveBanker
The following is a snapshot of the state of the account structure after the bid request was processed and more than 15 second have gone by. Next to some of the money pools are the references to the steps, ie: === 3.1 === means step 3 sub-step 1.
###Budget Account - nemi
$ curl http://localhost:9985/v1/accounts/nemi { "adjustmentLineItems" : {}, "adjustmentsIn" : {}, "adjustmentsOut" : {}, "allocatedIn" : {}, "allocatedOut" : { "USD/1M" : 2300020 === 2 === }, "budgetDecreases" : {}, "budgetIncreases" : { "USD/1M" : 123000000 === 1 === }, "commitmentsMade" : {}, "commitmentsRetired" : {}, "lineItems" : {}, "md" : { "objectType" : "Account", "version" : 1 }, "recycledIn" : { "USD/1M" : 20 }, "recycledOut" : {}, "spent" : {}, "type" : "budget" }
###Budget Account - nemi:saturno
$ curl http://localhost:9985/v1/accounts/nemi:saturno { "adjustmentLineItems" : {}, "adjustmentsIn" : {}, "adjustmentsOut" : {}, "allocatedIn" : {}, "allocatedOut" : { "USD/1M" : 200020 === 3.3 === === 5.1 === }, "budgetDecreases" : {}, "budgetIncreases" : { "USD/1M" : 1200020 === 2.1 === }, "commitmentsMade" : {}, "commitmentsRetired" : {}, "lineItems" : {}, "md" : { "objectType" : "Account", "version" : 1 }, "recycledIn" : { "USD/1M" : 20 === 8.2 === }, "recycledOut" : { "USD/1M" : 20 }, "spent" : {}, "type" : "budget" }
###Budget Account - nemi:jupiter
$ curl http://localhost:9985/v1/accounts/nemi:jupiter { "adjustmentLineItems" : {}, "adjustmentsIn" : {}, "adjustmentsOut" : {}, "allocatedIn" : {}, "allocatedOut" : { "USD/1M" : 100000 === 3.5 === }, "budgetDecreases" : {}, "budgetIncreases" : { "USD/1M" : 1100000 === 2.2 === }, "commitmentsMade" : {}, "commitmentsRetired" : {}, "lineItems" : {}, "md" : { "objectType" : "Account", "version" : 1 }, "recycledIn" : {}, "recycledOut" : {}, "spent" : {}, "type" : "budget" }
###Spend Account - nemi:saturno:router.slaveBanker
$ curl http://localhost:9985/v1/accounts/nemi:saturno:router.slaveBanker { "adjustmentLineItems" : {}, "adjustmentsIn" : {}, "adjustmentsOut" : {}, "allocatedIn" : {}, "allocatedOut" : {}, "budgetDecreases" : {}, "budgetIncreases" : { "USD/1M" : 100020 === 3.1 === === 5.2 === }, "commitmentsMade" : { "USD/1M" : 20 === 4.2 === }, "commitmentsRetired" : {}, "lineItems" : {}, "md" : { "objectType" : "Account", "version" : 1 }, "recycledIn" : {}, "recycledOut" : {}, "spent" : {}, "type" : "spend" }
###Spend Account - nemi:saturno:postAuction.slaveBanker
$ curl http://localhost:9985/v1/accounts/nemi:saturno:postAuction.slaveBanker { "adjustmentLineItems" : {}, "adjustmentsIn" : {}, "adjustmentsOut" : {}, "allocatedIn" : {}, "allocatedOut" : {}, "budgetDecreases" : {}, "budgetIncreases" : { "USD/1M" : 100000 === 3.2 === }, "commitmentsMade" : {}, "commitmentsRetired" : { "USD/1M" : 20 === 7.1 === }, "lineItems" : {}, "md" : { "objectType" : "Account", "version" : 1 }, "recycledIn" : {}, "recycledOut" : { "USD/1M" : 20 === 8.1 === }, "spent" : {}, "type" : "spend" }
###Spend Account - : nemi:jupiter:router.slaveBanker
$ curl http://localhost:9985/v1/accounts/nemi:jupiter:router.slaveBanker { "adjustmentLineItems" : {}, "adjustmentsIn" : {}, "adjustmentsOut" : {}, "allocatedIn" : {}, "allocatedOut" : {}, "budgetDecreases" : {}, "budgetIncreases" : { "USD/1M" : 100000 === 3.4 === }, "commitmentsMade" : { "USD/1M" : 5 === 4.1 === }, "commitmentsRetired" : { "USD/1M" : 5 === 4.3 === }, "lineItems" : {}, "md" : { "objectType" : "Account", "version" : 1 }, "recycledIn" : {}, "recycledOut" : {}, "spent" : {}, "type" : "spend" }
###Steps for the cash flow
-
external call to nemi.setBudget(123 USD): causes nemi.budgetIncreases to go up by 123,000,000
-
external calls to saturno.setBalance(1USD) and jupiter.setBalance(1USD): causes nemi->allocatedOut to go up by 2,000,000 and :
-
saturno->budgetIncreases to go up by 1,000,000
-
jupiter->budgetIncreases to go up by 1,000,000
-
internal timed calls every second to *-router.setBalance(0.1USD) and *-pal.setBalance(0.1USD) cause each of these accounts' budgetIncreases to go up by 100,000 and the parent accounts' allocatedOut to go up by 200,000 and thus:
-
saturno:router.slaveBanker->budgetIncreases goes up by 100,000
-
saturno:postAuction.slaveBanker->budgetIncreases goes up by 100,000
-
saturno->allocatedOut goes up by 200,000
-
jupiter:router.slaveBanker->budgetIncreases goes up by 100,000
-
jupiter->allocatedOut goes up by 100,000
-
now we can bid!
- router call to jupiter-router.authorizeBid(5) causes jupiter-router.commitmentsMade to go up by 5
- router call to saturno-router.authorizeBid(20) causes saturno-router.commitmentsMade to go up by 20
- jupiter loses the internal auction, so router call to jupiter-router.cancelBid() causes jupiter-router.commitmentsRetired to go up by 5
- saturno wins the internal auction, so the commitment is communicated out of band to the post-auction loop
-
now we wait 1 second
- internal timed calls every second to *-router.setBalance(0.1USD) and *-pal.setBalance(0.1USD) cause saturno.allocatedOut to increase by 20 and saturno-router.budgetIncreases to go up by 20
-
now we wait 1 second
- internal timed calls every second to *-router.setBalance(0.1USD) and *-pal.setBalance(0.1USD) cause no change
- ... 13 more times...
-
15 seconds after the bid, the post-auction loop declares that saturno's bid has been lost
- post-auction-loop call to saturno-pal.commitBid() causes saturno-pal.commitmentsRetired to go up by 20
-
now we wait 1 second
- internal timed calls every second to *-router.setBalance(0.1USD) and *-pal.setBalance(0.1USD) cause saturno-pal.recycledOut to increase by 20 and saturno.recycledIn to go up by 20
-
now we wait 1 second
- internal timed calls every second to *-router.setBalance(0.1USD) and *-pal.setBalance(0.1USD) cause no change
- ... and so on ...