Esempio n. 1
0
 def assert_missing_parameter(self, parameter_name):
     temp_complete_proposal = copy.deepcopy(complete_rise_proposal)
     temp_complete_proposal.pop(parameter_name)
     proposal = json.dumps(temp_complete_proposal)
     proposal_result = tu.send_and_receive_ws(proposal)
     self.assertEqual(missing_parameter_message[parameter_name],
                      proposal_result["error"]["message"])
Esempio n. 2
0
def sell_last_bought_contract():
    json_contract_id = json.dumps({"portfolio": 1})
    result_contract_id = tu.send_and_receive_ws(json_contract_id)

    num_open_contract = len(result_contract_id['portfolio']['contracts'])

    if num_open_contract != 0:
        # get the contract id of last purchase contract
        contract_id = result_contract_id['portfolio']['contracts'][-1][
            'contract_id']

        # sell it
        json_sell_contract = json.dumps({"sell": contract_id, "price": 0})

        result_sell_contract = tu.send_and_receive_ws(json_sell_contract)

    else:
        result_sell_contract = "No open contract. Skipped selling contract"
        print(result_sell_contract)

    return result_sell_contract
Esempio n. 3
0
def buy(proposal):
    print_if_error(proposal)
    id = proposal['proposal']['id']

    json_buy = json.dumps({"buy": id, "price": 100})
    result_buy = tu.send_and_receive_ws(json_buy)

    print_if_error(result_buy)

    result_longcode = result_buy['buy']['longcode']

    return result_longcode
Esempio n. 4
0
    def test_forget_all(self):
        json_data = json.dumps({'forget_all': 'ticks'})
        result_js = tu.send_and_receive_ws(json_data)

        forget_all = result_js['forget_all']
        msg_type = result_js["msg_type"]

        expected_forget_all = []
        expected_msg_type = "forget_all"

        self.assertEqual(forget_all, expected_forget_all)
        self.assertEqual(msg_type, expected_msg_type)
Esempio n. 5
0
    def test_forget_all_3(self):
        json_data = json.dumps(
            {
                'forget_all': 'ticks'
            }
        )

        output = tu.send_and_receive_ws(json_data)
        msg_type = output["msg_type"]

        expected_msg_type = "forget_all"

        self.assertEqual(msg_type, expected_msg_type)
Esempio n. 6
0
def proposal_call_put(symbol, contract_type, duration, duration_unit):
    proposal = json.dumps({
        "proposal": 1,
        "amount": "10",
        "basis": "payout",
        "contract_type": contract_type,
        "currency": "USD",
        "duration": duration,
        "duration_unit": duration_unit,
        "symbol": symbol
    })

    proposal_result_js = tu.send_and_receive_ws(proposal)

    return proposal_result_js
Esempio n. 7
0
def proposal_lookback(symbol, contract_type):
    proposal = json.dumps({
        "proposal": 1,
        "amount": "1",
        "basis": "multiplier",
        "contract_type": contract_type,
        "currency": "USD",
        "duration": "1",
        "duration_unit": "m",
        "symbol": symbol
    })

    proposal_result_js = tu.send_and_receive_ws(proposal)

    return proposal_result_js
Esempio n. 8
0
def proposal_digit_even_odd(symbol, contract_type):
    proposal = json.dumps({
        "proposal": 1,
        "amount": "10",
        "basis": "payout",
        "contract_type": contract_type,
        "currency": "USD",
        "duration": 5,
        "duration_unit": "t",
        "symbol": symbol
    })

    proposal_result_js = tu.send_and_receive_ws(proposal)

    return proposal_result_js
Esempio n. 9
0
def proposal_highlow_tick(symbol, contract_type):
    proposal = json.dumps({
        "proposal": 1,
        "amount": "10",
        "basis": "payout",
        "contract_type": contract_type,
        "currency": "USD",
        "duration": "5",
        "duration_unit": "t",
        "selected_tick": "1",
        "symbol": symbol
    })

    proposal_result_js = tu.send_and_receive_ws(proposal)

    return proposal_result_js
Esempio n. 10
0
def find_latest_tick(symbol):
    # use tick_history API to get current spot
    spot = json.dumps({
        "ticks_history": symbol,
        "end": "latest",
        "start": 1,
        "style": "ticks",
        "adjust_start_time": 1,
        "count": 1
    })

    result_spot = tu.send_and_receive_ws(spot)
    current_spot = result_spot['history']['prices'][0]
    current_spot = float(current_spot)

    # note the current spot is float type.
    return current_spot
