Coinmonks
Published in

Coinmonks

CCXT Cryptocurrency Trading — Limit Orders and Market Orders [Tutorial]

Discover and review best Trading automation softwares

Limit Orders

CCXT Examples

import ccxtbittrex = ccxt.bittrex({
'apiKey': '...',
'secret': '...',
})
# fetch your account balances for each asset
account_balance = bittrex.fetch_balance()
# execute the order
limit_order_placement = bittrex.create_limit_buy_order('ETH/BTC', '0.01', '0.014'))
account_balance = bittrex.fetch_balance()orderbook = bittrex.fetch_order_book('ETH/BTC')

Shrimpy Examples

Install

pip install shrimpy-python

Example

import shrimpy
import time
# use your Shrimpy API public and private keys to create the client
public_key = '...' # shrimpy_public_key (aka Shrimpy Master Key)
secret_key = '...' # shrimpy_secret_key (aka Shrimpy Master Key)
client = shrimpy.ShrimpyApiClient(public_key, secret_key)# create a new user
user = client.create_user(
'mycustomname' # (optional) name
)
# link up to 20 exchange accounts for each user
account = client.link_account(
user['id'], # user_id
'bittrex', # exchange
'...', # public_key (aka exchange apiKey)
'...' # private_key (aka exchange secretKey)
)
# access balance data for each of your user's accounts
balance = client.get_balance(
user['id'], # user_id
account['id'] # account_id
)
# sleep for 5 seconds the first time linking an account
time.sleep(5)
# place an IOC or GTC limit order for your user
place_limit_order_response = client.place_limit_order(
user['id'], # user_id
account['id'], # account_id
'ETH', # base_symbol
'BTC', # quote_symbol
'0.01', # quantity of base_symbol
'0.026', # price
'SELL', # side
'IOC' # time_in_force ('IOC' or 'GTC')
)
orderbooks = client.get_orderbooks(
'bittrex', # exchange
'ETH', # base_symbol
'BTC', # quote_symbol
10 # limit of how much depth to return on each side
)
client.allocate(
'701e0d16-1e9e-42c9-b6a1-4cada1f395b8', # user_id
123, # account_id
{
'isDynamic': False,
'allocations': [
{ 'symbol': 'BTC', 'percent': '100' }
]
}
)

Market Orders

That means if you want to sell LTC to buy BTC, the exchange will continue selling LTC at the market rate until it reaches the order size you specified.

CCXT Example

import ccxtbittrex = ccxt.bittrex({
'apiKey': '...',
'secret': '...',
})
# get account balances to determine how much can be traded
account_balance = bittrex.fetch_balance()
# sell .001 ETH for market price and receive BTC right now
market_order_placement = bittrex.create_market_sell_order('ETH/BTC', .001)

Shrimpy Example

import shrimpy# use your Shrimpy API public and private keys to create the client
public_key = '...'
secret_key = '...'
client = shrimpy.ShrimpyApiClient(public_key, secret_key)# note: since we created a user in our last example script,
# we can just retrieve our list of users.
users = client.list_users()
first_user_id = users[0]['id']
# retrieve the accounts associated with this user
accounts = client.list_accounts(
first_user_id
)
first_account_id = accounts[0]['id']
# access balance data for the user account you previously created
balance = client.get_balance(
first_user_id, # user_id
first_account_id # account_id
)
# execute a market order
smart_order_response = client.create_trade(
first_user_id, # user_id
first_account_id, # account_id
'BTC', # from_symbol
'ETH', # to_symbol
'0.01' # amount of from_symbol
)

Smart Trading

It’s so easy!

import shrimpy# use your Shrimpy API public and private keys to create the client
public_key = '...'
secret_key = '...'
client = shrimpy.ShrimpyApiClient(public_key, secret_key)# note: since we created a user in our last example script,
# we can just retrieve our list of users.
users = client.list_users()
first_user_id = users[0]['id']
# retrieve the accounts associated with this user
accounts = client.list_accounts(
first_user_id
)
first_account_id = accounts[0]['id']
# access balance data for the user account you previously created
balance = client.get_balance(
first_user_id, # user_id
first_account_id # account_id
)
# execute a market order
smart_order_response = client.create_trade(
first_user_id, # user_id
first_account_id, # account_id
'BTC', # from_symbol
'ETH', # to_symbol
'0.01' # amount of from_symbol
True # enable smart_routing
)

Get Best Software Deals Directly In Your Inbox

--

--

Coinmonks (http://coinmonks.io/) is a non-profit Crypto Educational Publication. Follow us on Twitter @coinmonks and Our other project —  https://coincodecap.com, Email  — gaurav@coincodecap.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ShrimpyApp

Shrimpy is a crypto exchange trading bot for portfolio management, indexing the market, rebalancing, and strategy backtesting. Join now at shrimpy.io.