How to connect forexconnect API to excel

Moderator: Moderator

How to connect forexconnect API to excel

Postby juniorlcq » Fri Dec 13, 2013 2:09 am

Hello , to whom may concern ,
I want to connect my excel files with FXCM MT4 's DDE server .

I had tick enable DDE server and allow my FXCM MT4 to run , but the data is not coming to my excel .
Here's what I type in my excel column , example ='MT4'|BID!GBPJPY ; the data is not coming to my excel files.
I had also tried running FXCM MT4 as administrator , that didn't work out either .










I saw that it is possible to do it with ForexConnect API , however I also need the COM files as I will be using excel's VBA ( I read this here http://fxcodebase.com/wiki/index.php/Us ... ect_in_COM)


I'd downloaded and installed ForexConnectAPI-1.3.0-win32 and also ForexConnectAPI-1.1.3-win32-COM


My problem now is 3 main thing .
1) How do I login with excel using forexconnect
2) How do I retrieve current live data to excel using forexconnect ( Like the one I mention above , but it should bit a slight different )
3) How do I get historical data to excel using forexconnect , is it possible for this historical data which had export to my excel files to refresh it AUTOMATICALLY every given time ( Let say I wanted to retrieve previous hour data from mt4 , can it overwrite the old data replace in with the new one automatically ? )




I hope I had explain my situation well .
Thank you .
juniorlcq
 
Posts: 6
Joined: Fri Dec 13, 2013 1:52 am

Re: How to connect forexconnect API to excel

Postby juniorlcq » Fri Dec 13, 2013 4:00 am

I reinstalled ForexConnectAPI-1.3.0-win32 and also ForexConnectAPI-1.1.3-win32-COM on my computer . ( I read that I need COM in order for my excel's VBA to work )


I found some VBA samples in there . Right now I'm still trying to login with ForexConnect COM , the live data and historical data will do it later . I think you will need to be able to login forexconnectcom with excel 1st in order for the live and historical data to be exported .



I face a problem when copying the code ( Login VBA samples ) into my excel's VBA .

------------------------------------------------------------------------------------
Option Explicit

Dim transport As transport
Dim WithEvents session As session
Dim LastSessionStatus As fxcore2_com.SessionStatusCode

Public Sub Login()
Call CheckState
If LastSessionStatus = SessionStatusCode_Connected Then
Range("Info").Value = "Please logout at the first"
Exit Sub
End If
'force login
If Range("Login").Value = "" Or Range("Password").Value = "" Then
Range("Info").Value = "Please provide login and password"
Exit Sub
End If
Call session.Login(Range("Login").Value, Range("Password").Value, Range("URL").Value, Range("Connection").Value)
Range("Info").Value = "Logged in..."

End Sub

Public Sub Logout()
If LastSessionStatus <> SessionStatusCode_Connected Then
Range("Info").Value = "Please login at the first"
Exit Sub
End If
Call session.Logout
End Sub

Private Sub Worksheet_Activate()
On Error GoTo Catch
Call CheckState
Exit Sub
Catch:
MsgBox Err.Description
End Sub

Private Sub CheckState()
If transport Is Nothing Then
Set transport = CreateObject("fxcore2.com.Transport")

'create session
Set session = transport.createSession()
Range("Status").Value = GetStatusName(LastSessionStatus)
End If
End Sub

Private Sub Worksheet_Deactivate()
On Error Resume Next
Set session = Nothing
Set transport = Nothing
End Sub

Private Sub session_SessionStatusChanged(ByVal status As SessionStatusCode)
On Error GoTo Catch
Range("Status").Value = GetStatusName(status)
Range("Info").Value = ""
LastSessionStatus = status
Exit Sub
Catch:
MsgBox Err.Description

End Sub

Private Sub session_SessionStatusLoginError(ByVal error As String)
Range("Info").Value = error
End Sub

Private Function GetStatusName(status As SessionStatusCode)
Select Case status
Case SessionStatusCode_Connected
GetStatusName = "connected"
Case SessionStatusCode_Disconnected
GetStatusName = "disconnected"
Case SessionStatusCode_Connecting
GetStatusName = "connecting"
Case SessionStatusCode_TradingSessionRequested
GetStatusName = "trading session requested"
Case SessionStatusCode_Disconnecting
GetStatusName = "disconnecting"
Case SessionStatusCode_SessionLost
GetStatusName = "session lost"
Case SessionStatusCode_PriceSessionReconnecting
GetStatusName = "price session reconnecting"
Case SessionStatusCode_Unknown
GetStatusName = "unknown"
Case Else
GetStatusName = CStr(status)
End Select
End Function

----------------------------------------------------------------------------------

I'm just a newbie in VBA language , do I don't really understand what's going on in here especially after the logout part ....


I had problem running the Login and Logout macro , and it is because of the
Dim WithEvents session As session


Not sure how to fix it .


Edit : I tried to remove "WithEvents " and then tried running the macro , then there's an error somewhere else , located at here

Set transport = CreateObject("fxcore2.com.Transport")
juniorlcq
 
Posts: 6
Joined: Fri Dec 13, 2013 1:52 am

Re: How to connect forexconnect API to excel

Postby Gennadiy » Sun Dec 15, 2013 10:52 pm

The issue has been resolved here.
Gennadiy
 

Re: How to connect forexconnect API to excel

Postby waleeedijaz » Wed Mar 02, 2016 2:38 am

Here's what I type in my excel column , example ='MT4'|BID!GBPJPY ; the data is not coming to my excel files.
waleeedijaz
 
Posts: 1
Joined: Wed Mar 02, 2016 2:36 am

Re: How to connect forexconnect API to excel

Postby Julia CJ » Wed Mar 02, 2016 5:57 am

Hi Waleeed,

Could you please clarify do you use FXCM MT4 's DDE server? If it is true , in this case I would recommend you to contact FXCM support or post this question on dailyfx.com forum pages.
Thank you.
Julia CJ
 


Return to ForexConnect API

Who is online

Users browsing this forum: No registered users and 9 guests