A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.
Solution to Issue cannot be found in the documentation or other Issues and also occurs in the latest version of this library.
[X] I checked the documentation and other Issues. I am using the latest version of this library.
Issue
Hello there,
After struggling a while trying to send a MARKET order with websocket api I'm facing an unexpected issue. The API Response provides an error message "Parameter timeInForce sent when not required".
Looking at Binance documentation : Binance API TimeInForce
I have not found that it explicity doesn't want this parameter for order markets and just looks like optional and not used for MARKET orders however I've found this thread about something else which says the parameter must not be sent for market orders
I'm using Windows 10(x64), Pycharm Community 2022.2.5 and Python 3.11.
Any Clue ?
Thanks
Stephane
My code to reproduce :
from __future__ import print_function
from unicorn_binance_websocket_api.manager import BinanceWebSocketApiManager
import logging
import time
import threading
import os
from pathlib import Path
def print_stream_api_data(ubwa):
time.sleep(1)
while True:
if ubwa.is_manager_stopping():
exit(0)
oldest_stream_data_from_stream_buffer = ubwa.pop_stream_data_from_stream_buffer("Api")
if oldest_stream_data_from_stream_buffer is False:
time.sleep(0.01)
else:
try:
print(oldest_stream_data_from_stream_buffer)
except Exception:
# not able to process the data? write it back to the stream_buffer
ubwa.add_to_stream_buffer(oldest_stream_data_from_stream_buffer)
def main():
# Initialize logging file
logging.getLogger("unicorn_binance_websocket_api")
current_directory = os.getcwd()
sub_dir = 'logs/'
path = os.path.join(current_directory, sub_dir)
Path(path).mkdir(parents=True, exist_ok=True)
log_filename = path + f'{time.strftime("%Y-%m-%d_%H-%M-%S")}_unicorn.log'
logging.basicConfig(level=logging.DEBUG, filename=log_filename, format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}", style="{")
# create instance of BinanceWebSocketApiManager
ubwa = BinanceWebSocketApiManager(exchange="binance.com")
markets = ['btcusdt']
channels = ['kline_1m', 'Ticker']
# retrieve api keys
lines = [line.rstrip('\n') for line in open('secret.cfg')]
api_key = lines[0]
api_secret = lines[1]
# Create klines and ticker streams
for channel in channels:
ubwa.create_stream(channel, markets, stream_buffer_name=channel, output='default')
# Create API Stream
api_id = ubwa.create_stream(api=True, api_key=api_key, api_secret=api_secret, stream_label='Api', output='dict')
print("start API stream listening thread")
display_thread = threading.Thread(target=print_stream_api_data, args=(ubwa,))
display_thread.start()
time.sleep(2)
# Read account to check api streams are working. Works fine
account = ubwa.api.get_account_status(return_response=True, stream_id=api_id)['result']
# Place a market order fails here with response error message : Parameter timeInForce sent when not required
orig_client_order_id = ubwa.api.create_order(return_response=True, new_client_order_id='id_001', stream_id=api_id, order_type="MARKET", price=12, side="BUY", symbol="BTCUSDT")
if __name__ == '__main__':
main()
EDIT:, just edited the code below where i had the parameter timeInForce set for test purpose but actually when not set, it's anyway set by Unicorn apparently
Solution to Issue cannot be found in the documentation or other Issues and also occurs in the latest version of this library.
Issue
Hello there,
After struggling a while trying to send a MARKET order with websocket api I'm facing an unexpected issue. The API Response provides an error message "Parameter timeInForce sent when not required". Looking at Binance documentation : Binance API TimeInForce I have not found that it explicity doesn't want this parameter for order markets and just looks like optional and not used for MARKET orders however I've found this thread about something else which says the parameter must not be sent for market orders
I'm using Windows 10(x64), Pycharm Community 2022.2.5 and Python 3.11.
Any Clue ? Thanks Stephane
My code to reproduce :
EDIT:, just edited the code below where i had the parameter timeInForce set for test purpose but actually when not set, it's anyway set by Unicorn apparently