Exchange

Quickstart

from pprint import pprint
from steemexchange import SteemExchange

class Config():
    witness_url     = "wss://this.piston.rocks/"
    account         = "xeroc"
    # Either provide a cli-wallet RPC
    wallet_host     = "localhost"
    wallet_port     = 8092
    # or the (active) private key for your account
    wif             = ""

steem = SteemExchange(Config)
pprint(steem.buy(10, "SBD", 100))
pprint(steem.sell(10, "SBD", 100))
pprint(steem.cancel("24432422"))
pprint(steem.returnTicker())
pprint(steem.return24Volume())
pprint(steem.returnOrderBook(2))
pprint(steem.ws.get_order_book(10, api="market_history"))
pprint(steem.returnTradeHistory())
pprint(steem.returnMarketHistoryBuckets())
pprint(steem.returnMarketHistory(300))
pprint(steem.get_lowest_ask())
pprint(steem.get_higest_bid())
pprint(steem.transfer(10, "SBD", "fabian", "foobar"))

Definition

class steemexchange.exchange.SteemExchange(config, **kwargs)

This class serves as an abstraction layer for the decentralized exchange within the network and simplifies interaction for trading bots.

Parameters:config (config) – Configuration Class, similar to the example above

This class tries to map the poloniex API around the DEX but has some differences:

  • market pairs are denoted as ‘quote’_’base’, e.g. USD_BTS
  • Prices/Rates are denoted in ‘base’, i.e. the USD_BTS market is priced in BTS per USD. Example: in the USD_BTS market, a price of 300 means a USD is worth 300 BTS
  • All markets could be considered reversed as well (‘BTS_USD’)

Usage:

from steemexchange import SteemExchange
from pprint import pprint

class Config():
    wallet_host           = "localhost"
    wallet_port           = 8092
    #witness_url           = "ws://localhost:8090/"
    witness_url           = "wss://steemit.com/wstmp2"
    account = "xeroc"

steem = SteemExchange(Config)
pprint(steem.buy(10, "SBD", 100))
pprint(steem.sell(10, "SBD", 100))
pprint(steem.returnTicker())
pprint(steem.return24Volume())
pprint(steem.returnOrderBook(2))
pprint(steem.ws.get_order_book(10, api="market_history"))
pprint(steem.returnTradeHistory())
pprint(steem.returnMarketHistoryBuckets())
pprint(steem.returnMarketHistory(300))
pprint(steem.get_lowest_ask())
pprint(steem.get_higest_bid())
buy(amount, quote_symbol, rate, expiration=604800, killfill=False)

Places a buy order in a given market (buy quote, sell base in market quote_base). If successful, the method will return the order creating (signed) transaction.

Parameters:
  • amount (number) – Amount of quote to buy
  • quote_symbol (str) – STEEM, or SBD
  • price (float) – price denoted in base/quote
  • expiration (number) – (optional) expiration time of the order in seconds (defaults to 7 days)
  • killfill (bool) – flag that indicates if the order shall be killed if it is not filled (defaults to False)

Prices/Rates are denoted in ‘base’, i.e. the STEEM:SBD market is priced in SBD per STEEM.

Example: in the SBD:STEEM market, a price of 300 means a SBD is worth 300 STEEM

cancel(orderNumber)

Cancels an order you have placed in a given market. Requires only the “orderNumber”. An order number takes the form 1.7.xxx.

Parameters:orderNumber (str) – The Order Object ide of the form 1.7.xxxx
formatTimeFromNow(secs=0)

Properly Format Time that is x seconds in the future

Parameters:secs (int) – Seconds to go in the future (x>0) or the past (x<0)
Returns:Properly formated time for Graphene (%Y-%m-%dT%H:%M:%S)
Return type:str
getMyAccount()

Returns the structure containing all data relevant to the account specified in the configuration

get_higest_bid()

Return the highest bid.

Example:

{'SBD:STEEM': [{'price': 3.08643564387293, 'sbd': 320863, 'steem': 990323}],
 'STEEM:SBD': [{'price': '0.32399833185738391',
                'sbd': 320863,
                'steem': 990323}]}
get_lowest_ask()

Return the lowest ask.

Example:

{'SBD:STEEM': [{'price': 3.08643564387293, 'sbd': 320863, 'steem': 990323}],
 'STEEM:SBD': [{'price': '0.32399833185738391',
                'sbd': 320863,
                'steem': 990323}]}
myAccount = None

The trading account

return24Volume()

Returns the 24-hour volume for all markets, plus totals for primary currencies.

Sample output:

