public async Task<TradebookResponse> GetTradebook(TradebookRequest request)
		{
			var response = new TradebookResponse ();
			var client = this.ApiClient ();

			client.QueryString.Add ("currencypair", request.ExchangeMarketRef);
			string rawData = await client.DownloadStringTaskAsync (this.TradebookApiUri);
			var jsonData = JToken.Parse (rawData);

			response.AddRange (
				from rawTrade in jsonData["trades"]
				select new Trade () {
					ExchangeMarketCD = request.ExchangeMarketCD,
					TradeRef = rawTrade ["id"].Value<string> (),
					Price = Decimal.Parse (rawTrade ["price"].Value<string> ()),
					Amount = Decimal.Parse (rawTrade ["amount"].Value<string> ()),
					RawData = Encoding.ASCII.GetBytes (rawTrade.ToString ()),
					ReportedTime = Utilities.GetDateTimeFromUnixTimestamp (rawTrade ["date"].Value<long> ()),
					LastSeen = DateTimeOffset.UtcNow
				}
			);

			return response;
		}
Beispiel #2
0
		public async Task<TradebookResponse> GetTradebook(TradebookRequest request)
		{
			var response = new TradebookResponse ();
			var client = this.ApiClient ();
			var endpointUri = new Uri (
				this.TradebookApiUri, 
				this.TradebookApiUri.AbsolutePath.Replace("$$", request.ExchangeMarketRef)
			);
			string signature = this.GenerateRequestSignature(
				request.ApiSecret,
				endpointUri.AbsolutePath,
				client.QueryString
			);

			client.Headers.Add ("Rest-Key", request.ApiToken);
			client.Headers.Add ("Rest-Sign", signature);

			string rawData = await client.DownloadStringTaskAsync (endpointUri);
			var jsonData = JToken.Parse (rawData);

			response.AddRange (
				from rawTrade in jsonData["data"]
				select new Trade () {
					ExchangeMarketCD = request.ExchangeMarketCD,
					TradeRef = rawTrade ["tid"].Value<string> (),
					Price = Decimal.Parse (rawTrade ["price"].Value<string> ()),
					Amount = Decimal.Parse (rawTrade ["amount"].Value<string> ()),
					SettlementCurrencyCD = rawTrade["primary"] != null ? rawTrade["price_currency"].Value<string>() : null,
					RawData = Encoding.ASCII.GetBytes (rawTrade.ToString ()),
					ReportedTime = Utilities.GetDateTimeFromUnixTimestamp (rawTrade ["tid"].Value<long> () / 1000),
					LastSeen = DateTimeOffset.UtcNow
				}
			);

			return response;
		}