-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTicker.Basic.cs
More file actions
46 lines (34 loc) · 2.17 KB
/
Copy pathTicker.Basic.cs
File metadata and controls
46 lines (34 loc) · 2.17 KB
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
using System;
using System.Threading;
using System.Threading.Tasks;
using WhalesSecret.TradeScriptLib.API.TradingV1;
using WhalesSecret.TradeScriptLib.API.TradingV1.MarketData;
using WhalesSecret.TradeScriptLib.Entities;
using WhalesSecret.TradeScriptLib.Entities.MarketData;
namespace WhalesSecret.ScriptApiLib.Samples.BasicSamples.Subscriptions;
/// <summary>
/// Basic sample that demonstrates how a ticker subscription can be created and consumed.
/// </summary>
public class TickerBasic : IScriptApiSample
{
/// <inheritdoc/>
public async Task RunSampleAsync(ExchangeMarket exchangeMarket)
{
using CancellationTokenSource timeoutCts = new(TimeSpan.FromMinutes(2));
await using ScriptApi scriptApi = await ScriptApi.CreateAsync(timeoutCts.Token).ConfigureAwait(false);
Console.WriteLine($"Connect to {exchangeMarket} exchange with a public connection.");
ConnectionOptions connectionOptions = new(connectionType: ConnectionType.MarketData);
await using ITradeApiClient tradeClient = await scriptApi.ConnectAsync(exchangeMarket, connectionOptions).ConfigureAwait(false);
Console.WriteLine($"Public connection to {exchangeMarket} has been established successfully.");
SymbolPair symbolPair = SymbolPair.BTC_USDT;
Console.WriteLine($"Create subscription for '{symbolPair}' ticker on {exchangeMarket}.");
await using ITickerSubscription subscription = await tradeClient.CreateTickerSubscriptionAsync(symbolPair).ConfigureAwait(false);
Console.WriteLine($"Ticker subscription for '{symbolPair}' on {exchangeMarket} has been created successfully as '{subscription}'.");
Console.WriteLine($"Wait for next 2 ticker updates for {symbolPair}.");
Ticker ticker = await subscription.GetNewerTickerAsync(timeoutCts.Token).ConfigureAwait(false);
Console.WriteLine($"First ticker update '{ticker}' has been received.");
Ticker ticker2 = await subscription.GetNewerTickerAsync(timeoutCts.Token).ConfigureAwait(false);
Console.WriteLine($"Second ticker update '{ticker2}' has been received.");
Console.WriteLine("Disposing ticker subscription, trade API client, and script API.");
}
}