{'sbd_volume': 108329.611, 'steem_volume': 355094.043}
returnBalances()

Return SBD and STEEM balance of the account

returnMarketHistory(bucket_seconds=300, start_age=3600, stop_age=0)

Return the market history (filled orders).

Parameters:
  • bucket_seconds (int) – Bucket size in seconds (see returnMarketHistoryBuckets())
  • start_age (int) – Age (in seconds) of the start of the window (default: 1h/3600)
  • end_age (int) – Age (in seconds) of the end of the window (default: now/0)

Example:

{'close_sbd': 2493387,
 'close_steem': 7743431,
 'high_sbd': 1943872,
 'high_steem': 5999610,
 'id': '7.1.5252',
 'low_sbd': 534928,
 'low_steem': 1661266,
 'open': '2016-07-08T11:25:00',
 'open_sbd': 534928,
 'open_steem': 1661266,
 'sbd_volume': 9714435,
 'seconds': 300,
 'steem_volume': 30088443},
returnOpenOrders()

Return open Orders of the account

returnOrderBook(limit=25)

Returns the order book for the SBD/STEEM markets in both orientations.

Parameters:limit (int) – Limit the amount of orders (default: 25)

Sample output:

{'SBD:STEEM': {'asks': [{'price': 3.086436224481787,
                         'sbd': 318547,
                         'steem': 983175},
                        {'price': 3.086429621198315,
                         'sbd': 2814903,
                         'steem': 8688000}],
               'bids': [{'price': 3.0864376216446257,
                         'sbd': 545133,
                         'steem': 1682519},
                        {'price': 3.086440512632327,
                         'sbd': 333902,
                         'steem': 1030568}]},
 'STEEM:SBD': {'asks': [{'price': '0.32399827090802763',
                         'sbd': 318547,
                         'steem': 983175},
                        {'price': '0.32399896408839779',
                         'sbd': 2814903,
                         'steem': 8688000}],
               'bids': [{'price': '0.32399812424109331',
                         'sbd': 545133,
                         'steem': 1682519},
                        {'price': '0.32399782076056660',
                         'sbd': 333902,
                         'steem': 1030568}]}}
returnTicker()

Returns the ticker for all markets.

Output Parameters:

  • latest: Price of the order last filled
  • lowest_ask: Price of the lowest ask
  • highest_bid: Price of the highest bid
  • sbd_volume: Volume of SBD
  • steem_volume: Volume of STEEM
  • percent_change: 24h change percentage (in %)

Note

All prices returned by returnTicker are in the reveresed orientation as the market. I.e. in the SBD:STEEM market, prices are STEEM per SBD. That way you can multiply prices with 1.05 to get a +5%.

Sample Output:

{'SBD:STEEM': {'highest_bid': 3.3222341219615097,
               'latest': 1000000.0,
               'lowest_ask': 3.0772668228742615,
               'percent_change': -0.0,
               'sbd_volume': 108329611.0,
               'steem_volume': 355094043.0},
 'STEEM:SBD': {'highest_bid': 0.30100226633322913,
               'latest': 0.0,
               'lowest_ask': 0.3249636958897082,
               'percent_change': 0.0,
               'sbd_volume': 108329611.0,
               'steem_volume': 355094043.0}}
returnTradeHistory(time=3600, limit=100)

Returns the trade history for the internal market

Parameters:
  • hours (int) – Show the last x seconds of trades (default 1h)
  • limit (int) – amount of trades to show (<100) (default: 100)
sell(amount, quote_symbol, rate, expiration=604800, killfill=False)

Places a sell order in a given market (sell quote, buy base in market quote_base). If successful, the method will return the order creating (signed) transaction.

Parameters:
  • amount (number) – Amount of quote to sell
  • quote_symbol (str) – STEEM, or SBD
  • price (float) – price denoted in base/quote
  • expiration (number) – (optional) expiration time of the order in seconds (defaults to 7 days)
  • killfill (bool) – flag that indicates if the order shall be killed if it is not filled (defaults to False)

Prices/Rates are denoted in ‘base’, i.e. the STEEM:SBD market is priced in SBD per STEEM.

Example: in the SBD:STEEM market, a price of 300 means a SBD is worth 300 STEEM

transfer(amount, asset, recepient, memo='')

Transfer SBD or STEEM to another account

Parameters:
  • amount (float) – Amount to transfer
  • asset (str) – Asset to transfer (“SBD” or “STEEM”)
  • recepient (str) – Recepient of the transfer
  • memo (str) – (Optional) Memo attached to the transfer