betcode-org/flumine

Betfair Order Placement Failing

Closed this issue · 2 comments

All order placement failing from approx 10am BST this morning. This is happening on my AWS and local servers. No code changes or package updates for several weeks.

Logs are reporting a json issue.

{"asctime": "2023-09-19 12:15:22,580", "levelname": "CRITICAL", "message": "Execution unknown error", "exc_info": "Traceback (most recent call last):
  File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/flumine/execution/betfairexecution.py\", line 248, in _execution_helper
    response = trading_function(order_package, http_session)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/flumine/execution/betfairexecution.py\", line 44, in place
    return order_package.client.betting_client.betting.place_orders(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/betfairlightweight/endpoints/betting.py\", line 502, in place_orders
    (response, response_json, elapsed_time) = self.request(method, params, session)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/betfairlightweight/endpoints/baseendpoint.py\", line 32, in request
    request = self.create_req(method, params)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/betfairlightweight/endpoints/baseendpoint.py\", line 64, in create_req
    return json.dumps(
             ^^^^^^^^^^^
TypeError: Type is not JSON serializable: numpy.float64", "trading_function": "place", "exception": "Type is not JSON serializable: numpy.float64", "order_package": {"id": "34f1b2d6-56e6-11ee-871b-3e225781988e", "client": "<flumine.clients.betfairclient.BetfairClient object at 0x109a0d7d0>", "market_id": "1.218415679", "orders": ["139144185225768310"], "order_count": 1, "package_type": "Place", "customer_strategy_ref": "Peters-Mac-mini", "bet_delay": 0, "market_version": null, "retry": true, "retry_count": 0, "async": true}}

Order placement code is:

    trade = Trade(market_id=win_market.market_id, selection_id=bf_selection_id, handicap=runner_handicap, strategy=self)
    order = trade.create_order(side="BACK", order_type=LimitOrder(price=betfair_ladder.win_price, size=betfair_win_stake, persistence_type="MARKET_ON_CLOSE"))
    win_market.place_order(order)

python 3.11.2. orjson 3.9.7

I assume this is orjson no longer doing this automatically and instead requiring an option, 3.9.7 was only released on the 8th.

https://github.com/ijl/orjson#numpy

Apologies. This was raised in a hurry as I was heading out the door, and I forgot that I had upgraded orjson after reading the discussion in the Slack channel.

I was able to avoid the problem simply by uninstalling orjson, which I guess is slower, but works, and supports your assumption.