Download the PHP package cfxmarkets/php-brokerage-sdk without Composer

On this page you can find all versions of the php package cfxmarkets/php-brokerage-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-brokerage-sdk

CFX Markets Brokerage SDK for PHP

A public PHP SDK to access the CFX Markets brokerage API

This libraries helps to facilitate interactions with the CFX Brokerage through CFX's brokerage REST api. While the API may be used directly, it is much easier to use via this SDK because the SDK handles the details of routing and protocol conformity, and also provides a more intuitive, object-based means of access and input validation.

Before diving in, there are a few things to note about the way the SDK works:

  1. It throws exceptions. You should assume that all actions return the expected results, and you should be prepared to handle exceptions if they're thrown. Exceptions are documented at the code level, so make sure to read up on them before hand, and make sure at very least that you're handling general exceptions at an application level to avoid unpleasant system output to the user. Here are a few of the common ones:
    • \\CFX\\Persistence\\ResourceNotFoundException -- thrown when an attempt is made to get a resource that doesn't exist (e.g., $cfx->users->get('non-existent')).
    • \\CFX\\BadInputException -- thrown when an attempt is made to save a resource that has user input errors. Includes a getInputErrors method that returns the raw array of jsonapi format errors.
  2. The SDK is broken into a three-part hierarchy: Context > Datasource > Resource. The Context ($cfx in the examples below) is responsible for facilitating interactions between various types of resources; the Datasource ($cfx->users, $cfx->assets, etc...) is responsible for managing persistence and inflation ("unpersistence") for specific resources; and the Resource (returned by $cfx->assets->get('ASST001'), $cfx->users->create(), etc...) is responsible for providing an intuitive and meaningful interface for use of the data within a system.
  3. User input errors happen at the Resource level, and can be explored using the hasErrors(string $field = null) : bool, numErrors($field = null) : int, and getErrors($field = null) : array methods. The same methods are used on save to produce a \\CFX\\BadInputException, so instead of checking for errors manually, you can simply catch that exception if/when it's thrown.

Examples

The best way to understand the SDK's usage is by example. Following is a step-by-step example guide for how to perform the "Sell Now" functionality in the CFX system, which allows partners to input information into the CFX system that leads to a valid, active sell order for a user's holdings.

Instantiating the Context

The first thing you'll need to do to use the CFX SDK is instantiate the context. For this, you'll need the API url (either https://sandbox.apis.cfxtrading.com or https://apis.cfxtrading.com, depending on whether or not you're in production), your api key and secret, and an optional Guzzle5.3 HTTP Client instance (the last parameter, only if you want to specify special options):

Now you can move on to the rest of the flow.

1. Add the User to Our System

The first thing you'll need to do is make sure your user is in our system. For each of your users that you add to our system, you'll get back that user's CFX User ID and an OAuth token giving you access to manage the user's account. You should store both of these in your users table for future use.

Assuming you don't already have them in your table, you should proceed to create the user in our system:

Now that you have a valid OAuth token, you can use it to go through the rest of the process for the user.

2. List or Manage Assets

At this point, you might want to make sure the asset your user is interested in selling is in our system. You'll do that by searching for the asset, then creating an "Asset Intent"[^1] if you don't find results:

3. Order Intent

Now you've got a valid CFX user, an asset or asset intent, and presumably you've got everything else you need to initiate an order intent, so let's do it:

4. Legal Information, Bank Account, ID Documents, Ownership Documents, and Agreement Document

An order intent can't actually be converted into a live order until we've got a number of other pieces of information from the user. These include their SSN (or the tax id of the entity that owns the asset they're selling), their address, their legal name as it appears on their statement, a verified bank account, and a number of documents. Here's what all that might look like in code:

NOTE: Document handling in the current version of the API is not ideal. In future versions, you'll create a document, then attach it to a legal entity or an order intent as necessary, and this will trigger updating of that legal entity or intent. As it stands, though, you have to attach the order intent or legal entity to the document, which does not trigger updating of the order intent or legal entity. Because of this, you may have to manually refresh the order intent to see whether or not it now has a valid order. You can do this by calling $intent = $cfx->orderIntents->get("id=".$intent->getId());


Footnotes

[^1]: Since brokerage partners aren't allowed to create arbitrary assets in the system, they have to request that CFX create an asset for them. They do this using an AssetIntent.


All versions of php-brokerage-sdk with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
psr/http-message Version ~1.0
cfxmarkets/php-persistence Version ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.6.0
cfxmarkets/php-public-models Version ^1.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cfxmarkets/php-brokerage-sdk contains the following files

Loading the files please wait ....