3333
3434
3535def 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)
36+ """Example Futures Market client usage"""
5137
38+ # Usage of the Market client to access public endpoints:
39+ market = Market ()
40+ print (market .get_tick_types ())
41+ print (market .get_tradeable_products (tick_type = "trade" ))
42+ print (market .get_resolutions (tick_type = "trade" , tradeable = "PI_XBTUSD" ))
43+ print (
44+ market .get_ohlc (
45+ tick_type = "trade" ,
46+ symbol = "PI_XBTUSD" ,
47+ resolution = "5m" ,
48+ from_ = "1668989233" ,
49+ ),
50+ )
51+ print (market .get_fee_schedules ())
52+ print (
53+ market .get_orderbook (symbol = "fi_xbtusd_180615" ),
54+ ) # might need adjustment of the symbol
55+ print (market .get_tickers ())
56+ print (market .get_instruments ())
57+ print (market .get_instruments_status ())
58+ print (market .get_instruments_status (instrument = "PI_XBTUSD" ))
59+ print (market .get_trade_history (symbol = "PI_XBTUSD" ))
60+ print (market .get_historical_funding_rates (symbol = "PI_XBTUSD" ))
61+ time .sleep (2 ) # Just to avoid rate limits
62+
63+ # Usage of the Market client to access private endpoints:
64+ # (commented out to avoid accidental usage)
5265 priv_market = Market (key = key , secret = secret , sandbox = True )
5366 # print(priv_market.get_fee_schedules_vol())
5467 print (priv_market .get_leverage_preference ())
@@ -66,20 +79,25 @@ def market_examples() -> None:
6679
6780
6881def user_examples () -> None :
69- """Example User client usage"""
82+ """Example Futures User client usage"""
83+ # NOTE: This only works if you have set valid credentials for the the
84+ # Futures demo environment. Remove the `sandbox=True` argument to use
85+ # the production environment.
86+ #
87+ # Usage of the User client to access private endpoints:
7088 user = User (key = key , secret = secret , sandbox = True )
7189 print (user .get_wallets ())
72-
7390 print (user .get_subaccounts ())
7491 print (user .get_unwind_queue ())
7592 print (user .get_notifications ())
76-
7793 print (user .get_open_positions ())
7894 print (user .get_open_orders ())
7995
96+ # You can retrieve the account log like so:
8097 print (user .get_account_log (before = "1604937694000" ))
8198 print (user .get_account_log (info = "futures liquidation" ))
82- time .sleep (2 )
99+ time .sleep (2 ) # Just to avoid rate limits
100+
83101 response = user .get_account_log_csv ()
84102 assert response .status_code in {200 , "200" }
85103 with Path ("account_log.csv" ).open ("wb" ) as file :
@@ -89,10 +107,16 @@ def user_examples() -> None:
89107
90108
91109def trade_examples () -> None :
92- """Example Trade client usage"""
93- raise ValueError (
94- "Attention: Please check if you really want to execute the trade endpoints!" ,
110+ """Example Futures Trade client usage"""
111+ print (
112+ "Attention: Please check if you want to execute the trade endpoints!"
113+ " Check the script manually before running this example." ,
95114 )
115+ return
116+ # return
117+ # NOTE: This only works if you have set valid credentials for the the
118+ # Futures demo environment. Remove the `sandbox=True` argument to use
119+ # the production environment.
96120 trade = Trade (key = key , secret = secret , sandbox = True )
97121 print (trade .get_fills ())
98122 print (trade .get_fills (lastFillTime = "2020-07-21T12:41:52.790Z" ))
@@ -171,10 +195,11 @@ def funding_examples() -> None:
171195
172196
173197def main () -> None :
174- user_examples ()
175- market_examples ()
176- trade_examples ()
177- funding_examples ()
198+ """Uncomment the examples you want to run:"""
199+ # user_examples()
200+ # market_examples()
201+ # trade_examples()
202+ # funding_examples()
178203
179204
180205if __name__ == "__main__" :
0 commit comments