First time API test user, tried to purchase 0.2 BTC, but only 0.178 was purchased

Hi,
I installed the test API and set it up. I am using Visual Studio 2019 and C# and the JKord/Binance.Net wrapper.

When I placed (as a test user, using a test account) an order to purchase 0.2 BTC TestBinance.Spot.Order.PlaceOrder(“BTCUSDT”, OrderSide.Sell, OrderType.Market, 0.2m)

The result was a success, but only 0.178721 was actually purchased.
It purchased these in 3 fills:
1- Price 38277,42 Quantity 0,168454
2- Price 37548,01 Quantity 0,000267
3- Price 30000 Quantity 0,01

After that there were no open orders.

Is this a correct behaviour like in real time?

I assume that after a sale or purchase, you need to check how much actually was sold or purchased?

In the third fill the price was against 30.000, but the 2nd was 37548. That is more than 20% difference within milliseconds?? (PS at that time the actual price for BTC was about 38K)

I also assume that this is due to the fact that I am using the test version of the API. Perhaps there were not enough people on the test website and that only one order was on the orderbook for 30.000.

In real life this than would not have happened.

Doing this test a couple of times I noticed that in not all cases coins were actually purchased or sold. However there also was no error (the sale or purchase was a success). Again I assume this is if there is perhaps nobody on that test website at that time?

Hope someone will give me an answer.

Kind regards,

Clemens Linders

Hello, separating this into two sections:

  1. I don’t recognise method TestBinance.Spot.Order.PlaceOrder, so can’t tell how the code it’s written there, however you can use endpoint /api/v3/myTrades to check submitted sell order with original details (https://binance-docs.github.io/apidocs/spot/en/#account-information-user_data).

  2. Yes, the Testnet doesn’t have as much liquidity as the production and other users can put very random prices.

Hi Aisling,

As mentioned I am using a wrapper for the Binance API (https://github.com/JKorf/Binance.Net).

This is my code:

using System;
using System.Windows.Forms;
using CLL.Utils;
using Binance.Net;
using CryptoExchange.Net.Authentication;
using Binance.Net.Objects.Spot;
using Binance.Net.Enums;

namespace BinanceBot
{
public partial class MainForm : Form
{
string VersieNummer = “1.0”;
private string TestApiKey = apiKey;
private string TestApiPrivateKey = privateKey;
BinanceClient TestBinance = new BinanceClient();

    public MainForm()
    {
        InitializeComponent();
        this.Text += ": " + VersieNummer;
        TestApiKey = Utils.DecryptString(TestApiKey);
        TestApiPrivateKey = Utils.DecryptString(TestApiPrivateKey);

        TestBinance = new BinanceClient(new BinanceClientOptions
        {
            ApiCredentials = new ApiCredentials(TestApiKey, TestApiPrivateKey),
            BaseAddress = "https://testnet.binance.vision"
        });
    }

    private void btnTest_Click(object sender, EventArgs e)
    {
        var preAccInfo = TestBinance.General.GetAccountInfo();
        var preAllOrders = TestBinance.Spot.Order.GetAllOrders("BTCUSDT");
        var preOpenOrders = TestBinance.Spot.Order.GetOpenOrders("BTCUSDT");

        var result = TestBinance.Spot.Order.PlaceOrder("BTCUSDT", OrderSide.Sell, OrderType.Market, 0.2m);
        if (result.Success)
        {
            //order success (PlaceOrder is always success, that is not a problem)
            var accInfo = TestBinance.General.GetAccountInfo();
            var allOrders = TestBinance.Spot.Order.GetAllOrders("BTCUSDT");
            var openOrders = TestBinance.Spot.Order.GetOpenOrders("BTCUSDT");
        }
        else
        {
            //order fail
        }
    }
}

}

PS: I can use: TestBinance.Spot.Order.GetMyTrades(“BTCUSDT”);
to get all trades BTCUSDT and this lists exactly what seems to have happened, the sell of 0.178721 BTC and not 0.2 BTC.

But also using GetAccountInfo I can see that my BTC decreased 0.178721.

The things is that it seems off for me that 0.178721 BTC is sold and not 0.2 BTC. And if it couldn’s sell this I would have expected an open order to exist for the remainder.

Kind regards,

Clemens Linders

Hi Clemens,

why are you decrypting your API keys? It that necessary?

Thanks a lot, Jon

Hi Jon,

The short answer is because they are encrypted :slight_smile:

The reason that I do so is because some years ago I made a failure to post a question with a screen shot with my apikeys visible.

Nothing happened, but since than I encrypt apikeys for any purpose.

Kind regards,

Clemens