public void PlaceOrderExpected() { IDeserializer deserializer = null; var restMock = new Mock <IRestClient>(MockBehavior.Strict); restMock.SetupAllProperties(); restMock.Setup(x => x.AddHandler("application/json", It.IsAny <IDeserializer>())).Callback <string, IDeserializer>((ct, d) => deserializer = d); restMock.Setup(x => x.Execute <ResponseSingle <TradeOrder> >(It.IsAny <IRestRequest>())).Returns <IRestRequest>(request => { var responseMock = new Mock <IRestResponse <ResponseSingle <TradeOrder> > >(MockBehavior.Strict); responseMock.SetupAllProperties(); responseMock.Object.Content = Properties.Resources.PlaceOrderResponse; responseMock.Object.Request = request; responseMock.Object.Data = deserializer.Deserialize <ResponseSingle <TradeOrder> >(responseMock.Object); return(responseMock.Object); }); var client = new BitsoClient(restMock.Object, ServiceUrlMock, ApiKeyMock, ApiSecretMock); var instruction = new TradeInstruction(); instruction.Price = 1000; instruction.MajorCurrencyAmount = 1; instruction.OrderType = TradeOrderType.Limit; instruction.Side = MarketSide.Buy; instruction.BookName = "btc_mxn"; var res = client.PlaceOrder(instruction); Assert.IsNotNull(res); }
public void GetAccountInfoExpected() { IDeserializer deserializer = null; var restMock = new Mock <IRestClient>(MockBehavior.Strict); restMock.SetupAllProperties(); restMock.Setup(x => x.AddHandler("application/json", It.IsAny <IDeserializer>())).Callback <string, IDeserializer>((ct, d) => deserializer = d); restMock.Setup(x => x.Execute <ResponseSingle <AccountInfo> >(It.IsAny <IRestRequest>())).Returns <IRestRequest>(request => { var responseMock = new Mock <IRestResponse <ResponseSingle <AccountInfo> > >(MockBehavior.Strict); responseMock.SetupAllProperties(); responseMock.Object.Content = Properties.Resources.AccountStatusResponse; responseMock.Object.Request = request; responseMock.Object.Data = deserializer.Deserialize <ResponseSingle <AccountInfo> >(responseMock.Object); return(responseMock.Object); }); var client = new BitsoClient(restMock.Object, ServiceUrlMock, ApiKeyMock, ApiSecretMock); var res = client.GetAccountInfo(); Assert.IsNotNull(res); Assert.IsFalse(string.IsNullOrEmpty(res.ClientId)); Assert.AreNotEqual <decimal>(0M, res.DailyLimit); Assert.AreNotEqual <decimal>(0M, res.MonthlyLimit); Assert.AreNotEqual <decimal>(0M, res.DailyRemaining); Assert.IsFalse(string.IsNullOrEmpty(res.Email)); Assert.IsFalse(string.IsNullOrEmpty(res.FirstName)); Assert.IsFalse(string.IsNullOrEmpty(res.LastName)); Assert.AreNotEqual <AccountStatus>(AccountStatus.None, res.Status); }
public void GetAllLedgerEntriesExpected() { IDeserializer deserializer = null; var restMock = new Mock <IRestClient>(MockBehavior.Strict); restMock.SetupAllProperties(); restMock.Setup(x => x.AddHandler("application/json", It.IsAny <IDeserializer>())).Callback <string, IDeserializer>((ct, d) => deserializer = d); restMock.Setup(x => x.Execute <ResponseCollection <LedgerEntryBase> >(It.IsAny <IRestRequest>())).Returns <IRestRequest>(request => { var responseMock = new Mock <IRestResponse <ResponseCollection <LedgerEntryBase> > >(MockBehavior.Strict); responseMock.SetupAllProperties(); responseMock.Object.Content = Properties.Resources.LedgerResponse; responseMock.Object.Request = request; responseMock.Object.Data = deserializer.Deserialize <ResponseCollection <LedgerEntryBase> >(responseMock.Object); return(responseMock.Object); }); var client = new BitsoClient(restMock.Object, ServiceUrlMock, ApiKeyMock, ApiSecretMock); var res = client.GetAllLedgerEntries(); Assert.IsNotNull(res); Assert.AreNotEqual <int>(0, res.Count); Assert.AreNotEqual <int>(0, res[0].Balances.Count); Assert.AreNotEqual <TransactionType>(TransactionType.None, res[0].Kind); Assert.IsFalse(string.IsNullOrEmpty(res[0].Id)); Assert.IsFalse(string.IsNullOrEmpty(res[0].Balances[0].Currency)); res = client.GetAllLedgerEntries(string.Empty, SortDirection.Ascending, 7); Assert.IsNotNull(res); Assert.AreEqual <int>(7, res.Count); }
public void GetBitsoTransferFundingsExpected() { using (var client = new BitsoClient(this.TestingServerUrl, this.ApiKey, this.ApiSecret)) { try { var res = client.GetBitsoTransferFundings(); Assert.IsNotNull(res); Assert.AreNotEqual <int>(0, res.Count); Assert.AreNotEqual <decimal>(0M, res[0].Amount); Assert.AreNotEqual <TransferStatus>(TransferStatus.None, res[0].Status); Assert.AreNotEqual <TransferMethod>(TransferMethod.None, res[0].Method); Assert.IsFalse(string.IsNullOrEmpty(res[0].MethodName)); Assert.IsFalse(string.IsNullOrEmpty(res[0].Id)); Assert.IsFalse(string.IsNullOrEmpty(res[0].Currency)); Assert.IsFalse(string.IsNullOrEmpty(res[0].Details.Notes)); var diff = res[0].CreatedAt - default(System.DateTime); Assert.IsTrue(diff > System.TimeSpan.Zero); res = client.GetBitsoTransferFundings(1); Assert.IsNotNull(res); Assert.AreEqual <int>(1, res.Count); } catch (BitsoException ex) { this.TestContext.WriteLine(ex.Header); throw; } } }
public void GetAccountFeesExpected() { using (var client = new BitsoClient(this.TestingServerUrl, this.ApiKey, this.ApiSecret)) { try { var res = client.GetAccountFees(); Assert.IsNotNull(res); Assert.AreNotEqual <int>(0, res.TradeFees.Count); Assert.IsFalse(string.IsNullOrEmpty(res.TradeFees[0].BookName)); Assert.AreNotEqual <decimal>(0M, res.TradeFees[0].TakerPercent); Assert.AreNotEqual <decimal>(0M, res.TradeFees[0].TakerValue); Assert.AreNotEqual <decimal>(0M, res.TradeFees[0].MakerPercent); Assert.AreNotEqual <decimal>(0M, res.TradeFees[0].MakerValue); Assert.AreNotEqual <int>(0, res.WithdrawalFees.Count); Assert.AreNotEqual <decimal>(0M, res.WithdrawalFees.First().Value); } catch (BitsoException ex) { this.TestContext.WriteLine(ex.Header); throw; } } }
public void GetAllLedgerEntriesExpected() { using (var client = new BitsoClient(this.TestingServerUrl, this.ApiKey, this.ApiSecret)) { try { var res = client.GetAllLedgerEntries(); Assert.IsNotNull(res); Assert.AreNotEqual <int>(0, res.Count); Assert.AreNotEqual <int>(0, res[0].Balances.Count); Assert.AreNotEqual <TransactionType>(TransactionType.None, res[0].Kind); Assert.IsFalse(string.IsNullOrEmpty(res[0].Id)); Assert.IsFalse(string.IsNullOrEmpty(res[0].Balances[0].Currency)); res = client.GetAllLedgerEntries(string.Empty, SortDirection.Ascending, 5); Assert.IsNotNull(res); Assert.AreEqual <int>(5, res.Count); } catch (BitsoException ex) { this.TestContext.WriteLine(ex.Header); throw; } } }
public void GetAccountInfoExpected() { using (var client = new BitsoClient(this.TestingServerUrl, this.ApiKey, this.ApiSecret)) { try { var res = client.GetAccountInfo(); Assert.IsNotNull(res); Assert.IsFalse(string.IsNullOrEmpty(res.ClientId)); Assert.AreNotEqual <decimal>(0M, res.DailyLimit); Assert.AreNotEqual <decimal>(0M, res.MonthlyLimit); Assert.AreNotEqual <decimal>(0M, res.DailyRemaining); Assert.IsFalse(string.IsNullOrEmpty(res.Email)); Assert.IsFalse(string.IsNullOrEmpty(res.FirstName)); Assert.IsFalse(string.IsNullOrEmpty(res.LastName)); Assert.AreNotEqual <AccountStatus>(AccountStatus.None, res.Status); } catch (BitsoException ex) { this.TestContext.WriteLine(ex.Header); throw; } } }
public void AvailableBooksExpected() { IDeserializer deserializer = null; var restMock = new Mock <IRestClient>(MockBehavior.Strict); restMock.SetupAllProperties(); restMock.Setup(x => x.AddHandler("application/json", It.IsAny <IDeserializer>())).Callback <string, IDeserializer>((ct, d) => deserializer = d); restMock.Setup(x => x.Execute <ResponseCollection <CurrencyPair> >(It.IsAny <IRestRequest>())).Returns <IRestRequest>(request => { var responseMock = new Mock <IRestResponse <ResponseCollection <CurrencyPair> > >(MockBehavior.Strict); responseMock.SetupAllProperties(); responseMock.Object.Content = Properties.Resources.AvailableBooksResponse; responseMock.Object.Request = request; responseMock.Object.Data = deserializer.Deserialize <ResponseCollection <CurrencyPair> >(responseMock.Object); return(responseMock.Object); }); var client = new BitsoClient(restMock.Object, ServiceUrlMock, ApiKeyMock, ApiSecretMock); var res = client.GetAvailablePairs(); Assert.AreNotEqual <int>(0, res.Count); Assert.IsFalse(string.IsNullOrWhiteSpace(res[0].BookName)); Assert.AreNotEqual <decimal>(0M, res[0].MaximumAmount); Assert.AreNotEqual <decimal>(0M, res[0].MaximumPrice); Assert.AreNotEqual <decimal>(0M, res[0].MaximumValue); Assert.AreNotEqual <decimal>(0M, res[0].MinimumAmount); Assert.AreNotEqual <decimal>(0M, res[0].MinimumPrice); Assert.AreNotEqual <decimal>(0M, res[0].MinimumValue); }
public void GetPortfolioExpected() { IDeserializer deserializer = null; var restMock = new Mock <IRestClient>(MockBehavior.Strict); restMock.SetupAllProperties(); restMock.Setup(x => x.AddHandler("application/json", It.IsAny <IDeserializer>())).Callback <string, IDeserializer>((ct, d) => deserializer = d); restMock.Setup(x => x.Execute <ResponseSingle <Portfolio> >(It.IsAny <IRestRequest>())).Returns <IRestRequest>(request => { var responseMock = new Mock <IRestResponse <ResponseSingle <Portfolio> > >(MockBehavior.Strict); responseMock.SetupAllProperties(); responseMock.Object.Content = Properties.Resources.PortfolioResponse; responseMock.Object.Request = request; responseMock.Object.Data = deserializer.Deserialize <ResponseSingle <Portfolio> >(responseMock.Object); return(responseMock.Object); }); var client = new BitsoClient(restMock.Object, ServiceUrlMock, ApiKeyMock, ApiSecretMock); var res = client.GetPortfolio(); Assert.IsNotNull(res); Assert.AreNotEqual <int>(0, res.Balances.Count); Assert.IsFalse(string.IsNullOrEmpty(res.Balances[0].Currency)); }
public void GetOrderBookExpected() { IDeserializer deserializer = null; var restMock = new Mock <IRestClient>(MockBehavior.Strict); restMock.SetupAllProperties(); restMock.Setup(x => x.AddHandler("application/json", It.IsAny <IDeserializer>())).Callback <string, IDeserializer>((ct, d) => deserializer = d); restMock.Setup(x => x.Execute <ResponseSingle <OrderBook> >(It.IsAny <IRestRequest>())).Returns <IRestRequest>(request => { var responseMock = new Mock <IRestResponse <ResponseSingle <OrderBook> > >(MockBehavior.Strict); responseMock.SetupAllProperties(); var aggregateParameter = request.Parameters.Find(x => x.Name == "aggregate"); bool aggregate = aggregateParameter != null ? (bool)aggregateParameter.Value : false; responseMock.Object.Content = aggregate ? Properties.Resources.OrderBookResponse1 : Properties.Resources.OrderBookResponse2; responseMock.Object.Request = request; responseMock.Object.Data = deserializer.Deserialize <ResponseSingle <OrderBook> >(responseMock.Object); return(responseMock.Object); }); var client = new BitsoClient(restMock.Object, ServiceUrlMock, ApiKeyMock, ApiSecretMock); var res = client.GetOrderBook("btc_mxn"); Assert.IsNotNull(res); Assert.AreNotEqual <int>(0, res.Asks.Count); Assert.AreNotEqual <int>(0, res.Bids.Count); Assert.AreNotEqual <long>(0, res.Sequence); var diff = res.UpdatedAt - default(System.DateTime); Assert.IsTrue(diff > System.TimeSpan.Zero); Assert.AreNotEqual <decimal>(0M, res.Asks[0].Amount); Assert.AreNotEqual <decimal>(0M, res.Asks[0].Price); Assert.IsFalse(string.IsNullOrEmpty(res.Asks[0].OrderId)); Assert.IsFalse(string.IsNullOrEmpty(res.Asks[0].BookName)); const bool AggregateResults = true; res = client.GetOrderBook("btc_mxn", AggregateResults); Assert.IsNotNull(res); Assert.AreNotEqual <int>(0, res.Asks.Count); Assert.AreNotEqual <int>(0, res.Bids.Count); Assert.AreNotEqual <long>(0, res.Sequence); diff = res.UpdatedAt - default(System.DateTime); Assert.IsTrue(diff > System.TimeSpan.Zero); Assert.AreNotEqual <decimal>(0M, res.Asks[0].Amount); Assert.AreNotEqual <decimal>(0M, res.Asks[0].Price); Assert.IsTrue(string.IsNullOrEmpty(res.Asks[0].OrderId)); Assert.IsFalse(string.IsNullOrEmpty(res.Asks[0].BookName)); }
public void GetAllTickersExpected() { var client = new BitsoClient(this.TestingServerUrl); var res = client.GetAllTickers(); Assert.AreNotEqual <int>(0, res.Count); }
//https://bitso.com/api_info#account-creation public NewAccountInfo CreateAccount(Dictionary <string, string> requiredFieldValues, string webhookUrl = null) { if (!string.IsNullOrEmpty(webhookUrl)) { requiredFieldValues.Add("webhook_url", webhookUrl); } var rawResponse = BitsoClient.SendRequest("accounts", "POST", true, BitsoUtils.BuildJson(requiredFieldValues)); return(JsonConvert.DeserializeObject <NewAccountInfo>(rawResponse)); }
public Funding GetFunding(string fid) { var rawResponse = BitsoClient.SendRequest($"fundings/{fid}", "GET"); var funding = JsonConvert.DeserializeObject <Funding[]>(rawResponse); if (funding != null && funding.Length > 0) { return(funding[0]); } return(null); }
//https://bitso.com/developers#phone-number-withdrawal public Withdrawal WithdrawToPhoneNumber(double amount, string recipientGivenNames, string recipientFamilyNames, string phoneNumber, string bankCode) { var rawResponse = BitsoClient.SendRequest($"phone_withdrawal", "POST", true, $"{{ \"amount\": \"{amount}\"," + $"\"recipient_given_names\": \"{recipientGivenNames}\"," + $"\"recipient_family_names\": \"{recipientFamilyNames}\"," + $"\"phone_number\": \"{phoneNumber}\"," + $"\"bank_code\": \"{bankCode}\"}}"); return(JsonConvert.DeserializeObject <Withdrawal>(rawResponse)); }
//https://bitso.com/developers#lookup-orders public OpenOrder LookupOrder(string oid) { var rawResponse = BitsoClient.SendRequest($"orders/{oid}", "GET"); var orders = JsonConvert.DeserializeObject <OpenOrder[]>(rawResponse); if (orders != null && orders.Length > 0) { return(orders[0]); } return(null); }
public UserTrade GetUserTrade(string tid) { var rawResponse = BitsoClient.SendRequest($"user_trades/{tid}", "GET"); var userTrades = JsonConvert.DeserializeObject <UserTrade[]>(rawResponse); if (userTrades != null && userTrades.Length > 0) { return(userTrades[0]); } return(null); }
public Withdrawal GetWithdrawal(string wid) { var rawResponse = BitsoClient.SendRequest($"withdrawals/{wid}", "GET"); var withdrawal = JsonConvert.DeserializeObject <Withdrawal[]>(rawResponse); if (withdrawal != null && withdrawal.Length > 0) { return(withdrawal[0]); } return(null); }
//https://bitso.com/developers#spei-withdrawal public Withdrawal WithdrawToSPEI(decimal amount, string recipientGivenNames, string recipientFamilyNames, string clabe, string notesRef, string numericRef) { var rawResponse = BitsoClient.SendRequest($"spei_withdrawal", "POST", true, $"{{\"amount\":\"{amount}\"," + $"\"recipient_given_names\":\"{recipientGivenNames}\"," + $"\"recipient_family_names\":\"{recipientFamilyNames}\"," + $"\"clabe\":\"{clabe}\"," + $"\"notes_ref\":\"{notesRef}\"," + $"\"numeric_ref\":\"{numericRef}\"}}"); return(JsonConvert.DeserializeObject <Withdrawal>(rawResponse)); }
//https://bitso.com/api_info#place-an-order public OpenOrder PlaceOrder(string book, string side, string type, decimal price, decimal?minorAmount = null, decimal?majorAmount = null) { var rawResponse = BitsoClient.SendRequest("orders", "POST", true, $"{{\"book\":\"{book}\"," + $"\"side\":\"{side}\"," + $"\"type\":\"{type}\"," + (minorAmount.HasValue ? $"\"minor\":\"{minorAmount.Value}\"," : "") + (majorAmount.HasValue ? $"\"major\":\"{majorAmount.Value}\"," : "") + $"\"price\":\"{price}\"}}"); return(JsonConvert.DeserializeObject <OpenOrder>(rawResponse)); }
public void AvailableBooksExpected() { var client = new BitsoClient(this.TestingServerUrl); var res = client.GetAvailablePairs(); Assert.AreNotEqual <int>(0, res.Count); Assert.IsFalse(string.IsNullOrWhiteSpace(res[0].BookName)); Assert.AreNotEqual <decimal>(0M, res[0].MaximumAmount); Assert.AreNotEqual <decimal>(0M, res[0].MaximumPrice); Assert.AreNotEqual <decimal>(0M, res[0].MaximumValue); Assert.AreNotEqual <decimal>(0M, res[0].MinimumAmount); Assert.AreNotEqual <decimal>(0M, res[0].MinimumPrice); Assert.AreNotEqual <decimal>(0M, res[0].MinimumValue); }
public string[] CancelOpenOrders(params string[] oids) { var oidsBuilder = new StringBuilder(); var index = 0; foreach (var oid in oids) { if (index > 0) { oidsBuilder.Append("-"); } oidsBuilder.Append(oid); index++; } var rawResponse = BitsoClient.SendRequest($"orders/{oidsBuilder.ToString()}", "DELETE"); return(JsonConvert.DeserializeObject <string[]>(rawResponse)); }
public UserTrade[] GetUserTrades(params string[] tids) { var tidsBuilder = new StringBuilder(); var index = 0; foreach (var tid in tids) { if (index > 0) { tidsBuilder.Append("-"); } tidsBuilder.Append(tid); index++; } var rawResponse = BitsoClient.SendRequest($"user_trades/{tidsBuilder.ToString()}", "GET"); return(JsonConvert.DeserializeObject <UserTrade[]>(rawResponse)); }
public Funding[] GetFundings(params string[] fids) { var fidsBuilder = new StringBuilder(); var index = 0; foreach (var fid in fids) { if (index > 0) { fidsBuilder.Append("-"); } fidsBuilder.Append(fid); index++; } var rawResponse = BitsoClient.SendRequest($"fundings/{fidsBuilder.ToString()}", "GET"); return(JsonConvert.DeserializeObject <Funding[]>(rawResponse)); }
public Withdrawal[] GetWithdrawals(params string[] wids) { var widsBuilder = new StringBuilder(); var index = 0; foreach (var wid in wids) { if (index > 0) { widsBuilder.Append("-"); } widsBuilder.Append(wid); index++; } var rawResponse = BitsoClient.SendRequest($"withdrawals/{widsBuilder.ToString()}", "GET"); return(JsonConvert.DeserializeObject <Withdrawal[]>(rawResponse)); }
public void GetBanksInfoExpected() { using (var client = new BitsoClient(this.TestingServerUrl, this.ApiKey, this.ApiSecret)) { try { var res = client.GetBanksInfo(); Assert.IsNotNull(res); Assert.AreNotEqual <int>(0, res.Count); Assert.IsFalse(string.IsNullOrEmpty(res[0].Name)); Assert.IsFalse(string.IsNullOrEmpty(res[0].Code)); } catch (BitsoException ex) { this.TestContext.WriteLine(ex.Header); throw; } } }
public void GetTradesExpected() { var client = new BitsoClient(this.TestingServerUrl); var res = client.GetTrades("btc_mxn"); Assert.AreNotEqual <int>(0, res.Count); Assert.AreNotEqual <decimal>(0, res[0].Amount); Assert.IsFalse(string.IsNullOrEmpty(res[0].BookName)); Assert.IsTrue(res[0].MakerSide != MarketSide.None); Assert.AreNotEqual <decimal>(0M, res[0].Price); Assert.AreNotEqual <decimal>(0M, res[0].Amount); Assert.AreNotEqual <long>(0, res[0].TradeId); var diff = res[0].CreatedAt - default(System.DateTime); Assert.IsTrue(diff > System.TimeSpan.Zero); }
public void GetOpenTradeOrdersExpected() { const string BookName = "btc_mxn"; using (var client = new BitsoClient(this.TestingServerUrl, this.ApiKey, this.ApiSecret)) { try { var res = client.GetOpenTradeOrders(BookName); Assert.IsNotNull(res); } catch (BitsoException ex) { this.TestContext.WriteLine(ex.Header); throw; } } }
public void GetFundingDestinationsExpected() { const string CurrencyName = "mxn"; using (var client = new BitsoClient(this.TestingServerUrl, this.ApiKey, this.ApiSecret)) { try { var res = client.GetFundingDestinations(CurrencyName); Assert.IsNotNull(res); Assert.IsFalse(string.IsNullOrEmpty(res.AccountIdentifierName)); Assert.IsFalse(string.IsNullOrEmpty(res.AccountIdentifier)); } catch (BitsoException ex) { this.TestContext.WriteLine(ex.Header); throw; } } }
public void GetLedgerFundingExpected() { using (var client = new BitsoClient(this.TestingServerUrl, this.ApiKey, this.ApiSecret)) { try { var res = client.GetLedgerFunding(); Assert.IsNotNull(res); Assert.AreNotEqual <int>(0, res.Count); res = client.GetLedgerFunding(string.Empty, SortDirection.Ascending, 5); Assert.IsNotNull(res); Assert.AreEqual <int>(5, res.Count); } catch (BitsoException ex) { this.TestContext.WriteLine(ex.Header); throw; } } }
public void GetTickerExpected1() { var client = new BitsoClient(this.TestingServerUrl); var res = client.GetTicker("btc_mxn"); Assert.IsNotNull(res); Assert.IsFalse(string.IsNullOrWhiteSpace(res.BookName)); Assert.AreNotEqual <decimal>(0M, res.Ask); Assert.AreNotEqual <decimal>(0M, res.Bid); Assert.AreNotEqual <decimal>(0M, res.VolumeWeightedAveragePrice); Assert.AreNotEqual <decimal>(0M, res.Low); Assert.AreNotEqual <decimal>(0M, res.High); Assert.AreNotEqual <decimal>(0M, res.Last); Assert.AreNotEqual <decimal>(0M, res.Volume); var diff = res.CreatedAt - default(System.DateTime); Assert.IsTrue(diff > System.TimeSpan.Zero); }