-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Alexander Tanti <tantialex@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
366 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Binance.Spot.GiftCardExamples | ||
{ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Binance.Common; | ||
using Binance.Spot; | ||
using Binance.Spot.Models; | ||
using Microsoft.Extensions.Logging; | ||
|
||
public class CreateBinanceCode_Example | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
using var loggerFactory = LoggerFactory.Create(builder => | ||
{ | ||
builder.AddConsole(); | ||
}); | ||
ILogger logger = loggerFactory.CreateLogger<CreateBinanceCode_Example>(); | ||
|
||
HttpMessageHandler loggingHandler = new BinanceLoggingHandler(logger: logger); | ||
HttpClient httpClient = new HttpClient(handler: loggingHandler); | ||
|
||
var giftCard = new GiftCard(httpClient); | ||
|
||
var result = await giftCard.CreateBinanceCode("BUSD", 20.01); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Binance.Spot.GiftCardExamples | ||
{ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Binance.Common; | ||
using Binance.Spot; | ||
using Binance.Spot.Models; | ||
using Microsoft.Extensions.Logging; | ||
|
||
public class RedeemBinanceCode_Example | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
using var loggerFactory = LoggerFactory.Create(builder => | ||
{ | ||
builder.AddConsole(); | ||
}); | ||
ILogger logger = loggerFactory.CreateLogger<RedeemBinanceCode_Example>(); | ||
|
||
HttpMessageHandler loggingHandler = new BinanceLoggingHandler(logger: logger); | ||
HttpClient httpClient = new HttpClient(handler: loggingHandler); | ||
|
||
var giftCard = new GiftCard(httpClient); | ||
|
||
var result = await giftCard.RedeemBinanceCode("X1X1X1X1X1X11XX1X11X1"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Binance.Spot.GiftCardExamples | ||
{ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Binance.Common; | ||
using Binance.Spot; | ||
using Binance.Spot.Models; | ||
using Microsoft.Extensions.Logging; | ||
|
||
public class VerifyBinanceCode_Example | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
using var loggerFactory = LoggerFactory.Create(builder => | ||
{ | ||
builder.AddConsole(); | ||
}); | ||
ILogger logger = loggerFactory.CreateLogger<VerifyBinanceCode_Example>(); | ||
|
||
HttpMessageHandler loggingHandler = new BinanceLoggingHandler(logger: logger); | ||
HttpClient httpClient = new HttpClient(handler: loggingHandler); | ||
|
||
var giftCard = new GiftCard(httpClient); | ||
|
||
var result = await giftCard.VerifyBinanceCode("00000000000000000"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
open System | ||
open System.Net | ||
open System.Net.Http | ||
open System.Threading.Tasks | ||
open Microsoft.Extensions.Logging | ||
open Binance.Common | ||
open Binance.Spot | ||
open Binance.Spot.Models | ||
|
||
[<EntryPoint>] | ||
let main argv = | ||
let loggerFactory = LoggerFactory.Create(fun (builder:ILoggingBuilder) -> | ||
builder.AddConsole() |> ignore | ||
) | ||
let logger = loggerFactory.CreateLogger() | ||
|
||
let loggingHandler = new BinanceLoggingHandler(logger) | ||
let httpClient = new HttpClient(loggingHandler) | ||
|
||
let giftCard = new GiftCard(httpClient) | ||
|
||
let result = giftCard.CreateBinanceCode("BUSD", 20.01) |> Async.AwaitTask |> Async.RunSynchronously | ||
|
||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
open System | ||
open System.Net | ||
open System.Net.Http | ||
open System.Threading.Tasks | ||
open Microsoft.Extensions.Logging | ||
open Binance.Common | ||
open Binance.Spot | ||
open Binance.Spot.Models | ||
|
||
[<EntryPoint>] | ||
let main argv = | ||
let loggerFactory = LoggerFactory.Create(fun (builder:ILoggingBuilder) -> | ||
builder.AddConsole() |> ignore | ||
) | ||
let logger = loggerFactory.CreateLogger() | ||
|
||
let loggingHandler = new BinanceLoggingHandler(logger) | ||
let httpClient = new HttpClient(loggingHandler) | ||
|
||
let giftCard = new GiftCard(httpClient) | ||
|
||
let result = giftCard.RedeemBinanceCode("X1X1X1X1X1X11XX1X11X1") |> Async.AwaitTask |> Async.RunSynchronously | ||
|
||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
open System | ||
open System.Net | ||
open System.Net.Http | ||
open System.Threading.Tasks | ||
open Microsoft.Extensions.Logging | ||
open Binance.Common | ||
open Binance.Spot | ||
open Binance.Spot.Models | ||
|
||
[<EntryPoint>] | ||
let main argv = | ||
let loggerFactory = LoggerFactory.Create(fun (builder:ILoggingBuilder) -> | ||
builder.AddConsole() |> ignore | ||
) | ||
let logger = loggerFactory.CreateLogger() | ||
|
||
let loggingHandler = new BinanceLoggingHandler(logger) | ||
let httpClient = new HttpClient(loggingHandler) | ||
|
||
let giftCard = new GiftCard(httpClient) | ||
|
||
let result = giftCard.VerifyBinanceCode("00000000000000000") |> Async.AwaitTask |> Async.RunSynchronously | ||
|
||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
namespace Binance.Spot | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Binance.Spot.Models; | ||
|
||
public class GiftCard : SpotService | ||
{ | ||
public GiftCard(string baseUrl = DEFAULT_SPOT_BASE_URL, string apiKey = null, string apiSecret = null) | ||
: this(new HttpClient(), baseUrl: baseUrl, apiKey: apiKey, apiSecret: apiSecret) | ||
{ | ||
} | ||
|
||
public GiftCard(HttpClient httpClient, string baseUrl = DEFAULT_SPOT_BASE_URL, string apiKey = null, string apiSecret = null) | ||
: base(httpClient, baseUrl: baseUrl, apiKey: apiKey, apiSecret: apiSecret) | ||
{ | ||
} | ||
|
||
private const string CREATE_BINANCE_CODE = "/sapi/v1/giftcard/createCode"; | ||
|
||
/// <summary> | ||
/// This API is for creating a Binance Code. To get started with, please make sure:.<para /> | ||
/// You have a Binance account.<para /> | ||
/// You have passed kyc.<para /> | ||
/// You have a sufficient balance in your Binance funding wallet.<para /> | ||
/// You need Enable Withdrawals for the API Key which requests this endpoint.<para /> | ||
/// Weight(IP): 1.<para /> | ||
/// Daily creation volume: 2 BTC / 24H Daily creation times: 200 Codes / 24H. | ||
/// </summary> | ||
/// <param name="token">The coin type contained in the Binance Code.</param> | ||
/// <param name="amount">The amount of the coin.</param> | ||
/// <param name="recvWindow">The value cannot be greater than 60000.</param> | ||
/// <returns>Binance Gift Card Code.</returns> | ||
public async Task<string> CreateBinanceCode(string token, double amount, long? recvWindow = null) | ||
{ | ||
var result = await this.SendSignedAsync<string>( | ||
CREATE_BINANCE_CODE, | ||
HttpMethod.Post, | ||
query: new Dictionary<string, object> | ||
{ | ||
{ "token", token }, | ||
{ "amount", amount }, | ||
{ "recvWindow", recvWindow }, | ||
{ "timestamp", DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }, | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
private const string REDEEM_BINANCE_CODE = "/sapi/v1/giftcard/redeemCode"; | ||
|
||
/// <summary> | ||
/// This API is for redeeming the Binance Code. Once redeemed, the coins will be deposited in your funding wallet.<para /> | ||
/// Please note that if you enter the wrong code 5 times within 24 hours, you will no longer be able to redeem any Binance Code that day.<para /> | ||
/// Weight(IP): 1. | ||
/// </summary> | ||
/// <param name="code">Binance code.</param> | ||
/// <param name="recvWindow">The value cannot be greater than 60000.</param> | ||
/// <returns>Binance Gift Card details.</returns> | ||
public async Task<string> RedeemBinanceCode(string code, long? recvWindow = null) | ||
{ | ||
var result = await this.SendSignedAsync<string>( | ||
REDEEM_BINANCE_CODE, | ||
HttpMethod.Post, | ||
query: new Dictionary<string, object> | ||
{ | ||
{ "code", code }, | ||
{ "recvWindow", recvWindow }, | ||
{ "timestamp", DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }, | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
private const string VERIFY_BINANCE_CODE = "/sapi/v1/giftcard/verify"; | ||
|
||
/// <summary> | ||
/// This API is for verifying whether the Binance Code is valid or not by entering Binance Code or reference number.<para /> | ||
/// Please note that if you enter the wrong binance code 5 times within an hour, you will no longer be able to verify any binance code for that hour.<para /> | ||
/// Weight(IP): 1. | ||
/// </summary> | ||
/// <param name="referenceNo">reference number.</param> | ||
/// <param name="recvWindow">The value cannot be greater than 60000.</param> | ||
/// <returns>Binance Gift Card details.</returns> | ||
public async Task<string> VerifyBinanceCode(string referenceNo, long? recvWindow = null) | ||
{ | ||
var result = await this.SendSignedAsync<string>( | ||
VERIFY_BINANCE_CODE, | ||
HttpMethod.Get, | ||
query: new Dictionary<string, object> | ||
{ | ||
{ "referenceNo", referenceNo }, | ||
{ "recvWindow", recvWindow }, | ||
{ "timestamp", DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }, | ||
}); | ||
|
||
return result; | ||
} | ||
} | ||
} |
Oops, something went wrong.