This repository was archived by the owner on Oct 30, 2023. It is now read-only.
forked from joaopsilva/binance-java-api
-
Notifications
You must be signed in to change notification settings - Fork 599
Expand file tree
/
Copy pathMarginAccountEndpointsExample.java
More file actions
executable file
·42 lines (35 loc) · 1.72 KB
/
MarginAccountEndpointsExample.java
File metadata and controls
executable file
·42 lines (35 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.binance.api.examples;
import com.binance.api.client.BinanceApiClientFactory;
import com.binance.api.client.BinanceApiMarginRestClient;
import com.binance.api.client.domain.TransferType;
import com.binance.api.client.domain.account.MarginAccount;
import com.binance.api.client.domain.account.MarginTransaction;
import com.binance.api.client.domain.account.Trade;
import com.binance.api.examples.constants.PrivateConfig;
import java.util.List;
/**
* Examples on how to get margin account information.
*/
public class MarginAccountEndpointsExample {
public static void main(String[] args) {
BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY);
BinanceApiMarginRestClient client = factory.newMarginRestClient();
// Get account balances
MarginAccount marginAccount = client.getAccount();
System.out.println(marginAccount.getUserAssets());
System.out.println(marginAccount.getAssetBalance("ETH"));
System.out.println(marginAccount.getMarginLevel());
// Get list of trades
List<Trade> myTrades = client.getMyTrades("NEOETH");
System.out.println(myTrades);
// Transfer, borrow, repay
MarginTransaction spotToMargin = client.transfer("USDT", "1", TransferType.SPOT_TO_MARGIN);
System.out.println(spotToMargin.getTranId());
MarginTransaction borrowed = client.borrow("USDT", "1");
System.out.println(borrowed.getTranId());
MarginTransaction repayed = client.repay("USDT", "1");
System.out.println(repayed.getTranId());
MarginTransaction marginToSpot = client.transfer("USDT", "1", TransferType.MARGIN_TO_SPOT);
System.out.println(marginToSpot.getTranId());
}
}