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

User data updates for coin-margined futures not being received despite successful subscription. #545

Closed
deadheadblues opened this issue Jan 14, 2021 · 5 comments

Comments

@deadheadblues
Copy link

Describe the bug
User data updates are not received when streaming coin-margined futures despite successfully subscribing to updates. Works fine when subscribing to usdt-margined user data updates though.

To Reproduce

        // Set the default options of the Binance rest client.
        BinanceClient.SetDefaultOptions(new BinanceClientOptions()
        {
            ApiCredentials = apiCredentials,
            BaseAddress = "https://api.binance.us",
            BaseAddressUsdtFutures = "https://testnet.binancefuture.com",
            BaseAddressCoinFutures = "https://testnet.binancefuture.com",
            LogVerbosity = LogVerbosity.Debug
        });

        // Set the default options of the Binance web socket client.
        BinanceSocketClient.SetDefaultOptions(new BinanceSocketClientOptions()
        {
            ApiCredentials = apiCredentials,
            BaseAddress = "wss://stream.binance.us:9443",
            BaseAddressUsdtFutures = "wss://stream.binancefuture.com/",
            BaseAddressCoinFutures = "wss://stream.binancefuture.com/",
            LogVerbosity = LogVerbosity.Debug,
        });

        // Create a BinanceClient to make rest api requests.
        BinanceClient = new BinanceClient();
        // Create a BinanceSocketClient to make web socket requests.
        BinanceSocketClient = new BinanceSocketClient();

        // Subscripbe to usdt futures updates.
        WebCallResult<string> futuresUsdtStartStreamResult = BinanceClient.FuturesUsdt.UserStream.StartUserStream();
        if (futuresUsdtStartStreamResult.Success)
        {
            BinanceSocketClient.FuturesUsdt.SubscribeToUserDataUpdates(futuresUsdtStartStreamResult.Data,
                      null,
                      null,
                      onOrderUpdate => { Debug.Write("USDT FUTURE ORDER UPDATE RECEIVED" + Environment.NewLine); },
                      null);
        }

        // Subscribe to coin futures updates.
        WebCallResult<string> futuresCoinStartStreamResult = BinanceClient.FuturesCoin.UserStream.StartUserStream();
        if (futuresCoinStartStreamResult.Success)
        {
            BinanceSocketClient.FuturesCoin.SubscribeToUserDataUpdates(futuresCoinStartStreamResult.Data, 
                      null,
                      null,
                      onOrderUpdate => { Debug.Write("COIN FUTURE ORDER UPDATE RECEIVED" + Environment.NewLine); },
                      null);
        }

        // Send usdt future order.
        if (BinanceClient.FuturesUsdt.Order.PlaceOrder("BTCUSDT", OrderSide.Buy, OrderType.Market, 1).Success)
        {
            Debug.Write("USDT FUTURE ORDER SUCCESSFUL" + Environment.NewLine);
        }

        // Send coin future order.
        if (BinanceClient.FuturesCoin.Order.PlaceOrder("BTCUSD_210326", OrderSide.Buy, OrderType.Market, 1).Success)
        {
            Debug.Write("COIN FUTURE ORDER SUCCESSFUL"+Environment.NewLine);
        }

Expected behavior
The expected behavior is for user updates to be received through the user data stream subscription like how it happens for USDT futures.

