Пример #1
0
        public void ToAssetAmount_Should_ConvertToAssetAmount()
        {
            decimal amount1 = 22;
            decimal amount2 = 47.4m;
            decimal amount3 = 54678.0645m;
            decimal amount4 = 68;
            decimal amount5 = 127.15487m;

            decimal negativeAmount1 = -11;

            var toAssetAmount1 = SwitcheoHelpers.ToAssetAmount(amount1, SwitcheoClientTests.SampleTokensList[0].Precision);
            var toAssetAmount2 = SwitcheoHelpers.ToAssetAmount(amount2, SwitcheoClientTests.SampleTokensList[0].Precision);
            var toAssetAmount3 = SwitcheoHelpers.ToAssetAmount(amount3, SwitcheoClientTests.SampleTokensList[0].Precision);
            var toAssetAmount4 = SwitcheoHelpers.ToAssetAmount(amount4, SwitcheoClientTests.SampleTokensList[3].Precision);
            var toAssetAmount5 = SwitcheoHelpers.ToAssetAmount(amount5, SwitcheoClientTests.SampleTokensList[4].Precision);

            var toNegativeNeoAssetAmount1 = SwitcheoHelpers.ToAssetAmount(negativeAmount1, SwitcheoClientTests.SampleTokensList[0].Precision);

            Assert.AreEqual("2200000000", toAssetAmount1);
            Assert.AreEqual("4740000000", toAssetAmount2);
            Assert.AreEqual("5467806450000", toAssetAmount3);
            Assert.AreEqual("68", toAssetAmount4);
            Assert.AreEqual("127154870000000000000", toAssetAmount5);


            Assert.AreEqual("-1100000000", toNegativeNeoAssetAmount1);
        }
Пример #2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();

            SwitcheoBalancesList balancesList = (SwitcheoBalancesList)value;

            writer.WritePropertyName(BalanceType.Confirming.ToString().ToLower());
            writer.WriteStartObject();
            foreach (SwitcheoAssetConfirming assetBalance in balancesList.Confirming)
            {
                writer.WritePropertyName(assetBalance.Asset.Symbol);
                writer.WriteStartArray();
                foreach (SwitcheoAssetConfirming.SwitcheoConfirmingEvent confirmingEvent in assetBalance.Events)
                {
                    writer.WriteStartObject();

                    writer.WritePropertyName("event_type");
                    writer.WriteValue(confirmingEvent.Type.ToString().ToLower());
                    writer.WritePropertyName("asset_id");
                    writer.WriteValue(confirmingEvent.Asset.Id);
                    writer.WritePropertyName("amount");
                    writer.WriteValue(SwitcheoHelpers.ToAssetAmount(confirmingEvent.Amount, confirmingEvent.Asset?.Precision));
                    writer.WritePropertyName("transaction_hash");
                    writer.WriteValue(confirmingEvent.TransactionHash);
                    writer.WritePropertyName("created_at");
                    writer.WriteValue(confirmingEvent.CreatedAt);

                    writer.WriteEndObject();
                }
                writer.WriteEndArray();
            }
            writer.WriteEndObject();

            writer.WritePropertyName(BalanceType.Confirmed.ToString().ToLower());
            writer.WriteStartObject();
            foreach (SwitcheoAssetBalance assetBalance in balancesList.Confirmed)
            {
                writer.WritePropertyName(assetBalance.Asset.Symbol);
                writer.WriteValue(SwitcheoHelpers.ToAssetAmount(assetBalance.Amount, assetBalance.Asset?.Precision));
            }
            writer.WriteEndObject();

            writer.WritePropertyName(BalanceType.Locked.ToString().ToLower());
            writer.WriteStartObject();
            foreach (SwitcheoAssetBalance assetBalance in balancesList.Locked)
            {
                writer.WritePropertyName(assetBalance.Asset.Symbol);
                writer.WriteValue(SwitcheoHelpers.ToAssetAmount(assetBalance.Amount, assetBalance.Asset?.Precision));
            }
            writer.WriteEndObject();

            writer.WriteEndObject();
        }