View as Markdown

Auctions

Read more about the Auctions system in Hiro here .

Creating a New Auction #

To create a new auction, use the auctionsCreate function.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
void onAuctionCreate(const Hiro::Auction& auction)
{
    for (auto it = auction.reward.items.begin(); it != auction.reward.items.end(); it++)
    {
        std::cout << "Found codex item: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::AuctionCreateRequest request;
request.templateId = "template_auction_001";
request.conditionId = "condition_001";
request.instanceIds.insert(std::make_pair<std::string, std::string>("item_instance_001", "1"));

hiroClient->auctionsCreate(session, request, onAuctionCreate, onError);

To create a directed auction that’s only visible to specific players, set allowedUserIds to the list of user IDs who are allowed to see and bid on it. This is useful for restricted auctions such as guild sales, friends-only listings, or one-to-one trades.

1
2
3
4
5
6
7
Hiro::AuctionCreateRequest request;
request.templateId = "template_auction_001";
request.conditionId = "condition_001";
request.instanceIds.insert(std::make_pair<std::string, std::string>("item_instance_001", "1"));
request.allowedUserIds.push_back("friend_user_id_001");

hiroClient->auctionsCreate(session, request, onAuctionCreate, onError);

Placing a Bid on an Auction #

You can place a bid on an auction using the auctionsBid function.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
void OnAuctionsBid(const Hiro::Auction& auction)
{
    for (auto it = auction.reward.items.begin(); it != auction.reward.items.end(); it++)
    {
        std::cout << "Found codex item: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::AuctionBidRequest request;
request.id = "auction_instance_123";
request.version = "condition_001";
request.bid.currencies.insert(std::make_pair<std::string, std::string>("gold", "1000"));

hiroClient->auctionsBid(session, request, OnAuctionsBid, onError);

A bid isn’t limited to currencies. Set instanceIds on request.bid to escrow inventory item instances as part of the bid, letting a player trade items instead of, or alongside, currency. Currencies are optional when the bid includes items.

1
2
3
4
5
6
Hiro::AuctionBidRequest request;
request.id = "auction_instance_123";
request.version = "condition_001";
request.bid.instanceIds.push_back("item_instance_002");

hiroClient->auctionsBid(session, request, OnAuctionsBid, onError);

Canceling an Auction #

If an auction needs to be canceled before it ends, the auctionsCancel method can be used.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
void OnAuctionsCancel(const Hiro::AuctionCancel& auctionCancel)
{
    for (auto it = auctionCancel.reward.items.begin(); it != auctionCancel.reward.items.end(); it++)
    {
        std::cout << "Found codex item: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::AuctionsCancelRequest request;
request.id = "auction_instance_123";

hiroClient->auctionsCancel(session, request, OnAuctionsBid, onError);

Claiming a Winning Bid #

Once an auction has ended, the winning bidder can claim their item using auctionsClaimBid.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
void OnAuctionsClaimBid(const Hiro::AuctionClaimBid& auctionClaimBid)
{
    for (auto it = auctionClaimBid.reward.items.begin(); it != auctionClaimBid.reward.items.end(); it++)
    {
        std::cout << "Found codex item: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::AuctionClaimBidRequest request;
request.id = "auction_instance_123";

hiroClient->auctionsClaimBid(session, request, OnAuctionsBid, onError);

Listing Available Auctions #

You can list the currently available auctions using the auctionsList function.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
void OnAuctionsList(const Hiro::AuctionList& auctionList)
{
    for (auto it = auctions.begin(); it != auctions.end(); it++)
    {
        std::cout << "Auction found: " << it->second.id << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::AuctionListRequest request;

hiroClient->auctionsList(session, request, OnAuctionsBid, onError);

Set allowedOnly to true to return only the directed auctions where the caller is on the allowedUserIds list, for example auctions a friend created just for them. Leave it false (the default) to return only public auctions. The two result sets are disjoint, so you need separate calls to get both public and directed auctions.

1
2
3
4
Hiro::AuctionListRequest request;
request.allowedOnly = true;

hiroClient->auctionsList(session, request, OnAuctionsBid, onError);

Directed auction and item bid response fields #

A few response fields support restricted auctions:

  • Auction.allowedUserIds: the user IDs allowed to see and bid on a directed auction, if any.
  • Auction.immediateBuyout: whether the auction completes immediately once a bid meets the buyout price, as configured on AuctionTemplateCondition.immediateBuyout.
  • AuctionClaimCreated.receivedItems: the inventory items the creator receives from the winning bid, if the winning bid included items instead of, or alongside, currencies.