Пример #1
0
def cancel_bets(market):
    existing_bets = market.bet_set.filter(outcome__isnull=True,
                                          status='EXECUTABLE').all()

    if existing_bets:
        trading = get_betfair_client()
        res = trading.betting.cancel_orders(
            market_id=market.market_id,
            instructions=[
                cancel_instruction(bet_id=b.bet_id) for b in existing_bets
            ],
            lightweight=True)
        # print(json.dumps(res, indent=4, default=str, sort_keys=True))
        if res['status'] not in ['SUCCESS', 'PROCESSED_WITH_ERRORS']:
            raise Exception(
                f'$$$ Cannot cancel! {res["marketId"]}: {res["errorCode"]}')
        for item in res['instructionReports']:
            bet = Bet.objects.get(bet_id=item['instruction']['betId'])
            if item['status'] != 'SUCCESS':
                logger.error(f'Could not cancel {bet}')
                bet.status = 'EXECUTION_COMPLETE'
            else:
                bet.status = 'CANCELLED'
            bet.save()
            logger.info(f'$$$ Cancelled {bet}')
Пример #2
0
def order_cancel_to_betfair(command: CancelOrder,
                            instrument: BettingInstrument):
    """ Convert a SubmitOrder command into the data required by betfairlightweight """
    return {
        "market_id": instrument.market_id,
        "customer_ref": command.client_order_id.value,
        "instructions":
        [cancel_instruction(bet_id=command.venue_order_id.value)],
    }
Пример #3
0
def cancel_order(bet_id):
    # cancelling an order
    instruction = filters.cancel_instruction(bet_id=bet_id,
                                             size_reduction=2.00)
    cancel_order = trading.betting.cancel_orders(market_id=market_id,
                                                 instructions=[instruction])

    print(cancel_order.status)
    for cancel in cancel_order.cancel_instruction_reports:
        print("Status: %s, Size Cancelled: %s, Cancelled Date: %s" %
              (cancel.status, cancel.size_cancelled, cancel.cancelled_date))
Пример #4
0
 def test_cancel_instruction(self):
     response = cancel_instruction("1.123")
     assert response == {"betId": "1.123"}
Пример #5
0
 def create_cancel_instruction(self) -> dict:
     return filters.cancel_instruction(
         bet_id=self.bet_id,
         size_reduction=self.update_data.get("size_reduction"))
Пример #6
0
 def test_cancel_instruction(self):
     response = cancel_instruction('1.123')
     assert response == {'betId': '1.123'}