CampBX¶
About¶
This library provides python bindings for the CampBX bitcoin trading platform. To obtain API access please see the documenation at CampBX.
Note
All endpoints that require authentication are using HTTPS.
Installation¶
pip install campbx
Quick Usage¶
The API does not require a username and password, however you will have limited access to only the public endpoints.
Initializing the API:
from campbx import CampBX
c = CampBX('username', 'password')
Getting market ticker:
c.xticker()
{'Best Ask': '5.17', 'Best Bid': '5.07', 'Last Trade': '5.07'}
Check your account balance:
c.my_funds()
{'Liquid BTC': '0.00000000',
'Liquid USD': '2.19',
'Margin Account BTC': '0.00000000',
'Margin Account USD': '0.00',
'Total BTC': '15.00000000',
'Total USD': '74.58'}
Check your open orders:
c.my_orders()
{'Buy': [{'Dark Pool': 'No',
'Fill Type': 'Incremental',
'Margin Percent': 'None',
'Order Entered': '2012-04-10 08:59:51',
'Order Expiry': '2012-05-11 00:00:00',
'Order ID': '239801',
'Order Type': 'Quick Buy',
'Price': '4.50',
'Quantity': '16.00000000',
'Stop-loss': 'No'}],
'Sell': [{'Dark Pool': 'No',
'Fill Type': 'Incr',
'Margin Percent': 'None',
'Order Entered': '2012-04-05 22:07:05',
'Order Expiry': '2012-05-06 00:00:00',
'Order ID': '215603',
'Order Type': 'Quick Sell',
'Price': '5.20',
'Quantity': '15.00000000',
'Stop-loss': 'No'}]}
Debug Mode¶
To turn debug mode on and see more verbose output just use debug_mode:
c.debug_mode(True)
Endpoints¶
Marketing Data¶
These endpoints are public. Username and password are not required. You can use them to retrieve current market data such as price, last trade, etc.
Depth Table¶
Full market depth. Each element in these two arrays has two members: first member is Price and second member is Quantity available at that price. Both numbers are rounded to two decimal points.
Usage:
c.xdepth()
Output:
{'Asks': [[6.5, 9.0],
[6, 19.5],
[5.5, 5.0],
[5.4, 17.95838012],
[5.3, 2.0],
[5.25, 2.0],
[5.24, 2.0],
[5.23, 2.0],
[5.22, 2.0],
[5.2, 16.33884797],
[5.17, 128.98382722],
[5.16, 8.71]],
'Bids': [[5.13, 51.96],
[5.12, 54.33980295],
[5.11, 205.0],
[5.1, 6.57211378],
[5.07, 1.5],
[5.06, 2.0],
[5.03, 2.0],
[5, 2.3],
[4.91, 3.0],
[4.9, 24.7],
[4.81, 22.63227921],
[4.77, 14.5947811],
[4.76, 10.0],
[4.75, 10.41848778],
[4.74, 1.0],
[4.5, 30.0],
[3, 83.0]]}
Market Ticker¶
Get the best ask, best bid, and last trade
Usage:
c.xticker()
Output:
{'Best Ask': '5.17', 'Best Bid': '5.13', 'Last Trade': '5.13'}
Account Data¶
Access balances, orders, and margin position. All account data enpoints require username and password.
Account Balances¶
Latest account balances
Usage:
c.my_funds()
Output:
{'Liquid BTC': '0.00000000',
'Liquid USD': '2.19',
'Margin Account BTC': '0.00000000',
'Margin Account USD': '0.00',
'Total BTC': '15.00000000',
'Total USD': '74.58'}
Orders List¶
Latest orders buy or sell.
Usage:
c.my_orders()
Output:
{'Buy': [{'Dark Pool': 'No',
'Fill Type': 'Incremental',
'Margin Percent': 'None',
'Order Entered': '2012-04-10 08:59:51',
'Order Expiry': '2012-05-11 00:00:00',
'Order ID': '239801',
'Order Type': 'Quick Buy',
'Price': '4.50',
'Quantity': '16.00000000',
'Stop-loss': 'No'}],
'Sell': [{'Dark Pool': 'No',
'Fill Type': 'Incr',
'Margin Percent': 'None',
'Order Entered': '2012-04-05 22:07:05',
'Order Expiry': '2012-05-06 00:00:00',
'Order ID': '215603',
'Order Type': 'Quick Sell',
'Price': '5.20',
'Quantity': '15.00000000',
'Stop-loss': 'No'}]}
Margin positions¶
Open margin positions
Usage:
c.my_margins()
Output:
{'Margins': [{'Info': 'No open Margin positions.'}]}
Advanced Orders¶
Execute advanced orders with more options
Required Parameters
- TradeMode - AdvancedBuy or AdvancedSell.
- Price - Decimal or Market. The price at which you are willing to buy or sell the Bitcoins.
- Quantity - The amount of Bitcoins to buy or sell.
Optional Parameters
- FillType - Incremental, AON, or FOK. Default is Incremental.
- DarkPool - Use darkpools. Yes or No. Default is No.
- Expiry - The expiraton on the order in the YYYY/MM/DD format.
Note
Allowed Expiry range is 1 Hour through 31 Days.
Note
Please note that all parameters are case-sensitive. CampBX highly recommends executing small trades and experimenting with all of the possible parameter values before implementing them in your strategy. Expiry date field allows using many relative and absolute values and offers a lot of flexibility. If this is something that you rely on heavily in your strategy, please contact CampBX for details about additional formats.
Usage:
c.trade_advanced({
'TradeMode': 'AdvancedBuy',
'Price': 'Market',
'Quantity': '16.00'
})
Output:
{'Success': '0'}
Fund Transfers¶
Send Bitcoins to other CampBX users, bitcoint addresses, or get your deposit address
Instant, Free Bitcoin Transfer¶
If you need to send Bitcoins to other CampBX users, CampBX recommend using this. This call provides two distinct advantages over the traditional method of sending Bitcoin to an address:
- You can send Bitcoin instantly - there is no need to wait for confirmations from the Bitcoin network.
- You do not need to pay miner fees to transfer Bitcoins.
Parameters
- CBXCode - A valid CampBX account code
- BTCAmt - A decimal amount less than your account balance
Usage:
c.send_instant({
'CBXCode': 'some_code',
'BTCAmt': '2.50',
})
API call returns “Success” if account-to-account transfer is successful. The transaction will appear in your timeline as “CBX Instant Send/Receive”.
Note
The default withdrawal limit is 500 Bitcoins per 24 hours, and it can be raised by submitting a ticket to the helpdesk.
Bitcoin desposits¶
Get your Bitcoin deposit address
Usage:
c.get_btc_address()
Output:
{'Success': 'your_deposit_address'}
Bitcoin send-to¶
Send Bitcoins to any address
Parameters:
* BTCTo - A valid Bitcoin address
* BTCAmt - A decimal amount less than your account balance
Usage:
c.send_btc({
'BTCTo': 'bitcoin_address',
'BTCAmt': '100.00',
})
Output:
{'Success': 'transfer_id'}
Note
The default withdrawal limit is 500 Bitcoins per 24 hours, and it can be raised by submitting a ticket to the helpdesk.
Quick sell/buy¶
Execute quick sell or quick buy orders. Cancel orders.
Canceling an open order¶
Cancel an order
Parameters
- Type - The order type. This is either Buy or Sell
- OrderID - The ID of the order. You can get this from c.my_orders() in Account Data.
Note
The parameters for this call are case-sensitive.
Usage:
c.trade_cancel({
'Type': 'Buy',
'OrderID': 239801
})
Output:
{'Success': 'Order ID 239801 was deleted successfully.'}
Placing a new order¶
Place a buy or sell order
Parameters
- TradeMode - QuickBuy or QuickSell
- Quantity - The amount of Bitcoins to buy or sell
- Price - The price at which you are willing to buy or sell the Bitcoins.
Note
Orders stay open on CampBX order book for up to 31 days. Quantity and Price are decimal values that must follow all rules / limits set by CampBX. Minimum quantity to place an order is 0.1 Bitcoins.
Usage:
c.trade_enter({
'TradeMode': 'QuickSell',
'Quantity': '10.0',
'Price': '4.50'
})
Output:
{'Success': '0'}
Donations¶
If you would like to donate some coins, please donate to this address, 1EzebDR5wMvnSoQ5KQ1zF6UGcYr8qZSF4v
License¶
Copyright (c) 2011 Glen Zangirolami
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.