betcode-org/flumine

_validate_betfair_price only works for CLASSIC ladder types, not for FINEST and LINE_RANGE

Closed this issue · 1 comments

In the TOTAL_POINTS_LINE markets the back prices are the unders value and the lay prices are the overs value. The actual price is always 2.0.

I tried to place a bet on the overs at 233.0, but this trips up the order validation stuff here:

elif utils.as_dec(order.order_type.price) not in utils.PRICES:

{"asctime": "2022-10-24 18:48:19,823", "name": "flumine.controls", "levelname": "WARNING", "message": "Order has violated: ORDER_VALIDATION Error: Order price is not valid", "control": "ORDER_VALIDATION", "error": "Order price is not valid", "order": {"market_id": "1.205496414", "selection_id": 105545, "handicap": 0, "id": "138859300988413659", "customer_order_ref": "354b9995c9ce8-138859300988413659", "bet_id": null, "date_time_created": "2022-10-24 18:48:18.842366", "publish_time": null, "market_version": null, "async": null, "trade": {"id": "6be453dd-53cc-11ed-a6ba-001b213a8a25", "strategy": "NBABackOvers", "place_reset_seconds": 0.0, "reset_seconds": 0.0, "orders": ["138859300988413659"], "offset_orders": [], "notes": "", "market_notes": null, "status": "Live", "status_log": ""}, "order_type": {"order_type": "Limit", "price": 233.0, "size": 10, "persistence_type": "LAPSE", "time_in_force": null, "min_fill_size": null, "bet_target_type": null, "bet_target_size": null}, "info": {"side": "LAY", "size_matched": 0.0, "size_remaining": 10.0, "size_cancelled": 0.0, "size_lapsed": 0.0, "size_voided": 0.0, "average_price_matched": 0.0}, "responses": {"date_time_placed": null, "elapsed_seconds_executable": null}, "runner_status": null, "status": "Violation", "status_log": "Violation", "violation_msg": "Order has violated: ORDER_VALIDATION Error: Order price is not valid", "simulated": {"profit": 0.0, "piq": 0.0, "matched": []}, "notes": "", "market_notes": null}}

The issue is that the allowable prices for this market go from 0.5 to 400.5 in intervals of 0.5.

To find the allowable prices I think you need to look on market catalogue -> description -> priceLadderDescription -> type to see what type the ladder is (CLASSIC, FINEST or LINE_RANGE).

For LINE_RANGE ladder types you then have to look on market catalogue -> description -> lineRangeInfo to get the interval between prices and the min and max values.

I think the FINEST ladder type is mainly used for Asian Handicap markets.

LimitOrder class updated to handle this, defaults to CLASSIC but can be changed like so:

FINEST

order = trade.create_order(
    side="BACK",
    order_type=LimitOrder(
        price=233,
        size=2.00,
        price_ladder_definition=market_book.price_ladder_definition.type,
    ),
)

LINE_RANGE

order = trade.create_order(
    side="BACK",
    order_type=LimitOrder(
        price=999.5,
        size=2.00,
        price_ladder_definition=market_book.price_ladder_definition.type,
        line_range_info=market.market_catalogue.description.line_range_info,
    ),
)