Пример #1
0
        private void AssertCanFairlayPrivateApi()
        {
            PrivateApi privateApi = null;

            Assert.That(() => privateApi = builder.Build(), Throws.Nothing);
            Assert.That(privateApi, Is.Not.Null);
        }
Пример #2
0
    public ReadableInt(IPrivateConsumer privateConsumer, Action <PrivateApi> privateConsumerInitializer)
    {
        _privateConsumer = privateConsumer;
        var proxy = new PrivateApi(this);

        privateConsumerInitializer(proxy);
    }
Пример #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Configuration.Default.BasePath = "https://test.deribit.com/api/v2";
            // Configure HTTP basic authorization: bearerAuth
            Configuration.Default.Username = "******";
            Configuration.Default.Password = "******";

            //Configuration.Default.AccessToken = "gjF0ypJxao-8hmycbfgemBCjTtRnR9MMLxFxSkVoMyA";

            authApiInstance    = new AuthenticationApi(Configuration.Default);
            privateApiInstance = new PrivateApi(Configuration.Default);
        }
        public PrivateApiTest()
        {
            var apiKey    = Environment.GetEnvironmentVariable("BITFLYER_API_KEY");
            var apiSecret = Environment.GetEnvironmentVariable("BITFLYER_API_SECRET");

            if (apiKey == null || apiSecret == null)
            {
                throw new Exception("BITFLYER_API_KEY or BITFLYER_API_SECRET is null.");
            }

            _apiClient = new PrivateApi(apiKey, apiSecret);
        }
Пример #5
0
        private void createTestBuyOrder_Click(object sender, EventArgs e)
        {
            ;

            //ApiClient apiclient = new ApiClient(Configuration.Default);
            Configuration.Default.AddDefaultHeader("Access-Control-Allow-Origin", "*");
            Configuration.Default.AddDefaultHeader("Authorization", "Bearer " + accessToken);
            var apiInstance    = new PrivateApi(Configuration.Default);
            var instrumentName = "BTC-PERPETUAL";         // string | Instrument name
            var amount         = 500.0M;                  // decimal? | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH
            var type           = "limit";                 // string | The order type, default: `\"limit\"` (optional)
            var label          = "Test Buy Order by Bot"; // string | user defined label for the order (maximum 32 characters) (optional)
            var price          = 45000.0M;                // decimal? | <p>The order price in base currency (Only for limit and stop_limit orders)</p> <p>When adding order with advanced=usd, the field price should be the option price value in USD.</p> <p>When adding order with advanced=implv, the field price should be a value of implied volatility in percentages. For example,  price=100, means implied volatility of 100%</p> (optional)
            // var timeInForce = timeInForce_example;  // string | <p>Specifies how long the order remains in effect. Default `\"good_til_cancelled\"`</p> <ul> <li>`\"good_til_cancelled\"` - unfilled order remains in order book until cancelled</li> <li>`\"fill_or_kill\"` - execute a transaction immediately and completely or not at all</li> <li>`\"immediate_or_cancel\"` - execute a transaction immediately, and any portion of the order that cannot be immediately filled is cancelled</li> </ul> (optional)  (default to good_til_cancelled)
            // var maxShow = 8.14;  // decimal? | Maximum amount within an order to be shown to other customers, `0` for invisible order (optional)  (default to 1M)
            // var postOnly = true;  // bool? | <p>If true, the order is considered post-only. If the new price would cause the order to be filled immediately (as taker), the price will be changed to be just below the bid.</p> <p>Only valid in combination with time_in_force=`\"good_til_cancelled\"`</p> (optional)  (default to true)
            // var reduceOnly = true;  // bool? | If `true`, the order is considered reduce-only which is intended to only reduce a current position (optional)  (default to false)
            var stopPrice = 45000.0M;  // decimal? | Stop price, required for stop limit orders (Only for stop orders) (optional)

            //  var trigger = trigger_example;  // string | Defines trigger type, required for `\"stop_limit\"` order type (optional)
            //  var advanced = advanced_example;  // string | Advanced option order type. (Only for options) (optional)

            try {
                // Places a buy order for an instrument.
                //privateApiInstance.Configuration.AccessToken = Configuration.Default.AccessToken;
                MessageBox.Show("access token: " + privateApiInstance.Configuration.AccessToken);
                //  MessageBox.Show(privateApiInstance.GetBasePath());

                foreach (string key in  Configuration.Default.DefaultHeader.Keys)
                {
                    if (privateApiInstance.DefaultHeader().TryGetValue(key, out string value))
                    {
                        MessageBox.Show("key: " + key + " value: " + value);
                    }
                }
                //   Configuration.Default.AddDefaultHeader("authorization", "bearer " + accessToken); ;

                //  apiInstance.AddDefaultHeader("Access-Control-Allow-Origin","*");
                //  privateApiInstance.AddDefaultHeader("scope", "trade:read_write");
                //ApiClient.Default.con = Configuration;
                //  MessageBox.Show(ApiClient.Default.Configuration.AccessToken);
                Object result = apiInstance.PrivateBuyGetWithHttpInfo(instrumentName, amount, type, label, price, string.Empty, null, null, null, stopPrice, string.Empty, string.Empty);
                MessageBox.Show(result.ToString());
                Clipboard.SetText(result.ToString());
            } catch (ApiException ex) {
                MessageBox.Show("Exception when calling PrivateApi.PrivateBuyGet: " + ex.Message);
                MessageBox.Show("Status Code: " + ex.ErrorCode);
                MessageBox.Show(ex.StackTrace);
            }
        }
        public async Task ApiKeyNotFound()
        {
            var apiClient = new PrivateApi("xxxxxxxxxxx", "xxxxxxxxxxx");

            try
            {
                await apiClient.GetPermissions();
            }
            catch (BitFlyerApiException ex)
            {
                Assert.Equal(ex.ErrorResponse.Status, -500);
                Assert.Equal("Key not found", ex.ErrorResponse.ErrorMessage);
            }
        }
Пример #7
0
        private async ValueTask privateOpen(string id, string connect_key, string secret_key, string topic)
        {
            SendCommandQ(new QMessage
            {
                command = "OPEN",
                type    = 1,
                id      = id,
                topic   = topic,
                payload = ""
            });

            var _private_api = new PrivateApi(connect_key, secret_key);
            var _private_cli = (BitmexClient)_private_api.privateClient;

            var _expires   = (_private_cli.GenerateOnlyNonce(10) + 3600).ToString();
            var _signature = await _private_cli.CreateSignature(RestSharp.Method.Get, __auth_point, _expires);

            var _json_sign = "{ "
                             + $"'op': 'authKeyExpires', "
                             + $"'args': ['{connect_key}', {_expires}, '{_signature}']"
                             + "}";

            SendCommandQ(new QMessage
            {
                command = "SIGN",
                type    = 0,
                id      = id,
                topic   = topic,
                payload = _json_sign
            });

            var _json_subc = "{"
                             + " 'op': 'subscribe', "
                             + " 'args': ['order'] "
                             //+ " 'args': ['position','execution','order'] "
                             //+ " 'args': ['margin'] "
                             + "}";

            SendCommandQ(new QMessage
            {
                command = "SUBC",
                type    = 0,
                id      = id,
                topic   = topic,
                payload = _json_subc
            });
        }
        public PrivateApiTest()
        {
            var apiKey    = Environment.GetEnvironmentVariable("BITFLYER_API_KEY");
            var apiSecret = Environment.GetEnvironmentVariable("BITFLYER_API_SECRET");

            if (apiKey == null || apiSecret == null)
            {
                throw new Exception("Please set the environment variable BITFLYER_API_KEY and BITFLYER_API_SECRET for private API tests.");
            }

            apiClient = new PrivateApi(apiKey, apiSecret);

            var ticker      = PublicApi.GetTicker(ProductCode.FxBtcJpy).Result;
            var latestPrice = ticker.LatestPrice;

            buyPrice  = (int)(latestPrice * 0.95);
            sellPrice = (int)(latestPrice * 1.05);
        }
 public void Init()
 {
     instance = new PrivateApi();
 }
Пример #10
0
 public Trader(CommandLineOptions options)
 {
     _privateApi = new PrivateApi(options.ApiKey, options.ApiSecret);
     _betting    = options.Betting;
     _analyzer   = new TickerAnalyzer();
 }