public void GetMyOrders_Should_RespondWithUserOrdersArray() { // arrange var orders = new SwitcheoOrder[] { new SwitcheoOrder() { Id = new Guid("c415f943-bea8-4dbf-82e3-8460c559d8b7"), Blockchain = BlockchainType.Neo, ContractHash = SampleContractHash, Address = SampleAddress, Side = OrderSide.Buy, OfferAsset = SampleTokensList[0], WantAsset = SampleTokensList[1], OfferAmount = SwitcheoHelpers.FromAssetAmount("100000000", SampleTokensList[0].Precision), WantAmount = SwitcheoHelpers.FromAssetAmount("20000000", SampleTokensList[1].Precision), UseNativeToken = true, DepositTransaction = null, CreatedAt = DateTime.Now, Status = OrderStatus.Processed, Fills = new SwitcheoFill[0], Makes = new SwitcheoMake[0] } }; var client = PrepareClient(JsonConvert.SerializeObject(orders), true); // act var result = client.GetMyOrders(); // assert Assert.AreEqual(true, result.Success); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(orders[0], result.Data[0], "Fills", "Makes")); }
public void GetTrades_Should_RespondWithTradesArray() { // arrange var trades = new[] { new SwitcheoTrade() { Id = new Guid("712a5019-3a23-463e-b0e1-80e9f0ad4f91"), RawFillAmount = SwitcheoHelpers.FromAssetAmount("9122032316", SampleTokensList[2].Precision).ToString(), RawTakeAmount = SwitcheoHelpers.FromAssetAmount("20921746", SampleTokensList[0].Precision).ToString(), EventTime = DateTime.Now, IsBuy = false }, new SwitcheoTrade() { Id = new Guid("5d7e42a2-a8f3-40a9-bce5-7304921ff691"), RawFillAmount = SwitcheoHelpers.FromAssetAmount("280477933", SampleTokensList[0].Precision).ToString(), RawTakeAmount = SwitcheoHelpers.FromAssetAmount("4207169", SampleTokensList[2].Precision).ToString(), EventTime = DateTime.Now.AddMinutes(1), IsBuy = true } }; var client = PrepareClient(JsonConvert.SerializeObject(trades)); // act var result = client.GetTrades("SWTH_NEO"); // assert Assert.AreEqual(true, result.Success); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(trades[0], result.Data[0])); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(trades[1], result.Data[1])); }
public void GetOffers_Should_RespondWithOffersArray() { // arrange var offers = new[] { new SwitcheoOffer() { Id = new Guid("b3a91e19-3726-4d09-8488-7c22eca76fc0"), OfferAsset = SampleTokensList[2], WantAsset = SampleTokensList[0], AvailableAmount = SwitcheoHelpers.FromAssetAmount("2550000013", SampleTokensList[2].Precision), OfferAmount = SwitcheoHelpers.FromAssetAmount("4000000000", SampleTokensList[2].Precision), WantAmount = SwitcheoHelpers.FromAssetAmount("320000000", SampleTokensList[0].Precision) } }; var client = PrepareClient(JsonConvert.SerializeObject(offers)); // act var result = client.GetOffers(BlockchainType.Neo, "SWTH_NEO"); // assert Assert.AreEqual(true, result.Success); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(offers[0], result.Data[0])); }
public void FromAssetAmount_Should_ConvertFromAssetAmount() { string amount1 = "2200000000.0"; string amount2 = "4740000000"; string amount3 = "5467806450000"; string amount4 = "68"; string amount5 = "127154870000000000000"; string negativeAmount1 = "-1100000000"; var fromAssetAmount1 = SwitcheoHelpers.FromAssetAmount(amount1, SwitcheoClientTests.SampleTokensList[0].Precision); var fromAssetAmount2 = SwitcheoHelpers.FromAssetAmount(amount2, SwitcheoClientTests.SampleTokensList[0].Precision); var fromAssetAmount3 = SwitcheoHelpers.FromAssetAmount(amount3, SwitcheoClientTests.SampleTokensList[0].Precision); var fromAssetAmount4 = SwitcheoHelpers.FromAssetAmount(amount4, SwitcheoClientTests.SampleTokensList[3].Precision); var fromAssetAmount5 = SwitcheoHelpers.FromAssetAmount(amount5, SwitcheoClientTests.SampleTokensList[4].Precision); var fromNegativeNeoAssetAmount1 = SwitcheoHelpers.FromAssetAmount(negativeAmount1, SwitcheoClientTests.SampleTokensList[0].Precision); Assert.AreEqual(22, fromAssetAmount1); Assert.AreEqual(47.4m, fromAssetAmount2); Assert.AreEqual(54678.0645m, fromAssetAmount3); Assert.AreEqual(68, fromAssetAmount4); Assert.AreEqual(127.15487m, fromAssetAmount5); Assert.AreEqual(-11, fromNegativeNeoAssetAmount1); }
public void CreateOrder_Should_RespondWithOrder() { // arrange var expected = new SwitcheoOrder() { Id = new Guid("cfd3805c-50e1-4786-a81f-a60ffba33434"), Blockchain = BlockchainType.Neo, ContractHash = SampleContractHash, Address = SampleAddress, Side = OrderSide.Buy, OfferAsset = SampleTokensList[0], WantAsset = SampleTokensList[2], OfferAmount = SwitcheoHelpers.FromAssetAmount("2050000", SampleTokensList[0].Precision), WantAmount = SwitcheoHelpers.FromAssetAmount("2050000000", SampleTokensList[2].Precision), UseNativeToken = true, DepositTransaction = null, CreatedAt = DateTime.Now, Status = OrderStatus.Pending, Fills = new SwitcheoFill[] { new SwitcheoFill() { Id = new Guid("2eaa3621-0e7e-4b3d-9c8c-454427f20949"), OfferHash = "bb70a40e8465596bf63dbddf9862a009246e3ca27a4cf5140d70f01bdd107277", OfferAsset = SampleTokensList[0], WantAsset = SampleTokensList[2], FillAmount = SwitcheoHelpers.FromAssetAmount("1031498", SampleTokensList[0].Precision), WantAmount = SwitcheoHelpers.FromAssetAmount("2050000000", SampleTokensList[2].Precision), FilledAmount = 0, FeeAsset = SampleTokensList[2], Price = 0.00050317m, Transaction = null, Status = FillStatus.Pending, CreatedAt = DateTime.Now, TransactionHash = "97ad8c0af68d22304e7f2d09d04f3beed29a845fe57de53444fff1507b752b99" } } }; var client = PrepareClient(JsonConvert.SerializeObject(expected), true); // act var result = client.CreateOrder("SWTH_NEO", BlockchainType.Neo, OrderSide.Buy, 0.00100000m, SwitcheoHelpers.FromAssetAmount("2050000000", SampleTokensList[0].Precision), true, OrderType.Limit); // assert Assert.AreEqual(true, result.Success); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(expected, result.Data, "Fills", "Makes")); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(expected.Fills[0], result.Data.Fills[0])); }
public void GetMyContractBalances_Should_RespondWithUserContractBalancesArray() { // arrange var balances = new SwitcheoBalancesList() { Confirming = new SwitcheoAssetConfirming[] { new SwitcheoAssetConfirming() { Asset = SampleTokensList[1], Events = new SwitcheoAssetConfirming.SwitcheoConfirmingEvent[] { new SwitcheoAssetConfirming.SwitcheoConfirmingEvent() { Type = EventType.Withdrawal, Asset = SampleTokensList[1], Amount = SwitcheoHelpers.FromAssetAmount("-100000000", SampleTokensList[1].Precision), TransactionHash = null, CreatedAt = DateTime.Now } } } }, Confirmed = new SwitcheoAssetBalance[] { new SwitcheoAssetBalance() { Asset = SampleTokensList[1], Amount = SwitcheoHelpers.FromAssetAmount("47320000000", SampleTokensList[1].Precision) }, new SwitcheoAssetBalance() { Asset = SampleTokensList[2], Amount = SwitcheoHelpers.FromAssetAmount("421549852102", SampleTokensList[2].Precision) }, new SwitcheoAssetBalance() { Asset = SampleTokensList[0], Amount = SwitcheoHelpers.FromAssetAmount("50269113921", SampleTokensList[0].Precision) } }, Locked = new SwitcheoAssetBalance[] { new SwitcheoAssetBalance() { Asset = SampleTokensList[1], Amount = SwitcheoHelpers.FromAssetAmount("500000000", SampleTokensList[1].Precision) }, new SwitcheoAssetBalance() { Asset = SampleTokensList[0], Amount = SwitcheoHelpers.FromAssetAmount("1564605000", SampleTokensList[0].Precision) } } }; var client = PrepareClient(JsonConvert.SerializeObject(balances), true); // act var result = client.GetMyContractBalances(); // assert Assert.AreEqual(true, result.Success); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(balances.Confirming[0].Asset, result.Data.Confirming[0].Asset)); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(balances.Confirming[0].Events[0], result.Data.Confirming[0].Events[0])); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(balances.Confirmed[0], result.Data.Confirmed[0])); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(balances.Confirmed[1], result.Data.Confirmed[1])); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(balances.Confirmed[2], result.Data.Confirmed[2])); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(balances.Locked[0], result.Data.Locked[0])); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(balances.Locked[1], result.Data.Locked[1])); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { SwitcheoBalancesList balancesList = new SwitcheoBalancesList(); var client = (SwitcheoClient)serializer.Context.Context; if (reader.TokenType == JsonToken.StartObject) { JObject rootObject = JObject.Load(reader); if (rootObject.ContainsKey(BalanceType.Confirming.ToString().ToLower())) { JToken confirmingBalances = rootObject.GetValue(BalanceType.Confirming.ToString().ToLower()); balancesList.Confirming = new SwitcheoAssetConfirming[confirmingBalances.Children().Count()]; int tabIndex = 0; foreach (JProperty assetConfirming in confirmingBalances.Children()) { SwitcheoAssetConfirming _assetConfirming = new SwitcheoAssetConfirming() { Asset = client.GetToken(assetConfirming.Name), }; List <SwitcheoConfirmingEvent> events = new List <SwitcheoConfirmingEvent>(); foreach (JObject confirmingEvent in (JArray)assetConfirming.Value) { var switcheoConfirmingEvent = JsonConvert.DeserializeObject <SwitcheoConfirmingEvent>(confirmingEvent.ToString(), new JsonSerializerSettings() { Context = new StreamingContext(StreamingContextStates.Other, client) }); events.Add(switcheoConfirmingEvent); } _assetConfirming.Events = events.ToArray(); balancesList.Confirming[tabIndex] = _assetConfirming; tabIndex++; } } if (rootObject.ContainsKey(BalanceType.Confirmed.ToString().ToLower())) { JToken confirmedBalances = rootObject.GetValue(BalanceType.Confirmed.ToString().ToLower()); balancesList.Confirmed = new SwitcheoAssetBalance[confirmedBalances.Children().Count()]; int tabIndex = 0; foreach (JProperty assetBalance in confirmedBalances.Children()) { var asset = client.GetToken(assetBalance.Name); balancesList.Confirmed[tabIndex] = new SwitcheoAssetBalance() { Asset = asset, Amount = SwitcheoHelpers.FromAssetAmount(assetBalance.Value.ToString(), asset.Precision) }; tabIndex++; } } if (rootObject.ContainsKey(BalanceType.Locked.ToString().ToLower())) { JToken lockedBalances = rootObject.GetValue(BalanceType.Locked.ToString().ToLower()); balancesList.Locked = new SwitcheoAssetBalance[lockedBalances.Children().Count()]; int tabIndex = 0; foreach (JProperty assetBalance in lockedBalances.Children()) { var asset = client.GetToken(assetBalance.Name); balancesList.Locked[tabIndex] = new SwitcheoAssetBalance() { Asset = asset, Amount = SwitcheoHelpers.FromAssetAmount(assetBalance.Value.ToString(), asset.Precision) }; tabIndex++; } } } return(balancesList); }