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

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

			response.AddRange (
				from rawTrade in jsonData["result"][request.ExchangeMarketRef]
				select new Trade () {
					ExchangeMarketCD = request.ExchangeMarketCD,
					Price = Decimal.Parse (rawTrade[0].Value<string> ()),
					Amount = Decimal.Parse (rawTrade[1].Value<string> ()),
					RawData = Encoding.ASCII.GetBytes (rawTrade.ToString ()),
					ReportedTime = Utilities.GetDateTimeFromUnixTimestamp (rawTrade[2].Value<long> ()),
					LastSeen = DateTimeOffset.UtcNow
				}
			);

			return response;
		}
Esempio n. 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;
		}