JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.02k stars 420 forks source link

UsdFuturesApi.Trading.GetOpenOrdersAsync cant get openorders #1311

Closed basarkavas closed 6 months ago

basarkavas commented 8 months ago

Hi, I am using new restclient like below code, but cant return open orders. public Binance.Net.Clients.BinanceRestClient client; //create client here with options client = new BinanceRestClient(); BinanceRestClient.SetDefaultOptions(options => { options.ApiCredentials = new ApiCredentials(apiKey, secretKey); // <- Provide you API key/secret in these fields to retrieve data related to your account
if (ENVIRONMENT.Contains("TEST")) { options.Environment = BinanceEnvironment.Testnet; } else if (ENVIRONMENT.Contains("PROD")) { options.Environment = BinanceEnvironment.Live; }

}); //important part here !! var resultGetPositionInformationAsync = await client.UsdFuturesApi.Trading.GetOpenOrdersAsync(symbol);

//cant get result from this code, everything works then this part, i can get limit orders but i cant get openorders??

thx for help

JKorf commented 8 months ago

You're setting the default options after the client has already been created. Either set the default options before that or specify them for the specific client:

BinanceRestClient.SetDefaultOptions(options =>{
  // Set options
});
var client = new BinanceRestClient();

// OR

var client = new BinanceRestClient(options => {
  // Set options
});
basarkavas commented 8 months ago

hi jkorf,

i have set options right, i can call all other functions, just there is a problem with this function, i cant get open order(current open position) from this function, it can get just limit orders. thnks in advance.

JKorf commented 8 months ago

What is the value of resultGetPositionInformationAsync.Error?

basarkavas commented 8 months ago

there is no data in data property, but i have open position, but it is not limit position, just real open position, pls try for your account, call this function and you cant see your current open position from your function call result. thnkx

JKorf commented 8 months ago

I didn't ask for the data property though. If you call var resultGetPositionInformationAsync = await client.UsdFuturesApi.Trading.GetOpenOrdersAsync(symbol); then either resultGetPositionInformationAsync.Data or resultGetPositionInformationAsync.Error will be filled.

I'm not currently able to try the call

alaky2 commented 8 months ago

Hi basarkavas, I think you want open "Positions" not "Orders". You need to use UsdFuturesApi.Account.GetPositionInformationAsync(Symbol). The UsdFuturesApi.Account.GetAccountInfoAsync also has a "Positions" property in response but it returns available coins (about 300). The UsdFuturesApi.Trading.GetOpenOrdersAsync(symbol) gives only open Orders not positions.

basarkavas commented 8 months ago

Thanks, I'll check it out.

On Tue, Oct 24, 2023 at 11:51 AM alaky2 @.***> wrote:

Hi basarkavas, I think you want open "Positions" not "Orders". You need to use UsdFuturesApi.Account.GetPositionInformationAsync(Symbol). The UsdFuturesApi.Account.GetAccountInfoAsync also has a "Positions" property in response but it returns available coins (about 300). The UsdFuturesApi.Trading.GetOpenOrdersAsync(symbol) gives only open Orders not positions.

— Reply to this email directly, view it on GitHub https://github.com/JKorf/Binance.Net/issues/1311#issuecomment-1776791871, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPEQHAXUCX3QW5PTV3KU5TYA56SLAVCNFSM6AAAAAA6NDQ6F6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZWG44TCOBXGE . You are receiving this because you authored the thread.Message ID: @.***>

basarkavas commented 8 months ago

yeah, ı have already tried this, but for the old version, getopernorders return also open positions, now i have to change to code like you said. thx

Steffx115 commented 3 weeks ago

You need to set UsdFuturesOptions.ApiCredentials separated from the standard ones

EDIT: for me its this: services.AddSingleton(new BinanceRestClient(opt => { opt.ApiCredentials = new ApiCredentials(apiKey, apiSecret); opt.UsdFuturesOptions.ApiCredentials = new ApiCredentials(apiKey, apiSecret); opt.Environment = BinanceEnvironment.Live; }));