Skip to content

Update and rename Leo_Even_Odd.xml to LeoclassEven_Odd.xml#7

Open
Kingsleycoman254 wants to merge 1 commit intoDerivBots:mainfrom
Kingsleycoman254:patch-1
Open

Update and rename Leo_Even_Odd.xml to LeoclassEven_Odd.xml#7
Kingsleycoman254 wants to merge 1 commit intoDerivBots:mainfrom
Kingsleycoman254:patch-1

Conversation

@Kingsleycoman254
Copy link

import requests

API endpoint URLs

API_BASE_URL = "https://trade.deriv.com/api/"
AUTH_ENDPOINT = API_BASE_URL + "oauth2/token"
TRADE_ENDPOINT = API_BASE_URL + "trading/v3/order"

Your API credentials

CLIENT_ID = "your_client_id"
CLIENT_SECRET = "your_client_secret"
GRANT_TYPE = "client_credentials"

Authenticate

def authenticate():
data = {
"grant_type": GRANT_TYPE,
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET
}
response = requests.post(AUTH_ENDPOINT, data=data)
return response.json()

Place trade

def place_trade(token, symbol, amount, contract_type):
headers = {"Authorization": f"Bearer {token}"}
data = {
"amount": amount,
"symbol": symbol,
"type": contract_type
}
response = requests.post(TRADE_ENDPOINT, headers=headers, json=data)
return response.json()

Example usage

if name == "main":
auth_response = authenticate()
access_token = auth_response["access_token"]
# Place trades using the access_token
# Example: place_trade(access_token, "even", 100, "CALL")

import requests

# API endpoint URLs
API_BASE_URL = "https://trade.deriv.com/api/"
AUTH_ENDPOINT = API_BASE_URL + "oauth2/token"
TRADE_ENDPOINT = API_BASE_URL + "trading/v3/order"

# Your API credentials
CLIENT_ID = "your_client_id"
CLIENT_SECRET = "your_client_secret"
GRANT_TYPE = "client_credentials"

# Authenticate
def authenticate():
    data = {
        "grant_type": GRANT_TYPE,
        "client_id": CLIENT_ID,
        "client_secret": CLIENT_SECRET
    }
    response = requests.post(AUTH_ENDPOINT, data=data)
    return response.json()

# Place trade
def place_trade(token, symbol, amount, contract_type):
    headers = {"Authorization": f"Bearer {token}"}
    data = {
        "amount": amount,
        "symbol": symbol,
        "type": contract_type
    }
    response = requests.post(TRADE_ENDPOINT, headers=headers, json=data)
    return response.json()

# Example usage
if __name__ == "__main__":
    auth_response = authenticate()
    access_token = auth_response["access_token"]
    # Place trades using the access_token
    # Example: place_trade(access_token, "even", 100, "CALL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant