Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetAmountsAsync crashes program #723

Closed
clemenslinders opened this issue Jan 31, 2022 · 2 comments
Closed

GetAmountsAsync crashes program #723

clemenslinders opened this issue Jan 31, 2022 · 2 comments

Comments

@clemenslinders
Copy link

Hi,

I build a C# application using Exchange Sharp and that is working.

Now I want to build a second program that simply get's the amount I have on Poloniex.
It needs to be a seperate application.

I created a .Net 4.7.2 Console app (tried WinFroms .Net 4.7.2as well, Working application is: WinForms .net 4.7.2).
I used Nuget to add ExchangeSharp (Install-Package DigitalRuby.ExchangeSharp -Version 0.9.2)
I tried 4.9.1 as well, which is the version I used for my Winforms application.

The program terminates/crashes after it calls: var amounts = await api.Result.GetAmountsAsync();
Although it is in a try/catch loop, it doesn't even get to the catch, the program simply terminates.

Am I forgetting something?
What can be the problem.
Most of the code is copied and pasted from the working WinForms application.

I hope someone can help me.

Kind regards,

Clemens Linders

My code is very simple:

using CLL.Utils;
using ExchangeSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GetPoloniexCoinsFromExchange
{
/*
* Add Exchange Sharp to application: Install-Package DigitalRuby.ExchangeSharp -Version 0.9.2
*
*
*
*
*
*/

internal class Program
{
    static private string PoloniexApiKey = "Secret";
    static private string PoloniexApiPrivateKey = "Secret To";

    public partial class CoinNameQtyValue
    {
        public string CoinName { get; set; }
        public decimal Qty { get; set; }
    }

    private static async Task<ExchangePoloniexAPI> CreatePoloniexAPI(string response = null)
    {
        var api = (await ExchangeAPI.GetExchangeAPIAsync(ExchangeName.Poloniex) as ExchangePoloniexAPI);
        api.LoadAPIKeysUnsecure(PoloniexApiKey, PoloniexApiPrivateKey);//API keys opgeven
        return api;
    }

    static void Main(string[] args)
    {
        GetPoloniexPossessions();
        //System.Environment.Exit(0);
    }
    private async static void GetPoloniexPossessions()
    {
        try
        {
            PoloniexApiKey = Utils.DecryptString(PoloniexApiKey);
            PoloniexApiPrivateKey = Utils.DecryptString(PoloniexApiPrivateKey);
            List<CoinNameQtyValue> PoloniexCryptoCoinsInPossessionListExchange = new List<CoinNameQtyValue>();
            CoinNameQtyValue newPoloniexCoin = new CoinNameQtyValue();
            var api = CreatePoloniexAPI();
            var amounts = await api.Result.GetAmountsAsync();//Program terminates after this line

            for (int i = 0; i < amounts.Count; i++)
            {
                newPoloniexCoin = new CoinNameQtyValue();
                newPoloniexCoin.CoinName = amounts.ElementAt(i).Key;
                newPoloniexCoin.Qty = amounts.ElementAt(i).Value;

                PoloniexCryptoCoinsInPossessionListExchange.Add(newPoloniexCoin);
            }

            api.Dispose();
        }
        catch (Exception ex)
        {

            throw;
        }
    }
}

}

@jjxtra
Copy link
Collaborator

jjxtra commented Feb 2, 2022

var api = await CreatePoloniexAPI();

@jjxtra jjxtra closed this as completed Feb 2, 2022
@clemenslinders
Copy link
Author

Hi Jeff,

Thanks.

This solved another issue as well.

Kind regards,

Clemens Linders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants