// You can get those variables at the B2B section of your partner account
sdk, err := b2b.New(b2b.Options{
Domain: "b2b.swapduck.space",
PartnerID: "stinky-duck-HbMytL",
PublicKey: "changeme",
PrivateKey: "changeme",
})
if err != nil {
panic(err)
}
// This will call some endpoints on our side
err = sdk.Test(context.Background())
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
<aside> ℹ️
Our XML file is based on the BestChange XML format. Currencies not present on BestChange will have IDs based on their name and network.
</aside>
xml, err := sdk.GetXML(context.Background(), "my-personal-xml")
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
// drop the .xml extension at the end
// ex.: /rates/xml/my-personal-xml.xml -> my-personal-xml
type Currency struct {
ID CurrencyIdentificationDTO `json:"id"`
CreatedAt int64 `json:"createdAt"`
IsActive bool `json:"isActive"`
BestchangeID string `json:"bestchangeId"`
PrecisionDecimals int `json:"precisionDecimals"`
LogoURL string `json:"logoUrl"`
Type string `json:"type"`
IsMemo bool `json:"isMemo"`
Description string `json:"description,omitempty"`
}
type ListCurrenciesResponse struct {
Currencies []Currency `json:"currencies"`
}
res, err := sdk.ListCurrencies(context.Background())
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
type PartnerEstimation struct {
AmountLeft string `json:"amountLeft"`
AmountRight string `json:"amountRight"`
AmountLeftUsdt string `json:"amountLeftUsdt"`
AmountRightUsdt string `json:"amountRightUsdt"`
Quotes RateQuotesDTO `json:"quotes"`
ExchangeStrategyID string `json:"exchangeStrategyId"`
AppliedNetworkFee string `json:"appliedNetworkFee"`
Hash string `json:"hash"`
MinAmount string `json:"minAmount"`
MaxAmount string `json:"maxAmount"`
}
type RateQuotesDTO struct {
SellQuote PriceQuotesDTO `json:"sellQuote"`
BuyQuote PriceQuotesDTO `json:"buyQuote"`
}
type PriceQuotesDTO struct {
BaseValue string `json:"baseValue"`
QuoteValue string `json:"quoteValue"`
}
res, err := sdk.EstimateRate(context.Background(), b2b.EstimateDTO{
AmountLeft: "1",
CurrencyLeftName: "BTC",
CurrencyLeftNetwork: "BTC",
CurrencyRightName: "USDT",
CurrencyRightNetwork: "TRC20",
})
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
type CreateOrderResponse struct {
ID string `json:"id"`
}
res, err := sdk.CreateOrder(context.Background(), b2b.CreateOrderDTO{
AmountLeft: "20",
CurrencyLeftName: "XRP",
CurrencyLeftNetwork: "XRP",
CurrencyRightName: "ETH",
CurrencyRightNetwork: "ETH",
WithdrawalAddress: "0x223a01f60375379a729031601115455a8739863e",
NotificationEmail: "test@test.com",
MarkupPercentage: "1",
})
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}