Skip to content

Gem Exchange

Ruhrpottpatriot edited this page Sep 1, 2015 · 1 revision

Introduction

The gem exchange service is not like the other services in the /v2 namespace. It does not retrieve large sets of data from a storage back-end. Instead, it converts a given number of coins-to-gems or gem-to-coins.

Terminology

  • Broker: A broker arranges transactions between a buyer and a seller for a commission when the deal is executed.
  • Quotation: A quotation is a statement of the current market price of a security or commodity. The exchange service represents a broker. The broker can provide quotations that describe the real-time conversion rate between gems and gold.

The broker has the following service contracts:

  • Get a quotation for the given quantity of a commodity
  • (not implemented) Discover the identifiers of commodities These service contracts are reflected in the code by the following interface:
  • IExchangeBroker
  • extends IBroker<GemQuotation>
  • IBroker<TQuotation>
    • GetQuotation(quantity)

Quickstart

Gold to Gems

TQuotation : GemQuotation
  1. Create an instance of the IBroker.
IBroker<GemQuotation> service = GW2.V2.Commerce.Exchange.ForCurrency("coins");
  1. Get a quotation for 100 gold.
    Underlying service: https://api.guildwars2.com/v2/commerce/exchange/coins?quantity=1000000
GemQuotation quotation = service.GetQuotation(1000000);
  1. Print the quotation.
string message = "Coins per gem: " + quotation.CoinsPerGem + "\n";
message += "To send (coins): " + quotation.Send;
message += "To receive (gems): " + quotation.Receive;
message += "Timestamp: " + quotation.Timestamp;

Coins per gem: 1366 To send (coins): 1000000 To receive (gems): 731 Timestamp: 9/27/2014 6:11:41 PM +00:00

Complete example

IBroker<GemQuotation> service = GW2.V2.Commerce.Exchange.ForCurrency("coins");
GemQuotation quotation = service.GetQuotation(1000000);
string message = "Coins per gem: " + quotation.CoinsPerGem + "\n";
message += "To send (coins): " + quotation.Send;
message += "To receive (gems): " + quotation.Receive;
message += "Timestamp: " + quotation.Timestamp;

Gems to Gold

TQuotation : GemQuotation
  1. Create an instance of the IBroker.
IBroker<GemQuotation> service = GW2.V2.Commerce.Exchange.ForCurrency("gems");
  1. Get a quotation for 100 gems.
    Underlying service: https://api.guildwars2.com/v2/commerce/exchange/gems?quantity=100
GemQuotation quotation = service.GetQuotation(100);
  1. Print the quotation.
string message = "Coins per gem: " + quotation.CoinsPerGem + "\n";
message += "To send (gems): " + quotation.Send + "\n";
message += "To receive (coins): " + quotation.Receive + "\n";
message += "Timestamp: " + quotation.Timestamp;

Coins per gem: 985 To send (gems): 100 To receive (coins): 98502 Timestamp: 9/27/2014 6:11:41 PM +00:00

Complete example

IBroker<GemQuotation> service service = GW2.V2.Commerce.Exchange.ForCurrency("gems");
GemQuotation quotation = service.GetQuotation(100);
string message = "Coins per gem: " + quotation.CoinsPerGem + "\n";
message += "To send (gems): " + quotation.Send + "\n";
message += "To receive (coins): " + quotation.Receive + "\n";
message += "Timestamp: " + quotation.Timestamp;
Console.WriteLine(message);