Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Subscribe to a Symbol and Receive Quotes in the Absence of Open Positions? #31

Open
FxMathSolution opened this issue Jan 23, 2024 · 3 comments

Comments

@FxMathSolution
Copy link

In the context of algorithmic trading, I've noticed that I receive a 'Symbol not Subscribed' alert when attempting to get quotes for a specific symbol (e.g., EURUSD) when there are no open positions for that pair. Is there a way to subscribe to a symbol and receive quotes even in the absence of open positions? What approach should be taken to ensure the availability of quotes for any given symbol?

Copy link

We're glad you've opened your first issue. Please provide all the necessary details and any relevant code or screenshots to help us understand the problem better. Our team will review your issue and provide assistance as soon as possible. Thank you for contributing!

@FxMathSolution
Copy link
Author

FxMathSolution commented Jan 23, 2024

I just testing this example:

api = Ctrader(server,account,password)
time.sleep(3)

checkConnection = api.isconnected()
print("Is Connected?: ", checkConnection)
time.sleep(1)

api.subscribe("EURUSD", "GBPUSD")


quote = api.quote()
print(quote)

# Buy position
price = api.quote()
price = price['EURUSD']['bid'] 

symbol = "EURUSD"
volume = 0.01 # position size:
stoploss =  round(price - 0.00010,6)
takeprofit = round(price + 0.00010,6)

id = api.buy(symbol, volume, stoploss, takeprofit)
print(f"Position: {id}")

# sell position 
price = api.quote()
price = price['EURUSD']['bid'] 

symbol = "EURUSD"
volume = 0.01 # position size
stoploss =  round(price + 0.00010,6)
takeprofit = round(price - 0.00010,6)

id = api.sell(symbol, volume, stoploss, takeprofit)
print(f"Position: {id}")

@FxMathSolution
Copy link
Author

I fixed it. Add a sleep here:

api.subscribe("EURUSD", "GBPUSD")
time.sleep(1)

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

No branches or pull requests

1 participant