import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import java.util.function.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import java.time.Duration;
import java.lang.invoke.VarHandle;
import java.lang.invoke.MethodHandles;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import static x30_pkg.x30_util.DynamicObject;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import java.text.*;
import java.text.NumberFormat;
import java.util.TimeZone;
import java.awt.geom.*;
class main {
static class BitGet {
String domain = "https://api.bitget.com";
String webSocketURL = "wss://ws.bitget.com/spot/v1/stream";
Timestamp serverTime() {
return new Timestamp(toLong(loadJSONMapPage(domain + "/api/spot/v1/public/time").get("data")));
}
// How much we are ahead or behind of the server's time
// (Note: includes network lag)
Duration serverTimeDifference() {
var serverTime = serverTime();
return tsNow().minusAsDuration(serverTime);
}
WebSocketClient printingWebSocketClient() { try {
return new PrintingWebSocketClient(new URI(webSocketURL));
} catch (Exception __e) { throw rethrow(__e); } }
String signMessage(String message, BitGetCredentials cred) {
return base64(hmacSHA256(message, hexToBytes(assertNempty(cred.secretKey()))));
}
Map loginRequest(BitGetCredentials cred) {
String timestamp = str(serverTime().unixSeconds());
String messageToSign = timestamp /* + "GET" + "/user/verify"*/;
String sign = signMessage(messageToSign, cred);
return litorderedmap(
"op" , "login",
"args" , ll(litorderedmap(
"apiKey" , assertNempty(cred.apiKey),
"passphrase" , assertNempty(cred.passphrase),
"timestamp", timestamp,
"sign", sign
)));
}
}
static long toLong(Object o) {
if (o instanceof Number)
return ((Number) o).longValue();
if (o instanceof String)
return parseLong((String) o);
return 0;
}
static Map loadJSONMapPage(String url) {
return jsonDecodeMap(loadPage(url));
}
static Map loadJSONMapPage(URLConnection urlConnection) {
return jsonDecodeMap(loadPage(urlConnection));
}
static Timestamp tsNow() {
return new Timestamp();
}
static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
static String base64(byte[] a) {
return base64encode(a);
}
static byte[] hmacSHA256(byte[] message, byte[] key) { try {
String algorithm = "HmacSHA256";
Mac mac = Mac.getInstance(algorithm);
mac.init(new SecretKeySpec(key, algorithm));
return mac.doFinal(message);
} catch (Exception __e) { throw rethrow(__e); } }
static byte[] hmacSHA256(String message, byte[] key) {
return hmacSHA256(toUtf8(message), key);
}
static byte[] hexToBytes(String s) {
if (odd(l(s))) throw fail("Hex string has odd length: " + quote(shorten(10, s)));
int n = l(s) / 2;
byte[] bytes = new byte[n];
for (int i = 0; i < n; i++) {
int a = parseHexChar(s.charAt(i*2));
int b = parseHexChar(s.charAt(i*2+1));
if (a < 0 || b < 0)
throw fail("Bad hex byte: " + quote(substring(s, i*2, i*2+2)) + " at " + i*2 + "/" + l(s));
bytes[i] = (byte) ((a << 4) | b);
}
return bytes;
}
static A assertNempty(A a) {
return assertNempty("empty", a);
}
static A assertNempty(String msg, A a) {
if (empty(a)) throw fail(msg + ": " + a);
return a;
}
static String str(Object o) {
return o == null ? "null" : o.toString();
}
static String str(char[] c) {
return new String(c);
}
static String str(char[] c, int offset, int count) {
return new String(c, offset, count);
}
static LinkedHashMap litorderedmap(Object... x) {
LinkedHashMap map = new LinkedHashMap();
litmap_impl(map, x);
return map;
}
static List ll(A... a) {
ArrayList l = new ArrayList(a.length);
if (a != null) for (A x : a) l.add(x);
return l;
}
static long parseLong(String s) {
if (empty(s)) return 0;
return Long.parseLong(dropSuffix("L", s));
}
static long parseLong(Object s) {
return Long.parseLong((String) s);
}
static Map jsonDecodeMap(String s) {
Object o = jsonDecode(s);
if (o instanceof List && empty((List) o))
return new HashMap();
if (o instanceof Map)
return (Map) o;
else
throw fail("Not a JSON map: " + s);
}
static int loadPage_defaultTimeout = 60000;
static ThreadLocal loadPage_charset = new ThreadLocal();
static boolean loadPage_allowGzip = true, loadPage_debug;
static boolean loadPage_anonymous = false; // don't send computer ID
static int loadPage_verboseness = 100000;
static int loadPage_retries = 1; //60; // seconds
static ThreadLocal loadPage_silent = new ThreadLocal();
static volatile int loadPage_forcedTimeout; // ms
static ThreadLocal loadPage_forcedTimeout_byThread = new ThreadLocal(); // ms
static ThreadLocal