Debug logging
2021/01/14 10:30:03:505 | Binance | Debug | Client configuration: LogVerbosity: Debug, Writers: 1, Credentials: Set, BaseAddress: https://api.binance.us/, Proxy: -, RateLimiters: 0, RateLimitBehaviour: Wait, RequestTimeout: 00:00:30
2021/01/14 10:30:03:568 | Binance | Debug | Client configuration: LogVerbosity: Debug, Writers: 1, Credentials: Set, BaseAddress: wss://stream.binance.us:9443/, Proxy: -, AutoReconnect: True, ReconnectInterval: 00:00:05, SocketResponseTimeout: 00:00:10, SocketSubscriptionsCombineTarget:
2021/01/14 10:30:03:578 | Binance | Debug | [1] Creating request for https://api.binance.us/api/v3/time
2021/01/14 10:30:03:597 | Binance | Debug | [1] Sending GET request to https://api.binance.us/api/v3/time
2021/01/14 10:30:03:774 | Binance | Debug | [1] Response received in 165ms: {"serverTime":1610638204515}
2021/01/14 10:30:03:912 | Binance | Debug | [2] Creating request for https://api.binance.us/api/v3/time
2021/01/14 10:30:03:913 | Binance | Debug | [2] Sending GET request to https://api.binance.us/api/v3/time
2021/01/14 10:30:03:929 | Binance | Debug | [2] Response received in 15ms: {"serverTime":1610638204675}
2021/01/14 10:30:03:931 | Binance | Info | Time offset set to 762.9376ms
2021/01/14 10:30:03:933 | Binance | Debug | [3] Creating request for https://testnet.binancefuture.com/fapi/v1/listenKey
2021/01/14 10:30:03:935 | Binance | Debug | [3] Sending POST request to https://testnet.binancefuture.com/fapi/v1/listenKey with request body
2021/01/14 10:30:04:522 | Binance | Debug | [3] Response received in 586ms: {"listenKey":"RWnCXTN9iL95pR13TUaOiamT9zxZKbpssaSIpnJ3eDZSDnA7S87Nm4L7gOFOHXyZ"}
2021/01/14 10:30:04:547 | Binance | Debug | Created new socket for wss://stream.binancefuture.com/ws/RWnCXTN9iL95pR13TUaOiamT9zxZKbpssaSIpnJ3eDZSDnA7S87Nm4L7gOFOHXyZ
2021/01/14 10:30:04:570 | Binance | Debug | Socket 1 connecting
2021/01/14 10:30:05:405 | Binance | Debug | Socket 1 connected
2021/01/14 10:30:05:408 | Binance | Debug | [5] Creating request for https://testnet.binancefuture.com/dapi/v1/listenKey
2021/01/14 10:30:05:409 | Binance | Debug | [5] Sending POST request to https://testnet.binancefuture.com/dapi/v1/listenKey with request body
2021/01/14 10:30:06:011 | Binance | Debug | [5] Response received in 601ms: {"listenKey":"xdq6x5FRcuTIZdarFmPj889Ejzj049aAW9uKjoAtNIRG2KFlihqdAi55krMxP6Lk"}
2021/01/14 10:30:06:013 | Binance | Debug | Created new socket for wss://stream.binancefuture.com/ws/xdq6x5FRcuTIZdarFmPj889Ejzj049aAW9uKjoAtNIRG2KFlihqdAi55krMxP6Lk
2021/01/14 10:30:06:014 | Binance | Debug | Socket 2 connecting
2021/01/14 10:30:06:732 | Binance | Debug | Socket 2 connected
2021/01/14 10:30:06:793 | Binance | Debug | [7] Creating request for https://testnet.binancefuture.com/fapi/v1/order
2021/01/14 10:30:06:832 | Binance | Debug | [7] Sending POST signed request to https://testnet.binancefuture.com/fapi/v1/order with request body quantity=1&recvWindow=5000&side=BUY&signature=0853BEE189FF34C5A396BE759A30CA76032C46478F56719E3C1854E4F7C694F2&symbol=BTCUSDT&timestamp=1610638207555&type=MARKET
2021/01/14 10:30:07:632 | Binance | Debug | [7] Response received in 796ms: {"orderId":2611733004,"symbol":"BTCUSDT","status":"NEW","clientOrderId":"6bngw21DJGGemRmdGN9eQe","price":"0","avgPrice":"0.00000","origQty":"1","executedQty":"0","cumQty":"0","cumQuote":"0","timeInForce":"GTC","type":"MARKET","reduceOnly":false,"closePosition":false,"side":"BUY","positionSide":"BOTH","stopPrice":"0","workingType":"CONTRACT_PRICE","priceProtect":false,"origType":"MARKET","updateTime":1610638208309}
2021/01/14 10:30:07:665 | Binance | Debug | Socket 1 received data: {"e":"ORDER_TRADE_UPDATE","T":1610638208309,"E":1610638208312,"o":{"s":"BTCUSDT","c":"6bngw21DJGGemRmdGN9eQe","S":"BUY","o":"MARKET","f":"GTC","q":"1","p":"0","ap":"0","sp":"0","x":"NEW","X":"NEW","i":2611733004,"l":"0","z":"0","L":"0","T":1610638208309,"t":0,"b":"0","a":"0","m":false,"R":false,"wt":"CONTRACT_PRICE","ot":"MARKET","ps":"BOTH","cp":false,"rp":"0","pP":false,"si":0,"ss":0}}
USDT FUTURE ORDER SUCCESSFUL
2021/01/14 10:30:07:679 | Binance | Debug | [8] Creating request for https://testnet.binancefuture.com/dapi/v1/order
2021/01/14 10:30:07:680 | Binance | Debug | [8] Sending POST signed request to https://testnet.binancefuture.com/dapi/v1/order with request body quantity=1&recvWindow=5000&side=BUY&signature=336904923664A5B5CC7FBC84B34144B82A915B42D29FCAD50185656239E9FD8C&symbol=BTCUSD_210326&timestamp=1610638208442&type=MARKET
2021/01/14 10:30:07:685 | Binance | Debug | {
"e": "ORDER_TRADE_UPDATE",
"T": 1610638208309,
"E": 1610638208312,
"o": {
"s": "BTCUSDT",
"c": "6bngw21DJGGemRmdGN9eQe",
"S": "BUY",
"o": "MARKET",
"f": "GTC",
"q": "1",
"p": "0",
"ap": "0",
"sp": "0",
"x": "NEW",
"X": "NEW",
"i": 2611733004,
"l": "0",
"z": "0",
"L": "0",
"T": 1610638208309,
"t": 0,
"b": "0",
"a": "0",
"m": false,
"R": false,
"wt": "CONTRACT_PRICE",
"ot": "MARKET",
"ps": "BOTH",
"cp": false,
"rp": "0",
"pP": false,
"si": 0,
"ss": 0
}
}
USDT FUTURE ORDER UPDATE RECEIVED
2021/01/14 10:30:07:705 | Binance | Debug | Socket 1 received data: {"e":"ACCOUNT_UPDATE","T":1610638208309,"E":1610638208312,"a":{"B":[{"a":"USDT","wb":"41155.75036105","cw":"41155.75036105"}],"P":[{"s":"BTCUSDT","pa":"5","ep":"39560.50000","cr":"41904.65494994","up":"1408.83485865","mt":"cross","iw":"0","ps":"BOTH","ma":"USDT"},{"s":"BTCUSDT","pa":"0","ep":"0.00000","cr":"-9108.66000000","up":"0","mt":"cross","iw":"0","ps":"LONG","ma":"USDT"},{"s":"BTCUSDT","pa":"0","ep":"0.00000","cr":"4421.03000000","up":"0","mt":"cross","iw":"0","ps":"SHORT","ma":"USDT"}],"m":"ORDER"}}
2021/01/14 10:30:07:734 | Binance | Debug | Socket 1 received data: {"e":"ORDER_TRADE_UPDATE","T":1610638208309,"E":1610638208312,"o":{"s":"BTCUSDT","c":"6bngw21DJGGemRmdGN9eQe","S":"BUY","o":"MARKET","f":"GTC","q":"1","p":"0","ap":"39849.93000","sp":"0","x":"TRADE","X":"FILLED","i":2611733004,"l":"1","z":"1","L":"39849.93","n":"15.93997200","N":"USDT","T":1610638208309,"t":154402974,"b":"0","a":"0","m":false,"R":false,"wt":"CONTRACT_PRICE","ot":"MARKET","ps":"BOTH","cp":false,"rp":"0","pP":false,"si":0,"ss":0}}
2021/01/14 10:30:07:736 | Binance | Debug | {
"e": "ORDER_TRADE_UPDATE",
"T": 1610638208309,
"E": 1610638208312,
"o": {
"s": "BTCUSDT",
"c": "6bngw21DJGGemRmdGN9eQe",
"S": "BUY",
"o": "MARKET",
"f": "GTC",
"q": "1",
"p": "0",
"ap": "39849.93000",
"sp": "0",
"x": "TRADE",
"X": "FILLED",
"i": 2611733004,
"l": "1",
"z": "1",
"L": "39849.93",
"n": "15.93997200",
"N": "USDT",
"T": 1610638208309,
"t": 154402974,
"b": "0",
"a": "0",
"m": false,
"R": false,
"wt": "CONTRACT_PRICE",
"ot": "MARKET",
"ps": "BOTH",
"cp": false,
"rp": "0",
"pP": false,
"si": 0,
"ss": 0
}
}
USDT FUTURE ORDER UPDATE RECEIVED
2021/01/14 10:30:08:293 | Binance | Debug | [8] Response received in 611ms: {"orderId":14702153,"symbol":"BTCUSD_210326","pair":"BTCUSD","status":"NEW","clientOrderId":"p1MIkOR8gRUjLUKWIwhAaO","price":"0","avgPrice":"0.0","origQty":"1","executedQty":"0","cumQty":"0","cumBase":"0","timeInForce":"GTC","type":"MARKET","reduceOnly":false,"closePosition":false,"side":"BUY","positionSide":"BOTH","stopPrice":"0","workingType":"CONTRACT_PRICE","priceProtect":false,"origType":"MARKET","updateTime":1610638208959}
COIN FUTURE ORDER SUCCESSFUL

@deadheadblues
Copy link
Author

Pardon the double post - I received a 404 page not found when submitting both times. Please remove one.

@ltoni90
Copy link

ltoni90 commented Jan 18, 2021

Change the BaseAddress of BinanceSocketClientOptions to BaseAddress = "wss://stream.binancefuture.com", as you're using the Binance Testnet.

@deadheadblues
Copy link
Author

Thanks for the suggestion. I implemented it but am still not receiving updates from the web socket after successfully submitting a coin-m futures order.

This was referenced Jan 20, 2021
@ltoni90
Copy link

ltoni90 commented Jan 21, 2021

Hmm that's strange... I had the same issue with the Binance Testnet. I got it running by passing the following options to the clients:

var clientOptions = new BinanceClientOptions
{
    BaseAddressUsdtFutures = "https://testnet.binancefuture.com",
    BaseAddressCoinFutures = "https://testnet.binancefuture.com"
};

var socketClientOptions = new BinanceSocketClientOptions
{
    BaseAddress = "wss://stream.binancefuture.com",
    BaseAddressUsdtFutures = "wss://stream.binancefuture.com",
    BaseAddressCoinFutures = "wss://stream.binancefuture.com",
};

Maybe this helps you.

EDIT:
If this settings still not working for you, I suggest that you clone the whole Binance.Net repo and replace the NuGet reference with the cloned repo. After that open BinanceSocketClientFutures (Binance.Net.Objects.SocketSubClients) and set a breakpoint on the Subscribe<T>(string url, bool combined, Action<T> onData) method. Run your app again and as soon as the debugger hits the breakpoint take a look at the BaseAddress property. In my case I forgot to add BaseAddress = "wss://stream.binancefuture.com". That's why I suggested to change the BaseAddress.

@JKorf
Copy link
Owner

JKorf commented Mar 1, 2021

@deadheadblues Is this still relevant?

@JKorf JKorf closed this as completed May 31, 2021
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

3 participants