RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 00009 #pragma once 00010 00011 #include "bid_request.h" 00012 #include "currency.h" 00013 #include "account_key.h" 00014 00015 #include "soa/jsoncpp/value.h" 00016 #include "jml/utils/compact_vector.h" 00017 00018 namespace ML { struct Parse_Context; } 00019 00020 namespace RTBKIT { 00021 00022 /*****************************************************************************/ 00023 /* BID STATUS */ 00024 /*****************************************************************************/ 00025 00026 enum BidStatus { 00027 BS_WIN, 00028 BS_LOSS, 00029 BS_TOOLATE, 00030 BS_INVALID, 00031 BS_LOSTBID, 00032 BS_DROPPEDBID, 00033 BS_NOBUDGET 00034 }; 00035 00036 BidStatus bidStatusFromString(const std::string& str); 00037 00038 const char* bidStatusToChar(BidStatus status); 00039 inline std::string bidStatusToString(BidStatus status) 00040 { 00041 return std::string(bidStatusToChar(status)); 00042 } 00043 00044 00045 /******************************************************************************/ 00046 /* BIDS */ 00047 /******************************************************************************/ 00048 00055 struct Bid 00056 { 00057 00058 Bid() : creativeIndex(-1), price(), priority(0.0), account() {} 00059 00060 00064 SmallIntVector availableCreatives; 00065 int spotIndex; // Index of the spot in the bid request. 00066 00067 00073 int creativeIndex; 00074 Amount price; // The amount we wish to bid. 0 means no bid. 00075 double priority; // Use as a tie breaker in the router. 00076 00084 AccountKey account; 00085 00086 00087 bool isNullBid() const { return price.isZero(); } 00088 00089 void bid(int creativeIndex, Amount price, double priority = 0.0); 00090 00091 Json::Value toJson() const; 00092 static Bid fromJson(ML::Parse_Context&); 00093 }; 00094 00101 struct Bids : public ML::compact_vector<Bid, 4> 00102 { 00107 std::set<std::string> dataSources; 00108 00109 Json::Value toJson() const; 00110 static Bids fromJson(const std::string& raw); 00111 }; 00112 00113 00114 /******************************************************************************/ 00115 /* BID RESULT */ 00116 /******************************************************************************/ 00117 00121 struct BidResult 00122 { 00123 BidStatus result; 00124 double timestamp; 00125 00126 Id auctionId; 00127 int spotNum; 00128 Amount secondPrice; 00129 std::string confidence; 00130 00131 std::shared_ptr<BidRequest> request; 00132 Bids ourBid; 00133 Json::Value metadata; 00134 Json::Value augmentations; 00135 00136 static BidResult parse(const std::vector<std::string>& msg); 00137 }; 00138 00139 00140 } // namespace RTBKIT