-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbidder.h
227 lines (196 loc) · 6.3 KB
/
bidder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
* BiddingAgent.h
*
* Created on: Oct 26, 2013
* Author: jan
*/
#pragma once
#include <string>
#include <memory>
#include <vector>
#include <functional>
namespace lwrtb {
// enum class BidStatus: char
enum BidStatus
{
WIN, ///< Bid was won
LOSS, ///< Bid was lost
TOOLATE, ///< Bid was too late and so not accepted
INVALID, ///< Bid was invalid and so not accepted
LOSTBID, ///< Bid was lost somewhere
DROPPEDBID, ///< Bid was dropped as way too late
NOBUDGET, ///< No budget
BUG ///< Bug request
};
inline
std::string BidStatusToString (BidStatus status)
{
switch (status)
{
case BidStatus::WIN: return "WIN";
case BidStatus::LOSS: return "LOSS";
case BidStatus::TOOLATE: return "TOOLATE";
case BidStatus::INVALID: return "INVALID";
case BidStatus::LOSTBID: return "LOSTBID";
case BidStatus::DROPPEDBID: return "DROPPEDBID";
case BidStatus::NOBUDGET: return "NOBUDGET";
case BidStatus::BUG: return "BUG";
default: return "NOPE";
}
}
// forward
class Bidder;
//
// DELIVERY
//
struct DeliveryEvent
{
std::string event;
double timestamp; // number of seconds since epoch
std::string auctionId;
std::string spotId;
int spotIndex;
std::string bidRequest;
std::string augmentations;
std::string bid;
std::string win;
std::string campaignEvents;
std::vector<std::string> visits;
};
class DeliveryCb
{
public:
DeliveryCb() {}
virtual ~DeliveryCb() {}
virtual void call(Bidder& , const DeliveryEvent&) {}
};
//
// BID REQUEST
//
struct BidRequestEvent
{
double timestamp; // Start time of the auction.
std::string id; // Auction id
std::string bidRequest;
std::string bids; // Impressions available for bidding
double timeLeftMs; // Time left of the bid request.
std::string augmentations; // Data from the augmentors.
std::string winCostModel; // Win cost model.
};
class BidRequestCb
{
public:
BidRequestCb() {}
virtual ~BidRequestCb() {}
virtual void call(Bidder& , const BidRequestEvent&) { }
};
//
// BID RESULT
//
struct BidResultEvent
{
BidStatus result; ///> Result of our bid
double timestamp; ///> Time at which the event occured
std::string auctionId; ///> Unique auction id for the original bid
int spotNum; ///> Spot index into the bidRequest.imp or ourBid
std::string secondPrice; ///> Depends on result from router or the exchange
std::string bidRequest; ///> Original request we bid on
std::string ourBid; ///> Original bids that was placed
std::string metadata; ///> Metadata that was attached to the bid
std::string augmentations; ///> Original Augmentations sent with the request
};
class BidResultCb
{
public:
BidResultCb() {}
virtual ~BidResultCb() {}
virtual void call(Bidder& , const BidResultEvent&) {}
};
//
// ERROR
//
struct ErrorEvent
{
double timestamp;
std::string description;
std::vector<std::string> originalError;
};
class ErrorCb
{
public:
ErrorCb() {}
virtual ~ErrorCb() {}
virtual void call(Bidder& , const ErrorEvent&) {}
};
class Bidder
{
public:
/**
* Create a bidder.
* \param name name give to the bidder.
*/
Bidder(const std::string& name,
const std::string& service_proxy_config = "");
virtual ~Bidder();
void init();
void start(bool sync=false );
void shutdown();
/** Notify the AgentConfigurationService that the configuration of the
* bidding agent has changed.
* \param config string rep. of a AgentConfig json object
* Note that bidding agent will remember the given configuration which will
* be used to answer any further configuration requests that are received.
* This function is thread-safe and can be called at any time to change the
* bid request which will be received by the agent. Note that update are
* done asynchronously and changes might not take effect immediately.
*/
void doConfig(const std::string& config);
/** Send a bid response to the router in answer to a received auction.
* \param id string rep. of an auction id given in the auction callback.
* \param bids string rep. of a Bids struct converted to json.
* \param meta string rep. of a json blob that will be returned as is in the bid result.
* \param wcm string rep of a Win cost model to be used.
*/
void doBid(const std::string& id,
const std::string& bids,
const std::string& meta = "",
const std::string& wmc = "");
/**
* the following callback if set, will be used
* for the delivery of relevant bid requests
*/
std::function<void(const BidRequestEvent&)> bid_request_cb_;
/**
* the following callback, if set, will be used i/o
* dispatch results coming from back from the router.
*/
std::function<void(const BidResultEvent&)> bid_result_cb_;
/**
* the following callback, if set, will be used i/o
* dispatch results coming from back from the router.
*/
std::function<void(const DeliveryEvent&)> delivery_event_cb_;
/**
* whenever router receives an invalid message from the
* agent. This can either be caused by an invalid config,
* and invalid bid
*/
std::function<void(const ErrorEvent&)> error_cb_;
void setBidRequestCb (BidRequestCb&);
void setDeliveryCb (DeliveryCb&);
void setBidResultCb (BidResultCb&);
void setErrorCb (ErrorCb&);
private:
const std::string name_;
class impl;
std::unique_ptr<impl> pimpl_;
// SWIG plumbing
BidResultCb* swig_bres_cb_ ;
DeliveryCb* swig_devr_cb_ ;
ErrorCb* swig_err_cb_ ;
BidRequestCb* swig_breq_cb_ ;
// unwanted.
Bidder(const Bidder&);
Bidder& operator=(const Bidder&);
};
} /* namespace lwrtb */