Link

ClearLoop

  1. List of supported exchanges

     + GET /platform/delegated-organizations
        
     + Response 200 OK
       {
         "organizations": [
           {
             "organizationId": "DRBT",
             "name": "Deribit",
             "currencies": ["BTC", "ETH"],
             "fields": [{"name": "clientSecret"}]   // additional required fields
           },
           {
             "organizationId": "BITF",
             "name": "Bitfinex",
             "currencies": ["BTC", "USDT", "LTC", "BSV", "ETH"] 
           },
           {
             "organizationId": "XENA",
             "name": "Xena",
             "currencies": ["BTC", "USDT", "LTC"]
           }
         ]
       }
    
  2. Create new portfolio (account) for client

     + POST /platform/portfolios
        
     + Request
       {
        "portfolioId": "EB33434A-D8DB-4E8C-8F8A-58A867108DE9",    // uniq string. UUID for example
        "portfolioType": "trading",
        "portfolioName": "Adam Smith"
       }
    
  3. Delegate funds to exchange

     + POST /platform/delegated-funds
        
     + Request
       {
         "requestId": "2BAA2E63-D3EC-4DE0-8E2A-A253A2CAE16A",    // uniq request id, string. UUID for example
         "amount": "2.005",    // positive amount - delegate, negative — unlock back
         "currency": "BTC",
         "portfolioId": "EB33434A-D8DB-4E8C-8F8A-58A867108DE9",  // client's portfolioId 
         "delegatedOrganizationId": "DRBT",     // exchange's organizationId from /platform/delegated-organizations
         "clientAccountId": "777",   
         "clientSecret": "optional-secret-key"     // optional, required only for exchanges with "clientSecret" in fields and only once for one clientAccountId
       } 
    
  4. Unlock delegated funds

    The same request as described above, but with negative “amount”

     + POST /platform/delegated-funds
        
     + Request
       {
         "requestId": "720A55C4-30FB-4418-8B73-F12E4AD99AA5",     // uniq request id, string. UUID for example
         "amount": "-1",                                          // negative amount
         "currency": "BTC",
         "portfolioId": "EB33434A-D8DB-4E8C-8F8A-58A867108DE9",
         "delegatedOrganizationId": "DRBT",
         "clientAccountId": "777"
       } 
    
  5. Get all delegated funds

     + GET /platform/delegated-funds?portfolioId={portfolioId}       // filter by client's portfolioId 
        
     + Response 200 OK
       {
         "delegatedFunds": [
           {
             "itemId": "87",
             "currency": "BTC",
             "amount": "3.00456",
             "portfolioId": "EB33434A-D8DB-4E8C-8F8A-58A867108DE9",
             "walletId": "ck92vvxyc000a3g5mb74gcdjh",
             "organizationId": "MYORG1",
             "delegatedOrganizationId": "DRBT",
             "clientAccountId": "777"
           },
           {
             "itemId": "94",
             "currency": "LTC",
             "amount": "0",
             "portfolioId": "EB33434A-D8DB-4E8C-8F8A-58A867108DE9",
             "walletId": "ckhk923gsl3g5nn93720dx",
             "organizationId": "MYORG1",
             "delegatedOrganizationId": "XENA",
             "clientAccountId": "test-xena-acc-id123"
           }
         ]
       }
    
  6. Get wallet balances

     + GET /platform/wallets?portfolioId={portfolioId}       // filter by client's portfolioId 
        
     + Response 200 
       {
         "wallets": [
           {
             "walletId": "ck92vvxyc000a3g5mb74gcdjh",
             "portfolioId": "EB33434A-D8DB-4E8C-8F8A-58A867108DE9",
             "organizationId": "MYORG1"
             "currency": "BTC",
             "balance": "0",
             "reserve": "0",
             "locked": "3.00456",
             "available": "0",
             "_embedded": {
               "depositTargets": [
                 {
                   "targetType": "crypto",
                   "mainCurrency": "BTC",
                   "address": "1AkwMcn1akvxBPEKJixKnhKKaBoQxDPcy9"   // deposit address
                 }
               ]
             }
           },
           {
             "walletId": "ck92vvxyc000a3g5mb74gcdjh",
             "portfolioId": "EB33434A-D8DB-4E8C-8F8A-58A867108DE9",
             "organizationId": "MYORG1"
             "currency": "LTC",
             "balance": "120.4",
             "reserve": "0",
             "locked": "0",
             "available": "120.4",    // funds, available on client's balance for withdrawal
             "_embedded": {
               "depositTargets": [
                 {
                   "targetType": "crypto",
                   "mainCurrency": "LTC",
                   "address": "LSrkGU6dsVnjJ9oADMTBwKnALZSpMjxPs4"   // deposit address
                 }
               ]
             }
           }
         ]
       }
    
  7. Create withdrawal request

     + POST /platform/orders
        
     + Request
       {
         "externalOrderId": "be70d9a8-2290-4692-9592-0fd572f6e864",   // uniq string. UUID for example
         "orderType": "withdraw",
         "baseCurrency": "LTC",
         "amount": "10",
         "portfolioId": "EB33434A-D8DB-4E8C-8F8A-58A867108DE9",
         "toAddress": "rwCQk17fhC8G9UCoMgaxsEQb6fVy8HhUY6"
       }
    
  8. Get all settlement orders to be paid

    You have to send the appropriate amount of funds to address specified in the wallet _embedded.depositTargets. You can also summarize all orders in one currency and send the entire amount in one transaction.

    If you accidentally send more or less than necessary - that’s okay. You can either send the missing amount, or withdraw the excess at any time (see 7. Create withdrawal request)

    For orderType: sell you have to send amount of baseCurrency. For buy you have to send extra.totalQuoteAmount of quoteCurrency

    For simplify this process you can just use _embedded.debitingAmount and _embedded.debitingCurrency

     + GET /platform/orders?portfolioId={portfolioId}&status=waiting-funds
        
     + Response 200 OK
       {
         "orders": [
           {
             "orderId": "14697072",
             "externalOrderId": "ck2m90bpq000i3i5qwinf48ap",
             "status": "waiting-funds",
             "orderType": "sell",
             "organizationId": "MYORG1",
             "portfolioId": "EB33434A-D8DB-4E8C-8F8A-58A867108DE9",
             "portfolioType": "trading",
             "amount": "10",
             "baseCurrency": "BTC",
             "quoteCurrency": "USD",
             "limitType": "off-exchange",
             "priceLimit": "9542.55",
             "extra": {
               "counterpartyPortfolioId": "3E93C5DA-23B0-4544-8135-355CE230BDBF",
               "counterpartyOrderId": "14697073",
               "totalQuoteAmount": "954255",
               "daysToSettle": "0",
               "feesPercent": "0.05"
             },
             "createdAt": "1582824873675",
             "_embedded": {
               "debitingAmount": "10",      // send this amount 
               "debitingCurrency": "BTC"    // in this currency
             }
           }
         ],
         "total": "1"
       }
    
  9. Continue settlement for “waiting-funds” orders

    When all required funds will be debited and available you can execute order

     + PATCH /platform/orders/{orderId}
        
     + Header
       Content-Type: application/vnd.continue-settlement+json
        
     + Request
       {}
        
     + Response 200 OK
       {}