Esempio n. 11
0
def proposal_callput_spread(symbol, contract_type):
    proposal = json.dumps({
        "proposal": 1,
        "amount": "10",
        "basis": "payout",
        "contract_type": contract_type,
        "currency": "USD",
        "duration": "15",
        "duration_unit": "s",
        "barrier": "+7.51",
        "barrier2": "-6.48",
        "symbol": symbol
    })

    proposal_result_js = tu.send_and_receive_ws(proposal)

    return proposal_result_js
Esempio n. 12
0
    def test_forget_all_2(self):
        # json.dumps: python dict => json string
        json_data = json.dumps({'forget_all': 'ticks'})

        # ws.send(json_data)
        output = tu.send_and_receive_ws(
            json_data)  # return output in string format

        expected_output = {
            "echo_req": {
                "forget_all": "ticks"
            },
            "forget_all": [],
            "msg_type": "forget_all"
        }

        self.assertEqual(output, expected_output)
Esempio n. 13
0
    def test_indonesia(self):
        indonesia = json.dumps({"landing_company": "id"})
        landing_company_id = tu.send_and_receive_ws(indonesia)

        # remember to convert empty dict {} to None, else, result will fail ( {}!=None )
        expected_id = {
            "echo_req": {
                "landing_company": "id"
            },
            "landing_company": {
                "financial_company": {
                    "address":
                    None,
                    "country":
                    "Costa Rica",
                    "has_reality_check":
                    0,
                    "legal_allowed_contract_categories": [
                        "asian", "callput", "digits", "endsinout",
                        "staysinout", "touchnotouch", "lookback",
                        "highlowticks", "reset"
                    ],
                    "legal_allowed_currencies": [
                        "AUD", "BCH", "BTC", "DAI", "ETH", "EUR", "GBP", "LTC",
                        "USD"
                    ],
                    "legal_allowed_markets": [
                        "commodities",
                        "forex",
                        "indices",
                        # "stocks",
                        "volidx"
                    ],
                    "legal_default_currency":
                    "USD",
                    "name":
                    "Binary (C.R.) S.A.",
                    "shortcode":
                    "costarica"
                },
                "gaming_company": {
                    "address":
                    None,
                    "country":
                    "Costa Rica",
                    "has_reality_check":
                    0,
                    "legal_allowed_contract_categories": [
                        "asian", "callput", "digits", "endsinout",
                        "staysinout", "touchnotouch", "lookback",
                        "highlowticks", "reset"
                    ],
                    "legal_allowed_currencies": [
                        "AUD", "BCH", "BTC", "DAI", "ETH", "EUR", "GBP", "LTC",
                        "USD"
                    ],
                    "legal_allowed_markets": [
                        "commodities",
                        "forex",
                        "indices",
                        # "stocks",
                        "volidx"
                    ],
                    "legal_default_currency":
                    "USD",
                    "name":
                    "Binary (C.R.) S.A.",
                    "shortcode":
                    "costarica"
                },
                "id": "id",
                "mt_financial_company": {
                    "address": [
                        "Govant Building", "Port Vila", "P.O. Box 1276",
                        "Vanuatu", "Republic of Vanuatu"
                    ],
                    "country":
                    "Republic of Vanuatu",
                    "has_reality_check":
                    0,
                    "legal_allowed_contract_categories": ["callput"],
                    "legal_allowed_currencies": ["USD"],
                    "legal_allowed_markets": ["forex"],
                    "legal_default_currency":
                    "USD",
                    "name":
                    "Binary (V) Ltd",
                    "shortcode":
                    "vanuatu"
                },
                "mt_gaming_company": {
                    # "address": {},
                    "address":
                    None,
                    "country":
                    "Costa Rica",
                    "has_reality_check":
                    0,
                    "legal_allowed_contract_categories": [
                        "asian", "callput", "digits", "endsinout",
                        "staysinout", "touchnotouch", "lookback",
                        "highlowticks", "reset"
                    ],
                    "legal_allowed_currencies": [
                        "AUD", "BCH", "BTC", "DAI", "ETH", "EUR", "GBP", "LTC",
                        "USD"
                    ],
                    "legal_allowed_markets": [
                        "commodities",
                        "forex",
                        "indices",
                        # "stocks",
                        "volidx"
                    ],
                    "legal_default_currency":
                    "USD",
                    "name":
                    "Binary (C.R.) S.A.",
                    "shortcode":
                    "costarica"
                },
                "name": "Indonesia",
                "virtual_company": "virtual"
            },
            "msg_type": "landing_company"
        }

        # to convert python structure same as json output
        expected_id_ = json.dumps(expected_id)
        expected_landing_company_id = json.loads(expected_id_)

        self.assertTrue(
            tu.compare_data(landing_company_id, expected_landing_company_id),
            "Unmatch result")
Esempio n. 14
0
    def setUp(self):
        # test forget_all API
        self.input = json.dumps({"forget_all": "ticks"})

        self.output = tu.send_and_receive_ws(self.input)