By using the BFS API it is possible to connect data between several external systems. In this article we will explore how to apply deposit orders of cash and associate these deposits with an allocation profile in BFS.

First we need to create an allocation profile and here we will use GetInstruments to collect the BFS-id's to be used in the Allocation Profile as AllocationItems.

We are going to filter on instrument type 2 which represents funds and we are only going to collect one ISIN which matches a test instrument called Fund A.

//Use the GetInstruments method to get all fund instruments and write their BFS-id's
//in the console
var client = new BFSServiceReference.bfsapiSoapClient();

var credentials = new BFSServiceReference.Credentials()
{
    UserName = bfsusername, //Username of administrative user in your instance of BFS
    Password = bfspassword, //Password of the administrative user in your instance of BFS
};

var accounts = client.GetInstruments(new BFSServiceReference.GetInstrumentsRequest()
{
    Credentials = credentials,

    identify = bfsidentifier, //Identifier is a unique token for your instance of BFS

    Args = new BFSServiceReference.GetInstrumentsArgs()
    {
        InstrumentType = 2,
        ISINs = new []
        {
            "SE1234123412"
        }
    },
    Fields = new BFSServiceReference.GetInstrumentsFields()
    {
        BrickId = true,
        Name = true
    },
});

foreach (var c in accounts.Result)
{
    Console.WriteLine(c.BrickId + ", " + c.Name);
}

The results look like the image below:

Now we are going to create the allocation profile and the code for this example is shown below:

//Create an allocation profile with the CreateAllocationProfiles method
var client = new BFSServiceReference.bfsapiSoapClient();

var credentials = new BFSServiceReference.Credentials()
{
    UserName = bfsusername, //Username of administrative user in your instance of BFS
    Password = bfspassword, //Password of the administrative user in your instance of BFS
};

var AI1 = new AllocationItem() //The only allocation item
{
    Asset = new Guid("138e92a5-f1d6-4473-9ca4-45f511881676"),
    AllocationPercentage = 1M
};

var response = client.CreateAllocationProfiles(new BFSServiceReference.CreateAllocationProfileRequest()
{
    Credentials = credentials,

    identify = bfsidentifier, //Identifier is a unique token for your instance of BFS        

    Entities = new[]
    {
        new AllocationProfile()
        {      
            Key = "Alloc1",
            Name = "My allocation",
            Owner = new Guid("0a39dc30-9e75-4261-920a-1398fb87c952"),
            AllocationItems = new []
            {
                AI1                
            },            
        },

    }

});

foreach (var c in response.Entities)
{
    Console.WriteLine(c.BrickId + "," + c.Errors);
}

The results are the following:

The allocation profile shows up in the GUI according to the image below:

The next step is for the external system to use CreateDepositCashOrder in to send a number of deposits to BFS where the deposits can be associated with Allocation Profiles and then orders to buy the products in the allocation profile will be created. 

In the example below we are creating one deposit order to deposit 100 SEK and another order to deposit 110 SEK. We are associating the second deposit with the allocation profile that we created above. All the deposit orders that we are sending to BFS are going to be linked together by a batch order. The BFS-id and the order number of the batch is being returned to the response object and could then be used for the actual bank transfer. When the bank transfer is ready by BFS the reference number can be matched to the batch order and the associated individual deposit orders can be activated and moved to the next state in the workflow.

The flow between the three systems are shown below:

The code for generating the deposits looks like this:

//Create two deposits with the CreateDepositCash method
var client = new BFSServiceReference.bfsapiSoapClient();

var credentials = new BFSServiceReference.Credentials()
{
    UserName = bfsusername, //Username of administrative user in your instance of BFS
    Password = bfspassword, //Password of the administrative user in your instance of BFS
};

var response = client.CreateDepositCashOrders(new BFSServiceReference.CreateDepositCashOrderRequest()
{
    Credentials = credentials,

    identify = bfsidentifier, //Identifier is a unique token for your instance of BFS        

    Entities = new[]
    {
        new DepositCashOrder()
        {
            AccountNo = "10032589",
            Amount = 100,
            CurrencyCode = "SEK",
            ExternalReference = "Deposit1"
        },
        new DepositCashOrder()
        {
            AccountNo = "10011484",           
            Amount = 110,
            CurrencyCode = "SEK",
            ExternalReference = "Test2",
            OrderSettlementType = OrderSettlementType.PAYMENT,
            AllocationProfileId = new Guid("ea03c9b6-e4f7-4c24-b7cb-1142fcd6faad"),
            LinkedAmount = 100M

        }
    }

});

//Show information about the batch order that was generated
Console.WriteLine(response.batchId + ", " + response.batchOrderNo);
//Show information about the individual deposit orders
Console.WriteLine("Orders:");
foreach (var c in response.Orders)
{
    Console.WriteLine(c.OrderId + ", " + c.OrderNo);
}

The results below show the created batch order first and then the individual orders that were created.

The GUI looks like this:

 

The next step is to process the batch order which would be automatically executed when the matching bank transfer file is imported.

For this article we can do this manually by navigating to the batch order and trigger the next workflow transition.

In the resulting ticket we will write the settlement date, value date and the custody account to use for the deposit.

The custody account now shows the aggregated deposit of 210 SEK while the individual deposits show on the BFS-accounts of the customer:

Customer BFS-account: