The goal of mForex API is to provide flexible, asynchronous programming model for .NET based clients connecting to mForex Trade Server. This implementation is a thin layer over C# one, however it's optimized for convenient use from F#.
We are currently conducting beta tests, so our API is only available on demand for demo accounts only. If you would like to participate, please contact us on api@mforex.pl.
mForex API for F# is available on NuGet
Install-Package mForex.API.FSharp
Once you have your account ready, you can log in to our server are register for EURUSD ticks using following code:
//Firstly, you have to create an APIClient object, which will be used to communicate with the server.
let client = APIClient(ServerType.Demo)
//Every method returns Async<'T>, so they can be used to create an asynchronous workflow.
//When run, it will connect and login to the server.
let workflow = async {
do! client.Connect()
let! result = client.Login(login, password)
let! reg = client.RequestTickRegistration("EURUSD", RegistrationAction.Register)
}Once connection has been established and tick have been registered for, Ticks event, provided by APIClient, is ready to be subscribed for. For example, to receive and process every incoming tick of EURUSD one could:
client.Ticks.Add(fun p ->
p |> Seq.ofArray
|> Seq.filter (fun x -> x.Symbol = symbol)
|> Seq.iter ( fun x -> [...] )APIClient offers an easy way to manage your orders through an ITradeProvider interface. For example, sample code which closes all opened positions on EURUSD instrument could look like this:
let trades = (client.RequestOpenTrades() |> Async.RunSynchronously).Trades
let workflow = trades
|> Seq.ofArray
|> Seq.map(fun t -> client.Trade.CloseOrder(t.Order, t.Volume))
|> Async.ParallelNote, that you can schedule closing all orders without waiting for first response, which could significantly boost performance in your scenario.
The protocol used to communicate with mForex Trade Server is fundamentally asynchronous. It is implemented in F#'s idiomatic way, using Async<'T> workflows.
If you encounter any bugs or would like to propose any new features or enhancements, please visit the issue tracker and report the issue.
Copyright 2013 Dom Maklerski mBanku S.A. Licensed under the MIT License.
NOTE: You can find more information: