77#
88
99"""
10- Module that implements some example usage for the Kraken Futures REST clients.
11-
12- This module may not be maintained on a regular basis, so please refer to the
13- unit tests of this package as they provide a much deeper dive into the usage.
10+ Module that implements *some* examples for the Kraken Futures REST clients
11+ usage.
1412"""
1513
1614import logging
3331
3432
3533def market_examples () -> None :
36- """Example market client usage"""
37- # market = Market()
38- # print(market.get_tick_types())
39- # print(market.get_tradeable_products(tick_type='trade'))
40- # print(market.get_resolutions(tick_type='trade', tradeable='PI_XBTUSD'))
41- # print(market.get_ohlc(tick_type='trade', symbol='PI_XBTUSD', resolution='5m', from_='1668989233'))
42- # print(market.get_fee_schedules())
43- # # print(market.get_orderbook(symbol='fi_xbtusd_180615')) # this endpoint is broken
44- # print(market.get_tickers())
45- # print(market.get_instruments())
46- # print(market.get_instruments_status())
47- # print(market.get_instruments_status(instrument='PI_XBTUSD'))
48- # print(market.get_trade_history(symbol='PI_XBTUSD'))
49- # print(market.get_historical_funding_rates(symbol='PI_XBTUSD'))
50- # time.sleep(2)
34+ """Example Futures Market client usage"""
5135
36+ # Usage of the Market client to access public endpoints:
37+ market = Market ()
38+ print (market .get_tick_types ())
39+ print (market .get_tradeable_products (tick_type = "trade" ))
40+ print (market .get_resolutions (tick_type = "trade" , tradeable = "PI_XBTUSD" ))
41+ print (
42+ market .get_ohlc (
43+ tick_type = "trade" ,
44+ symbol = "PI_XBTUSD" ,
45+ resolution = "5m" ,
46+ from_ = "1668989233" ,
47+ ),
48+ )
49+ print (market .get_fee_schedules ())
50+ print (
51+ market .get_orderbook (symbol = "fi_xbtusd_180615" ),
52+ ) # might need adjustment of the symbol
53+ print (market .get_tickers ())
54+ print (market .get_instruments ())
55+ print (market .get_instruments_status ())
56+ print (market .get_instruments_status (instrument = "PI_XBTUSD" ))
57+ print (market .get_trade_history (symbol = "PI_XBTUSD" ))
58+ print (market .get_historical_funding_rates (symbol = "PI_XBTUSD" ))
59+ time .sleep (2 ) # Just to avoid rate limits
60+
61+ # Usage of the Market client to access private endpoints:
62+ # (commented out to avoid accidental usage)
5263 priv_market = Market (key = key , secret = secret , sandbox = True )
5364 # print(priv_market.get_fee_schedules_vol())
5465 print (priv_market .get_leverage_preference ())
@@ -66,20 +77,25 @@ def market_examples() -> None:
6677
6778
6879def user_examples () -> None :
69- """Example User client usage"""
80+ """Example Futures User client usage"""
81+ # NOTE: This only works if you have set valid credentials for the the
82+ # Futures demo environment. Remove the `sandbox=True` argument to use
83+ # the production environment.
84+ #
85+ # Usage of the User client to access private endpoints:
7086 user = User (key = key , secret = secret , sandbox = True )
7187 print (user .get_wallets ())
72-
7388 print (user .get_subaccounts ())
7489 print (user .get_unwind_queue ())
7590 print (user .get_notifications ())
76-
7791 print (user .get_open_positions ())
7892 print (user .get_open_orders ())
7993
94+ # You can retrieve the account log like so:
8095 print (user .get_account_log (before = "1604937694000" ))
8196 print (user .get_account_log (info = "futures liquidation" ))
82- time .sleep (2 )
97+ time .sleep (2 ) # Just to avoid rate limits
98+
8399 response = user .get_account_log_csv ()
84100 assert response .status_code in {200 , "200" }
85101 with Path ("account_log.csv" ).open ("wb" ) as file :
@@ -89,10 +105,16 @@ def user_examples() -> None:
89105
90106
91107def trade_examples () -> None :
92- """Example Trade client usage"""
93- raise ValueError (
94- "Attention: Please check if you really want to execute the trade endpoints!" ,
108+ """Example Futures Trade client usage"""
109+ print (
110+ "Attention: Please check if you want to execute the trade endpoints!"
111+ " Check the script manually before running this example." ,
95112 )
113+ return
114+ # return
115+ # NOTE: This only works if you have set valid credentials for the the
116+ # Futures demo environment. Remove the `sandbox=True` argument to use
117+ # the production environment.
96118 trade = Trade (key = key , secret = secret , sandbox = True )
97119 print (trade .get_fills ())
98120 print (trade .get_fills (lastFillTime = "2020-07-21T12:41:52.790Z" ))
@@ -171,10 +193,11 @@ def funding_examples() -> None:
171193
172194
173195def main () -> None :
174- user_examples ()
175- market_examples ()
176- trade_examples ()
177- funding_examples ()
196+ """Uncomment the examples you want to run:"""
197+ # user_examples()
198+ # market_examples()
199+ # trade_examples()
200+ # funding_examples()
178201
179202
180203if __name__ == "__main__" :
0 commit comments