Skip to content

Commit

Permalink
1.4.3 fix #42
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Dec 12, 2023
1 parent 399021b commit 67bbfb6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v1.4.3 2023-12-12
### Fix
* For limit order get status EXPIRED_IN_MATCH on Binance testnet #42
+ Binance: in create Limit order parameters adding parameter "selfTradePreventionMode": "NONE"
+ For method json_format.ParseDict(..., ignore_unknown_fields=True) parameter added

## v1.4.2 2023-12-11
### Update
* Some minor improvements
Expand Down
2 changes: 1 addition & 1 deletion exchanges_wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
__contact__ = "https://github.com/DogsTailFarmer"
__email__ = "[email protected]"
__credits__ = ["https://github.com/DanyaSWorlD"]
__version__ = "1.4.2"
__version__ = "1.4.3"

from pathlib import Path
import shutil
Expand Down
2 changes: 1 addition & 1 deletion exchanges_wrapper/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ async def fetch_order( # lgtm [py/similar-function]

binance_res = {}
if self.exchange == 'binance':
params = {"symbol": symbol}
params = {"symbol": symbol, "selfTradePreventionMode": "NONE"}
if order_id:
params["orderId"] = order_id
else:
Expand Down
64 changes: 42 additions & 22 deletions exchanges_wrapper/exch_srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ async def FetchOpenOrders(self, request: api_pb2.MarketRequest,
for order in res:
order_id = order['orderId']
active_orders.append(order_id)
new_order = json_format.ParseDict(order, response_order)
new_order = json_format.ParseDict(order, response_order, ignore_unknown_fields=True)
# logger.debug(f"FetchOpenOrders.new_order: {new_order}")
response.items.append(new_order)
if client.exchange == 'bitfinex':
Expand Down Expand Up @@ -327,7 +327,7 @@ async def FetchOrder(self, request: api_pb2.FetchOrderRequest,
for trade in trades:
event = OrderTradesEvent(trade)
await _queue.put(weakref.ref(event)())
json_format.ParseDict(res, response)
json_format.ParseDict(res, response, ignore_unknown_fields=True)
return response

async def CancelAllOrders(self, request: api_pb2.MarketRequest,
Expand Down Expand Up @@ -363,48 +363,68 @@ async def FetchExchangeInfoSymbol(self, request: api_pb2.MarketRequest,
# logger.info(f"exchange_info_symbol: {exchange_info_symbol}")
open_client.ts_rlc = time.time()
filters_res = exchange_info_symbol.pop('filters', [])
json_format.ParseDict(exchange_info_symbol, response)
json_format.ParseDict(exchange_info_symbol, response, ignore_unknown_fields=True)
# logger.info(f"filters: {filters_res}")
filters = response.filters
for _filter in filters_res:
filter_type = _filter.get('filterType')
if filter_type == 'PRICE_FILTER':
new_filter_template = api_pb2.FetchExchangeInfoSymbolResponse.Filters.PriceFilter()
filters.price_filter.CopyFrom(json_format.ParseDict(_filter, new_filter_template))
filters.price_filter.CopyFrom(
json_format.ParseDict(_filter, new_filter_template, ignore_unknown_fields=True)
)
elif 'PERCENT_PRICE' in filter_type:
if filter_type == 'PERCENT_PRICE_BY_SIDE':
_filter['multiplierUp'] = _filter['bidMultiplierUp']
_filter['multiplierUp'] = _filter['askMultiplierUp']
_filter['multiplierDown'] = _filter['bidMultiplierDown']
del _filter['bidMultiplierUp']
del _filter['bidMultiplierDown']
del _filter['askMultiplierUp']
del _filter['askMultiplierDown']
new_filter_template = api_pb2.FetchExchangeInfoSymbolResponse.Filters.PercentPrice()
filters.percent_price.CopyFrom(json_format.ParseDict(_filter, new_filter_template))
filters.percent_price.CopyFrom(
json_format.ParseDict(_filter, new_filter_template, ignore_unknown_fields=True)
)
elif filter_type == 'LOT_SIZE':
new_filter_template = api_pb2.FetchExchangeInfoSymbolResponse.Filters.LotSize()
filters.lot_size.CopyFrom(json_format.ParseDict(_filter, new_filter_template))
filters.lot_size.CopyFrom(
json_format.ParseDict(_filter, new_filter_template, ignore_unknown_fields=True)
)
elif filter_type == 'MIN_NOTIONAL':
new_filter_template = api_pb2.FetchExchangeInfoSymbolResponse.Filters.MinNotional()
filters.min_notional.CopyFrom(json_format.ParseDict(_filter, new_filter_template))
filters.min_notional.CopyFrom(
json_format.ParseDict(_filter, new_filter_template, ignore_unknown_fields=True)
)
elif filter_type == 'NOTIONAL':
new_filter_template = api_pb2.FetchExchangeInfoSymbolResponse.Filters.Notional()
filters.notional.CopyFrom(json_format.ParseDict(_filter, new_filter_template))
filters.notional.CopyFrom(
json_format.ParseDict(_filter, new_filter_template, ignore_unknown_fields=True)
)
elif filter_type == 'ICEBERG_PARTS':
new_filter_template = api_pb2.FetchExchangeInfoSymbolResponse.Filters.IcebergParts()
filters.iceberg_parts.CopyFrom(json_format.ParseDict(_filter, new_filter_template))
filters.iceberg_parts.CopyFrom(
json_format.ParseDict(_filter, new_filter_template, ignore_unknown_fields=True)
)
elif filter_type == 'MARKET_LOT_SIZE':
new_filter_template = api_pb2.FetchExchangeInfoSymbolResponse.Filters.MarketLotSize()
filters.market_lot_size.CopyFrom(json_format.ParseDict(_filter, new_filter_template))
filters.market_lot_size.CopyFrom(
json_format.ParseDict(_filter, new_filter_template, ignore_unknown_fields=True)
)
elif filter_type == 'MAX_NUM_ORDERS':
new_filter_template = api_pb2.FetchExchangeInfoSymbolResponse.Filters.MaxNumOrders()
filters.max_num_orders.CopyFrom(json_format.ParseDict(_filter, new_filter_template))
filters.max_num_orders.CopyFrom(
json_format.ParseDict(_filter, new_filter_template, ignore_unknown_fields=True)
)
elif filter_type == 'MAX_NUM_ICEBERG_ORDERS':
new_filter_template = api_pb2.FetchExchangeInfoSymbolResponse.Filters.MaxNumIcebergOrders()
filters.max_num_iceberg_orders.CopyFrom(json_format.ParseDict(_filter, new_filter_template))
filters.max_num_iceberg_orders.CopyFrom(
json_format.ParseDict(_filter, new_filter_template, ignore_unknown_fields=True)
)
elif filter_type == 'MAX_POSITION':
new_filter_template = api_pb2.FetchExchangeInfoSymbolResponse.Filters.MaxPosition()
filters.max_position.CopyFrom(json_format.ParseDict(_filter, new_filter_template))
filters.max_position.CopyFrom(
json_format.ParseDict(_filter, new_filter_template, ignore_unknown_fields=True)
)
return response

async def FetchAccountInformation(self, request: api_pb2.OpenClientConnectionId,
Expand All @@ -428,7 +448,7 @@ async def FetchAccountInformation(self, request: api_pb2.OpenClientConnectionId,
balances.append({'asset': i.get('asset'), 'free': i.get('free'), 'locked': i.get('locked')})
# logger.info(f"account_information.balances: {balances}")
for balance in balances:
new_balance = json_format.ParseDict(balance, response_balance)
new_balance = json_format.ParseDict(balance, response_balance, ignore_unknown_fields=True)
response.balances.extend([new_balance])
return response

Expand All @@ -451,7 +471,7 @@ async def FetchFundingWallet(self, request: api_pb2.FetchFundingWalletRequest,
open_client.ts_rlc = time.time()
logger.debug(f"funding_wallet: {res}")
for balance in res:
new_balance = json_format.ParseDict(balance, response_balance)
new_balance = json_format.ParseDict(balance, response_balance, ignore_unknown_fields=True)
response.balances.extend([new_balance])
return response

Expand Down Expand Up @@ -482,7 +502,7 @@ async def FetchSymbolPriceTicker(
await self.rate_limit_control(open_client)
res = await client.fetch_symbol_price_ticker(symbol=request.symbol)
open_client.ts_rlc = time.time()
json_format.ParseDict(res, response)
json_format.ParseDict(res, response, ignore_unknown_fields=True)
return response

async def FetchTickerPriceChangeStatistics(
Expand All @@ -494,7 +514,7 @@ async def FetchTickerPriceChangeStatistics(
await self.rate_limit_control(open_client)
res = await client.fetch_ticker_price_change_statistics(symbol=request.symbol)
open_client.ts_rlc = time.time()
json_format.ParseDict(res, response)
json_format.ParseDict(res, response, ignore_unknown_fields=True)
return response

async def FetchKlines(self, request: api_pb2.FetchKlinesRequest,
Expand Down Expand Up @@ -597,7 +617,7 @@ async def FetchAccountTradeList(self, request: api_pb2.AccountTradeListRequest,
# logger.info(f"FetchAccountTradeList: {res}")
open_client.ts_rlc = time.time()
for trade in res:
trade_order = json_format.ParseDict(trade, response_trade)
trade_order = json_format.ParseDict(trade, response_trade, ignore_unknown_fields=True)
response.items.append(trade_order)
return response

Expand Down Expand Up @@ -632,7 +652,7 @@ async def OnTickerUpdate(self, request: api_pb2.MarketRequest,
'close_price': _event.close_price,
'event_time': _event.event_time}
# logger.info(f"OnTickerUpdate.event: {_event.symbol}, ticker_24h: {ticker_24h}")
json_format.ParseDict(ticker_24h, response)
json_format.ParseDict(ticker_24h, response, ignore_unknown_fields=True)
yield response
_queue.task_done()

Expand Down Expand Up @@ -813,7 +833,7 @@ async def CreateLimitOrder(self, request: api_pb2.CreateLimitOrderRequest,
origin_client_order_id=request.new_client_order_id,
receive_window=None,
response_type=False)
json_format.ParseDict(res, response)
json_format.ParseDict(res, response, ignore_unknown_fields=True)
logger.debug(f"CreateLimitOrder: for {open_client.name}:{request.symbol}: created: {res.get('orderId')}")
return response

Expand Down Expand Up @@ -842,7 +862,7 @@ async def CancelOrder(self, request: api_pb2.CancelOrderRequest,
_context.set_details(f"{ex}")
_context.set_code(grpc.StatusCode.UNKNOWN)
else:
json_format.ParseDict(res, response)
json_format.ParseDict(res, response, ignore_unknown_fields=True)
return response

async def TransferToMaster(self, request: api_pb2.MarketRequest,
Expand Down

0 comments on commit 67bbfb6

Please sign in to comment.