You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
order = client.create_order('EOSETH', 'buy', '10', order_type=args.ORDER_TYPE.MARKET)
51
+
# create a new spot order
52
+
order = client.create_spot_order('EOSETH', Side.BUY, '10', type=OrderType.MARKET)
49
53
```
50
54
51
-
## websocket client
52
-
53
-
All websocket calls work with callbacks, subscriptions use a callback with one argument for the subscription feed. All the other callbacks takes two arguments, err and result: callback(err, result). If the transaction is successful err is None and the result is in result. If the transaction fails, result is None and the error is in err.
54
-
55
-
There are three websocket clients, the PublicClient, the TradingClient and the AccountClient.
56
-
57
-
```python
58
-
from cryptomarket.websocket import PublicClient, TradingClient, AccountClient
59
-
60
-
# THE PUBLIC CLIENT
61
-
62
-
wsclient = PublicClient()
63
-
64
-
wsclient.connect() # blocks until connected
65
-
66
-
defmy_callback(err, data):
67
-
if err isnotNone: # deal with error
68
-
print(data)
69
-
70
-
# get currencies
71
-
wsclient.get_currencies(my_callback)
72
-
73
-
74
-
# get an order book feed,
75
-
# feed_callback is for the subscription feed, with one argument
76
-
# result_callback is for the subscription result (success or failure)
there are three websocket clients, `MarketDataClient`, the `TradingClient` and the `WalletClient`. The `MarketDataClient` is public, while the others require authentication to be used.
81
58
82
-
# THE TRADING CLIENT
59
+
Some subscription callbacks take a second argument, indicating the type of notification, either 'snapshsot' or 'update'.
83
60
84
-
wsclient = TradingClient(api_key, api_secret)
61
+
### MarketDataClient
85
62
86
-
wsclient.connect() # blocks until connected and authenticated.
63
+
There are no unsubscriptions methods for the `MarketDataClient`. To stop recieving messages is recomended to close the `MarketDataClient`.
from cryptomarket.exceptions import CryptomarketSDKException
112
165
113
166
client = Client(api_key, secret_key)
114
167
115
-
# catch a wrong argument
168
+
# catch a wrong argument
116
169
try:
117
170
order = client.create_order(
118
-
symbol='EOSETH',
171
+
symbol='EOSETH',
119
172
side='selllll', # wrong
120
173
quantity='3'
121
174
)
@@ -127,72 +180,40 @@ try:
127
180
order = client.create_order(
128
181
symbol='eosehtt', # non existant symbol
129
182
side='sell',
130
-
quantity='10',
183
+
quantity='10',
131
184
)
132
185
except CryptomarketSDKException as e:
133
186
print(f'exception catched {e}')
134
187
135
188
136
-
wsclient = TradingClient(api_key, api_secret)
137
-
138
-
# websocket errors are passed as the first argument to the callback
139
-
defcallback(err, result):
140
-
if err isnotNone:
141
-
print('an error ocurred')
142
-
print(err)
143
-
else:
144
-
print('successful transaction')
145
-
print(result)
189
+
client = WalletClient(api_key, api_secret)
190
+
try:
191
+
client.connect()
192
+
exceptExceptionas e:
193
+
# here we are catching connection and authentication errors
194
+
print(e)
195
+
```
146
196
147
-
wsclient.authenticate(callback=callback)
197
+
websocket methods take callbacks with two parameters, the first is the possible error, the second is the result of response from the server, for example:
148
198
149
-
# catch authorization error
150
-
# to catch an authorization error on client connection, a on_error function must be passed to the client
0 commit comments