Exemplo n.º 1
0
def __mark_orders_successful(request):
    orders = make_dict(request).get("params").get("instructions")
    return [{
        "status": "SUCCESS",
        "instruction": {
            "selectionId": int(order.get("selectionId"))
        },
    } for order in orders]
Exemplo n.º 2
0
def test_make_dict():
    GIVEN("valid dictionary in a json string")
    string = "this is clearly not a json dictionary"

    WHEN("we call make_dict")
    new_dict = make_dict(string)

    THEN("None is returned")
    assert new_dict is None
Exemplo n.º 3
0
 def openurl(self):
     self.__get_response()
     if self.__is_ok():
         json_response = self.__response.read()
         data = _add_ok_status(
             data=make_dict(json_response.decode("utf-8")))
     else:
         data = {}
     return data
Exemplo n.º 4
0
def test_json_utils():
    GIVEN("an open file and a dict")

    test_file = "test_write_to_json.txt"
    test_file_path = get_test_file_path(name=test_file)
    test_dict = {"this is a silly": "dict", "it would have no use": True}

    with open(test_file_path, "w+", encoding="utf-8") as file:
        WHEN("we write the dict as json to the file")
        write_json_to(file=file, data=test_dict)

    THEN("the record is in the file and can be converted back into the dict")
    with open(test_file_path, "r", encoding="utf-8") as file:
        json_string = next(file)
    assert make_dict(json_string) == test_dict

    cleanup_test_file(name=test_file)
Exemplo n.º 5
0
def test_post_data(mock_call_exchange):

    GIVEN("a market handler and some orders")
    market_handler = ExternalAPIMarketHandler(mediator=MockMediator(),
                                              environment="Dev",
                                              headers={},
                                              market_id=123456)
    orders = get_test_orders()

    WHEN("we post the orders")
    market_handler.post_order(orders=orders)
    THEN("the exchange was called with the correct request")
    args, kwargs = mock_call_exchange.call_args
    request = make_dict(kwargs.get("request"))
    expected_request = get_expected_request()
    assert args == ()
    assert request.get("params").get("instructions") == expected_request.get(
        "params").get("instructions")
Exemplo n.º 6
0
def __get_data():
    return make_dict(
        '{"runners": [{"status": "ACTIVE", "handicap": 0.0, "selectionId": 8724980, "sp": {"nearPrice": 28.0, "backStakeTaken": [{"price": 120.0, "size": 5.0}], "farPrice": 1.0, "layLiabilityTaken": []}, "totalMatched": 9.99, "adjustmentFactor": 4.545, "ex": {"availableToBack": [{"price": 17.5, "size": 6.94}, {"price": 15.0, "size": 9.66}, {"price": 14.0, "size": 122.08}], "availableToLay": [{"price": 40.0, "size": 6.36}, {"price": 70.0, "size": 9.17}, {"price": 75.0, "size": 5.0}], "tradedVolume": [{"price": 16.5, "size": 10.0}]}, "lastPriceTraded": 16.5}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 7406222, "sp": {"nearPrice": 120.0, "backStakeTaken": [], "farPrice": "NaN", "layLiabilityTaken": []}, "totalMatched": 0.0, "adjustmentFactor": 0.498, "ex": {"availableToBack": [{"price": 80.0, "size": 7.69}, {"price": 75.0, "size": 5.0}, {"price": 50.0, "size": 9.52}], "availableToLay": [{"price": 350.0, "size": 6.33}, {"price": 400.0, "size": 8.52}], "tradedVolume": []}}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 2588927, "sp": {"nearPrice": 30.0, "backStakeTaken": [{"price": 120.0, "size": 5.0}], "farPrice": 1.0, "layLiabilityTaken": []}, "totalMatched": 39.99, "adjustmentFactor": 5.0, "ex": {"availableToBack": [{"price": 14.0, "size": 9.72}, {"price": 13.5, "size": 7.39}, {"price": 13.0, "size": 120.0}], "availableToLay": [{"price": 50.0, "size": 6.85}, {"price": 60.0, "size": 8.14}, {"price": 65.0, "size": 5.0}], "tradedVolume": [{"price": 14.5, "size": 30.81}, {"price": 15.0, "size": 6.92}, {"price": 15.5, "size": 1.99}, {"price": 16.0, "size": 0.28}]}, "lastPriceTraded": 14.5}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 7407243, "sp": {"nearPrice": 9.1, "backStakeTaken": [], "farPrice": "NaN", "layLiabilityTaken": []}, "totalMatched": 70.28, "adjustmentFactor": 10.0, "ex": {"availableToBack": [{"price": 7.2, "size": 6.65}, {"price": 6.6, "size": 8.23}, {"price": 6.4, "size": 120.0}], "availableToLay": [{"price": 11.0, "size": 6.34}, {"price": 12.0, "size": 10.47}, {"price": 18.5, "size": 16.85}], "tradedVolume": [{"price": 8.0, "size": 13.07}, {"price": 8.2, "size": 6.92}, {"price": 8.4, "size": 13.24}, {"price": 8.6, "size": 6.76}, {"price": 8.8, "size": 20.01}, {"price": 9.0, "size": 10.0}, {"price": 9.2, "size": 0.28}]}, "lastPriceTraded": 9.2}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 7338681, "sp": {"nearPrice": 17.20378426340816, "backStakeTaken": [{"price": 1.01, "size": 45.11}, {"price": 60.0, "size": 5.0}], "farPrice": 1.0, "layLiabilityTaken": []}, "totalMatched": 0.0, "adjustmentFactor": 3.846, "ex": {"availableToBack": [{"price": 18.5, "size": 12.48}, {"price": 16.5, "size": 124.77}, {"price": 15.5, "size": 24.52}], "availableToLay": [{"price": 75.0, "size": 6.12}, {"price": 85.0, "size": 9.17}, {"price": 90.0, "size": 5.0}], "tradedVolume": []}}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 12743060, "sp": {"nearPrice": 72.0, "backStakeTaken": [{"price": 140.0, "size": 5.0}], "farPrice": 1.0, "layLiabilityTaken": []}, "totalMatched": 0.0, "adjustmentFactor": 1.235, "ex": {"availableToBack": [{"price": 42.0, "size": 70.17}, {"price": 40.0, "size": 9.11}, {"price": 32.0, "size": 5.14}], "availableToLay": [{"price": 110.0, "size": 6.36}, {"price": 200.0, "size": 5.54}, {"price": 280.0, "size": 5.19}], "tradedVolume": []}}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 7978445, "sp": {"nearPrice": 38.5, "backStakeTaken": [{"price": 85.0, "size": 5.0}], "farPrice": 1.0, "layLiabilityTaken": []}, "totalMatched": 50.0, "adjustmentFactor": 2.174, "ex": {"availableToBack": [{"price": 28.0, "size": 6.96}, {"price": 24.0, "size": 124.71}, {"price": 21.0, "size": 17.56}], "availableToLay": [{"price": 55.0, "size": 11.23}, {"price": 110.0, "size": 5.34}, {"price": 180.0, "size": 9.07}], "tradedVolume": [{"price": 25.0, "size": 36.73}, {"price": 26.0, "size": 6.36}, {"price": 27.0, "size": 6.92}]}, "lastPriceTraded": 25.0}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 12649338, "sp": {"nearPrice": 52.5, "backStakeTaken": [{"price": 90.0, "size": 5.0}], "farPrice": 1.0, "layLiabilityTaken": []}, "totalMatched": 0.0, "adjustmentFactor": 2.632, "ex": {"availableToBack": [{"price": 24.0, "size": 6.64}, {"price": 23.0, "size": 9.85}, {"price": 22.0, "size": 120.0}], "availableToLay": [{"price": 80.0, "size": 6.28}, {"price": 120.0, "size": 7.27}, {"price": 130.0, "size": 8.98}], "tradedVolume": []}}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 22361367, "sp": {"nearPrice": 5.95, "backStakeTaken": [], "farPrice": "NaN", "layLiabilityTaken": []}, "totalMatched": 10.19, "adjustmentFactor": 22.285, "ex": {"availableToBack": [{"price": 4.9, "size": 8.11}, {"price": 3.85, "size": 8.12}, {"price": 3.7, "size": 11.4}], "availableToLay": [{"price": 6.8, "size": 10.33}, {"price": 7.8, "size": 36.77}, {"price": 8.8, "size": 35.55}], "tradedVolume": [{"price": 5.7, "size": 10.2}]}, "lastPriceTraded": 5.7}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 20258183, "sp": {"nearPrice": 14.97515226214193, "backStakeTaken": [{"price": 1.01, "size": 5.0}], "farPrice": 1.0, "layLiabilityTaken": []}, "totalMatched": 0.0, "adjustmentFactor": 5.0, "ex": {"availableToBack": [{"price": 14.5, "size": 7.52}, {"price": 14.0, "size": 6.54}, {"price": 12.0, "size": 125.6}], "availableToLay": [{"price": 36.0, "size": 7.36}, {"price": 50.0, "size": 7.08}, {"price": 55.0, "size": 14.92}], "tradedVolume": []}}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 17775017, "sp": {"nearPrice": 4.5, "backStakeTaken": [], "farPrice": "NaN", "layLiabilityTaken": []}, "totalMatched": 0.0, "adjustmentFactor": 22.727, "ex": {"availableToBack": [{"price": 3.8, "size": 6.79}, {"price": 3.75, "size": 7.88}, {"price": 3.7, "size": 6.76}], "availableToLay": [{"price": 5.1, "size": 10.48}, {"price": 5.2, "size": 5.6}, {"price": 7.8, "size": 32.61}], "tradedVolume": []}}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 15708088, "sp": {"nearPrice": 285.0, "backStakeTaken": [], "farPrice": "NaN", "layLiabilityTaken": []}, "totalMatched": 0.38, "adjustmentFactor": 0.45, "ex": {"availableToBack": [{"price": 100.0, "size": 7.17}, {"price": 75.0, "size": 7.66}, {"price": 50.0, "size": 7.25}], "availableToLay": [{"price": 450.0, "size": 6.35}, {"price": 480.0, "size": 8.52}, {"price": 690.0, "size": 5.26}], "tradedVolume": [{"price": 150.0, "size": 0.38}]}, "lastPriceTraded": 150.0}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 22032700, "sp": {"nearPrice": 5.55, "backStakeTaken": [], "farPrice": "NaN", "layLiabilityTaken": []}, "totalMatched": 10.28, "adjustmentFactor": 16.667, "ex": {"availableToBack": [{"price": 4.9, "size": 8.7}, {"price": 4.8, "size": 35.34}, {"price": 4.6, "size": 8.03}], "availableToLay": [{"price": 6.0, "size": 9.46}, {"price": 6.2, "size": 7.88}, {"price": 9.8, "size": 5.4}], "tradedVolume": [{"price": 4.7, "size": 7.12}, {"price": 4.8, "size": 3.16}]}, "lastPriceTraded": 4.7}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 22361368, "sp": {"nearPrice": 34.5, "backStakeTaken": [{"price": 60.0, "size": 5.0}], "farPrice": 1.0, "layLiabilityTaken": []}, "totalMatched": 0.0, "adjustmentFactor": 2.941, "ex": {"availableToBack": [{"price": 21.0, "size": 9.56}, {"price": 20.0, "size": 5.88}, {"price": 19.5, "size": 123.46}], "availableToLay": [{"price": 48.0, "size": 6.36}, {"price": 75.0, "size": 5.34}, {"price": 90.0, "size": 11.14}], "tradedVolume": []}}], "process_time": "2019-01-13T07:00:34Z"}'  # pylint: disable=line-too-long
    )
Exemplo n.º 7
0
def __get_closed_market_dict():
    return make_dict(
        '{"result": [{"status": "OPEN", "isMarketDataDelayed": false, "numberOfRunners": 6, "complete": true, "bspReconciled": false, "runnersVoidable": false, "betDelay": 0, "marketId": "1.153523462", "crossMatching": true, "totalMatched": 11572.39, "version": 2590617656, "lastMatchTime": "2019-01-13T04:18:22.485Z", "numberOfWinners": 1, "inplay": true, "numberOfActiveRunners": 6, "totalAvailable": 244873.41, "runners": [{"status": "ACTIVE", "handicap": 0.0, "selectionId": 2320993, "sp": {"nearPrice": 4.292248027113674, "backStakeTaken": [{"price": 1.01, "size": 454.11}, {"price": 1.3, "size": 100.0}, {"price": 4.7, "size": 10.0}, {"price": 6.6, "size": 20.0}, {"price": 12.0, "size": 15.0}], "farPrice": 1.262463642, "layLiabilityTaken": [{"price": 1000.0, "size": 84.58}, {"price": 11.0, "size": 44.0}, {"price": 1.08, "size": 31.79}]}, "totalMatched": 3254.5, "adjustmentFactor": 25.0, "ex": {"availableToBack": [{"price": 4.0, "size": 97.1}, {"price": 3.95, "size": 71.1}, {"price": 3.9, "size": 30.96}], "availableToLay": [{"price": 4.2, "size": 20.88}, {"price": 4.3, "size": 85.06}, {"price": 4.4, "size": 46.12}], "tradedVolume": [{"price": 3.25, "size": 32.92}, {"price": 3.3, "size": 7.08}, {"price": 3.85, "size": 19.74}, {"price": 3.95, "size": 36.33}, {"price": 4.0, "size": 450.48}, {"price": 4.1, "size": 383.67}, {"price": 4.2, "size": 339.86}, {"price": 4.3, "size": 256.44}, {"price": 4.4, "size": 366.97}, {"price": 4.5, "size": 894.81}, {"price": 4.6, "size": 22.21}, {"price": 4.8, "size": 10.0}, {"price": 5.0, "size": 434.0}]}, "lastPriceTraded": 4.1}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 21427613, "sp": {"nearPrice": 6.035664381750683, "backStakeTaken": [{"price": 1.01, "size": 100.0}, {"price": 9.0, "size": 20.0}], "farPrice": 1.74, "layLiabilityTaken": [{"price": 1000.0, "size": 62.05}, {"price": 11.0, "size": 44.0}, {"price": 1.08, "size": 31.79}]}, "totalMatched": 2609.03, "adjustmentFactor": 14.085, "ex": {"availableToBack": [{"price": 7.0, "size": 39.63}, {"price": 6.8, "size": 83.63}, {"price": 6.6, "size": 156.86}], "availableToLay": [{"price": 7.2, "size": 51.99}, {"price": 7.4, "size": 22.88}, {"price": 7.6, "size": 18.16}], "tradedVolume": [{"price": 5.4, "size": 76.44}, {"price": 5.8, "size": 12.0}, {"price": 5.9, "size": 0.02}, {"price": 6.0, "size": 0.4}, {"price": 6.2, "size": 101.27}, {"price": 6.4, "size": 572.14}, {"price": 6.6, "size": 573.89}, {"price": 6.8, "size": 583.34}, {"price": 7.0, "size": 382.82}, {"price": 7.2, "size": 106.31}, {"price": 7.4, "size": 76.2}, {"price": 7.6, "size": 107.47}, {"price": 7.8, "size": 16.74}]}, "lastPriceTraded": 7.0}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 21059172, "sp": {"nearPrice": 3.5132056962946425, "backStakeTaken": [{"price": 1.01, "size": 210.18}], "farPrice": 1.51655879, "layLiabilityTaken": [{"price": 1000.0, "size": 23.15}, {"price": 11.0, "size": 44.0}, {"price": 1.08, "size": 31.79}]}, "totalMatched": 1075.07, "adjustmentFactor": 28.911, "ex": {"availableToBack": [{"price": 3.65, "size": 119.8}, {"price": 3.6, "size": 595.21}, {"price": 3.55, "size": 170.47}], "availableToLay": [{"price": 3.7, "size": 28.36}, {"price": 3.75, "size": 32.71}, {"price": 3.8, "size": 39.8}], "tradedVolume": [{"price": 3.3, "size": 59.41}, {"price": 3.35, "size": 84.85}, {"price": 3.45, "size": 18.14}, {"price": 3.5, "size": 294.19}, {"price": 3.55, "size": 308.87}, {"price": 3.6, "size": 164.0}, {"price": 3.65, "size": 111.98}, {"price": 3.7, "size": 33.64}]}, "lastPriceTraded": 3.65}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 21662195, "sp": {"nearPrice": 5.509852539, "backStakeTaken": [{"price": 1.01, "size": 117.0}, {"price": 24.0, "size": 15.0}], "farPrice": 1.530120482, "layLiabilityTaken": [{"price": 1000.0, "size": 27.6}, {"price": 990.0, "size": 100.0}, {"price": 11.0, "size": 44.0}, {"price": 1.08, "size": 31.79}]}, "totalMatched": 2639.26, "adjustmentFactor": 17.241, "ex": {"availableToBack": [{"price": 6.0, "size": 43.55}, {"price": 5.9, "size": 88.28}, {"price": 5.8, "size": 45.86}], "availableToLay": [{"price": 6.2, "size": 26.47}, {"price": 6.4, "size": 63.63}, {"price": 6.6, "size": 68.8}], "tradedVolume": [{"price": 4.7, "size": 70.0}, {"price": 5.4, "size": 0.75}, {"price": 5.5, "size": 19.84}, {"price": 5.6, "size": 809.05}, {"price": 5.7, "size": 707.38}, {"price": 5.8, "size": 197.76}, {"price": 5.9, "size": 217.39}, {"price": 6.0, "size": 497.37}, {"price": 6.2, "size": 119.73}]}, "lastPriceTraded": 6.0}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 22381578, "sp": {"nearPrice": 6.0, "backStakeTaken": [{"price": 1.01, "size": 65.0}, {"price": 6.6, "size": 20.0}, {"price": 14.5, "size": 15.0}], "farPrice": 3.990612903225806, "layLiabilityTaken": [{"price": 1000.0, "size": 92.71}, {"price": 1.08, "size": 31.79}]}, "totalMatched": 1809.66, "adjustmentFactor": 11.628, "ex": {"availableToBack": [{"price": 5.8, "size": 72.78}, {"price": 5.7, "size": 108.21}, {"price": 5.6, "size": 113.49}], "availableToLay": [{"price": 5.9, "size": 44.4}, {"price": 6.0, "size": 112.02}, {"price": 6.2, "size": 50.49}], "tradedVolume": [{"price": 5.4, "size": 70.0}, {"price": 5.6, "size": 70.39}, {"price": 5.7, "size": 111.57}, {"price": 5.8, "size": 246.11}, {"price": 5.9, "size": 187.49}, {"price": 6.0, "size": 481.83}, {"price": 6.2, "size": 451.27}, {"price": 6.4, "size": 33.54}, {"price": 6.6, "size": 28.69}, {"price": 6.8, "size": 10.0}, {"price": 7.0, "size": 100.31}, {"price": 7.2, "size": 18.46}]}, "lastPriceTraded": 5.8}, {"status": "ACTIVE", "handicap": 0.0, "selectionId": 21949486, "sp": {"nearPrice": 88.37895780883844, "backStakeTaken": [{"price": 1.01, "size": 18.18}, {"price": 15.0, "size": 20.0}], "farPrice": 16.78793252652877, "layLiabilityTaken": [{"price": 1000.0, "size": 606.63}, {"price": 1.08, "size": 31.79}]}, "totalMatched": 184.85, "adjustmentFactor": 3.135, "ex": {"availableToBack": [{"price": 100.0, "size": 9.33}, {"price": 90.0, "size": 25.58}, {"price": 70.0, "size": 48.97}], "availableToLay": [{"price": 120.0, "size": 8.67}, {"price": 130.0, "size": 15.0}, {"price": 180.0, "size": 14.72}], "tradedVolume": [{"price": 95.0, "size": 20.54}, {"price": 100.0, "size": 27.07}, {"price": 110.0, "size": 10.44}, {"price": 120.0, "size": 27.55}, {"price": 130.0, "size": 66.89}, {"price": 140.0, "size": 17.9}, {"price": 150.0, "size": 7.96}, {"price": 180.0, "size": 6.36}, {"price": 190.0, "size": 0.16}]}, "lastPriceTraded": 120.0}]}]}'  # pylint: disable=line-too-long
    )
Exemplo n.º 8
0
 def __get_first_record(self):
     with open(self.__file, "r", encoding="utf-8") as file:
         return make_dict(next(file))
Exemplo n.º 9
0
 def __get_first_bz2_record(self):
     with bz2.open(self.__file, "r") as file:
         return make_dict(next(file))
Exemplo n.º 10
0
 def __is_valid(self, line):
     return True if make_dict(line) else False
Exemplo n.º 11
0
 def __get_contents(self, file):
     return [
         make_dict(line) for line in file.readlines()
         if self.__is_valid(line)
     ]