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.04k stars 428 forks source link

Isolated Margin #850

Closed jurgenBE closed 2 years ago

jurgenBE commented 3 years ago

Hey,

Let's say this example WTCUSDT => this is 'isolated' margin x3

  1. I want to see how much USDT i have on the isolated margin account
  2. If not enough, transfer from spot account for example 1000 USDT to this isolated account
  3. place 'borrow' sell WTC order (1000 coins WTC) => I get for example 1200 USDT
  4. at a later time buy on the spot account 1000 WTC coins and then repay the 'isolated' loan...

How would someone do that with your binance.net program ?? Many thanx,

eduardobellotto commented 2 years ago

Hi jurgenBE.

I would do something like the code bellow.

The additional value in the repay order is for interest payment.

Best regards.

// Get all isolated margin account balances
var balanceResult = client.SpotApi.Account.GetIsolatedMarginAccountAsync().Result;

// Select balances of a specific symbol
var assetBalance = balanceResult.Data.Assets.First(x => x.Symbol == "WTCUSDT");

// Get quote (USDT) free balance for that symbol
var usdtBalance = assetBalance.QuoteAsset.Free;

// Check if it is greater than some value. If not, transfer the missing value.
if (usdtBalance < 100M)
{
    var amount = 100M - usdtBalance;
    var transferResult = client.SpotApi.Account.IsolatedMarginAccountTransferAsync("USDT", "WTCUSDT", IsolatedMarginTransferDirection.Spot, IsolatedMarginTransferDirection.IsolatedMargin, amount).Result;
}

// Open a short position
var sellResult = client.SpotApi.Trading.PlaceMarginOrderAsync("WTCUSDT", OrderSide.Sell, SpotOrderType.Market, null, 100M, null, null, null, null, null, SideEffectType.MarginBuy, true);

// At a later time, close the short position and repay the borrow value and the interest
var buyResult = client.SpotApi.Trading.PlaceMarginOrderAsync("WTCUSDT", OrderSide.Buy, SpotOrderType.Market, null, 101M, null, null, null, null, null, SideEffectType.AutoRepay, true);
jurgenBE commented 2 years ago

Hi Eduardo,

I am not doing anything anymore with binance.net. I am doing web3/solidity now. Are you experienced in these languages too? Can you send me a PM at @.**@.> if you are?

Verzonden vanuit Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 voor Windows

Van: @.> Verzonden: 29 May 2022 02:42 Aan: @.> CC: @.>; @.> Onderwerp: Re: [JKorf/Binance.Net] Isolated Margin (#850)

Hi jurgenBE.

I would do something like the code bellow.

The additional value in the repay order is for interest payment.

Best regards.

// Get all isolated margin account balances

var balanceResult = client.SpotApi.Account.GetIsolatedMarginAccountAsync().Result;

// Select balances of a specific symbol

var assetBalance = balanceResult.Data.Assets.First(x => x.Symbol == "WTCUSDT");

// Get quote (USDT) free balance for that symbol

var usdtBalance = assetBalance.QuoteAsset.Free;

// Check if it is greater than some value. If not, transfer the missing value.

if (usdtBalance < 100M)

{

var amount = 100M - usdtBalance;

var transferResult = client.SpotApi.Account.IsolatedMarginAccountTransferAsync("USDT", "WTCUSDT", IsolatedMarginTransferDirection.Spot, IsolatedMarginTransferDirection.IsolatedMargin, amount).Result;

}

// Open a short position

var sellResult = client.SpotApi.Trading.PlaceMarginOrderAsync("WTCUSDT", OrderSide.Sell, SpotOrderType.Market, null, 100M, null, null, null, null, null, SideEffectType.MarginBuy, true);

// At a later time, close the short position and repay the borrow value and the interest

var buyResult = client.SpotApi.Trading.PlaceMarginOrderAsync("WTCUSDT", OrderSide.Buy, SpotOrderType.Market, null, 101M, null, null, null, null, null, SideEffectType.AutoRepay, true);

— Reply to this email directly, view it on GitHubhttps://github.com/JKorf/Binance.Net/issues/850#issuecomment-1140350642, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACOZWZ76FONTJSMISSV344DVMK4OHANCNFSM5DF4BNQA. You are receiving this because you authored the thread.Message ID: @.***>

eduardobellotto commented 2 years ago

Hi jurgenBE.

I just know a little bit of C#.

Best regards.