Developer Interface

Info

class snowman.Info(symbol, session=None)[source]

the basic information of a portfolio.

Parameters:
  • symbol – the portfolio symbol, a string starting with ‘ZH’
  • session – (optional) the session object responsible for http(s) connection

Usage:

>>> from snowman import Info
>>> info = Info('ZH123456')
>>> info.get()
>>> info.owner()
>>> info.holdings()
get(origin=False, update=False)[source]

request the data when necessary, cache the result and return it.

Parameters:
  • origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
  • update – (optional, defaults to False) try to reuse the cache if update is false, otherwise, request and update the cache.
Return type:

dict

holdings(origin=False)[source]

return the current holdings of the portfolio, which is contained as a part of the basic information.

Parameters:origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
Return type:dict
owner(origin=False)[source]

return the owner information which is contained as a part of the basic information.

Parameters:origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
Return type:dict

Profit

class snowman.Profit(symbol, session=None)[source]

the profit history of a portfolio.

Parameters:
  • symbol – the portfolio symbol, a string starting with ‘ZH’
  • session – (optional) the session object responsible for http(s) connection

Usage:

>>> from snowman import Profit
>>> pft = Profit('ZH123456')
>>> pft.get() # return all the profit history
>>> pft.get(10) # return the profit history in the latest 10 days.
get(num=0, origin=False, update=False)[source]

request the profit history data when necessary, cache the data and return it.

Parameters:
  • num – num param only works when origin is False, can’t be negative. When num is 0, return the history data starting from the creation date of the portfolio, when num is postive integer N, only return the history data starting from N num ago.
  • origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
  • update – (optional, defaults to False) try to reuse the cache if update is false, otherwise, request and update the cache.
Return type:

list

Analysis

class snowman.Analysis(symbol, session=None)[source]

the analysis information of a portfolio.

Parameters:
  • symbol – the portfolio symbol, a string starting with ‘ZH’
  • session – (optional) the session object responsible for http(s) connection

Usage:

>>> from snowman import Analysis
>>> ana = Analysis('ZH123456')
>>> ana.benefit() # return benefit analysis data
>>> ana.turnover() # return turnover analysis data
>>> ...
all(page=1, count=5, origin=False)[source]

update all the caches, and return all analysis data in a single dict.

Parameters:
  • page – (optional, defaults to 1) this only affect the data for top stocks. this param works with count param. if page is N, the result is stocks ranking between [(N - 1) * count + 1, N * count] so when page is 1, the result is top [count] stocks.
  • count – (optional, defaults to 5) this only affect the data for top stocks. Check page param.
  • origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
  • update – (optional, defaults to False) try to reuse the cache if update is false, otherwise, request and update the cache.
Return type:

dict

benefit(origin=False, update=False)[source]

benefit analysis data

Parameters:
  • origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
  • update – (optional, defaults to False) try to reuse the cache if update is false, otherwise, request and update the cache.
Return type:

list

liquidity(origin=False, update=False)[source]

liquidity analysis data

Parameters:
  • origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
  • update – (optional, defaults to False) try to reuse the cache if update is false, otherwise, request and update the cache.
Return type:

dict if origin is True, otherwise an float number

max_draw(origin=False, update=False)[source]

max draw analysis data

Parameters:
  • origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
  • update – (optional, defaults to False) try to reuse the cache if update is false, otherwise, request and update the cache.
Return type:

dict

top_stocks(page=1, count=5, origin=False, update=False)[source]

volatility analysis data

Parameters:
  • page – (optional, defaults to 1) this param works with count param. if page is N, the result is stocks ranking between [(N - 1) * count + 1, N * count] so when page is 1, the result is top [count] stocks.
  • count – (optional, defaults to 5) check page param.
  • origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
  • update – (optional, defaults to False) try to reuse the cache if update is false, otherwise, request and update the cache.
Return type:

dict if origin is True, otherwise list

turnover(origin=False, update=False)[source]

turnover analysis data

Parameters:
  • origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
  • update – (optional, defaults to False) try to reuse the cache if update is false, otherwise, request and update the cache.
Return type:

dict if origin is True, otherwise an float number

volatility(origin=False, update=False)[source]

volatility analysis data

Parameters:
  • origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
  • update – (optional, defaults to False) try to reuse the cache if update is false, otherwise, request and update the cache.
Return type:

dict if origin is True, otherwise an float number

History

class snowman.History(symbol, session=None)[source]

the rebalancing history information of a portfolio.

Parameters:
  • symbol – the portfolio symbol, a string starting with ‘ZH’
  • session – (optional) the session object responsible for http(s) connection

Usage:

>>> from snowman import History
>>> his = History('ZH123456')
>>> his.get() #query all the rebalancing records of portfolio ZH123456.
>>> his.get(10) #query the latest 10 records of portfolio ZH123456
>>> his.get(10, 1, 3) 
>>> # query the latest 10 records,  if there are no less than 12 records, 
>>> # 4 requests will be sent,the count of result will be 12.
>>> # otherwise, just return all the records.
>>> his.get(origin = True) # return all the records in origin version.
>>> his.get(page = 1, count = 3) #return all the records, query 3 records each time.
be_login()[source]

make sure snowman has logined xueqiu.com.

get(num=0, page=1, count=20, origin=False, update=False)[source]

request the history data when necessary, cache the data and return it.

Parameters:
  • num – (optional, defaults to 0) this param specifies how many rebalance records snowman needs to query at least. The actual count of the result depends on history, page and count. these three works together to decide the result. when num is 0, all the records will be queried.
  • page – (optional, defaults to 1) this param works with count param, each request will return all the records in the range [(page - 1) * count + 1, page * count]. When num is positive number N, snowman will send mutliple requests, each request return count records. After the last request, the total number of records is (page * count), which will be not smaller than num or there are no more records.
  • count – (optional, defaults to 20) check param page.
  • origin – (optional, defaults to False) return the origin data from the api when origin is true, otherwise, return a simple customed version.
  • update – (optional, defaults to False) try to reuse the cache if update is false, otherwise, request and update the cache.
Return type:

dict